ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Суббота
6 июля
175855 Топик полностью
Лeoнид Ивaнoвич (16.12.2009 11:45, просмотров: 222) ответил luba на Не могу перевести AD9852 d 3-проводный режим программировани SPI
Есть код для AD9835, может быть, пригодится.  ;---------------------------------------------------------------------------- ;AD9835 DDS support module ;---------------------------------------------------------------------------- ;Constantes: .equ DDS_Cmd_WrPh = 0b00000000 ;write phase byte .equ DDS_Cmd_WrPhDef = 0b00010000 ;-//- to the defer register .equ DDS_Ph0 = 0b00001000 ;phase0 address .equ DDS_Ph1 = 0b00001010 ;phase1 address .equ DDS_Ph2 = 0b00001100 ;phase2 address .equ DDS_Ph3 = 0b00001110 ;phase3 address .equ DDS_Ph_LSB = 0b00000000 ;phase byte 1 address .equ DDS_Ph_MSB = 0b00000001 ;phase byte 2 address .equ DDS_Cmd_WrFr = 0b00100000 ;write frequency byte .equ DDS_Cmd_WrFrDef = 0b00110000 ;-//- to the defer register .equ DDS_Fr0 = 0b00000000 ;frequency0 address .equ DDS_Fr1 = 0b00000100 ;frequency1 address .equ DDS_Fr_L_LSB = 0b00000000 ;frequency byte 1 address .equ DDS_Fr_H_LSB = 0b00000001 ;frequency byte 2 address .equ DDS_Fr_L_MSB = 0b00000010 ;frequency byte 3 address .equ DDS_Fr_H_MSB = 0b00000011 ;frequency byte 4 address .equ DDS_Cmd_PSel = 0b01000000 ;phase select command .equ DDS_Cmd_FSel = 0b01010000 ;frequency select command .equ DDS_Cmd_PFSel = 0b01100000 ;phase and frequency select command .equ DDS_PSEL0 = 0b00000000 ;select phase0 .equ DDS_PSEL1 = 0b00000010 ;select phase1 .equ DDS_PSEL2 = 0b00000100 ;select phase2 .equ DDS_PSEL3 = 0b00000110 ;select phase3 .equ DDS_FSEL0 = 0b00000000 ;select frequency0 .equ DDS_FSEL1 = 0b00001000 ;select frequency1 .equ DDS_Cmd_Cnt1 = 0b10000000 ;DDS control 1 command .equ DDS_SYNC = 0b00100000 ;SYNC bit .equ DDS_SELSRC = 0b00010000 ;SELSRC bit .equ DDS_Cmd_Cnt2 = 0b11000000 ;DDS control 2 command .equ DDS_SLEEP = 0b00100000 ;SLEEP bit .equ DDS_RESET = 0b00010000 ;RESET bit .equ DDS_CLR = 0b00001000 ;CLR bit ;---------------------------------------------------------------------------- ;Set DDS Phase: ;Input: temp - phase register number (0..3) ; tempH:tempL - phase code DDS_Ph: push YL push YH push Cnt tst temp brne Ph1 ldi YL,DDS_Ph0 ldi YH,DDS_PSEL0+DDS_Cmd_PSel rjmp PhX Ph1: dec temp brne Ph2 ldi YL,DDS_Ph1 ldi YH,DDS_PSEL1+DDS_Cmd_PSel rjmp PhX Ph2: dec temp brne Ph3 ldi YL,DDS_Ph2 ldi YH,DDS_PSEL2+DDS_Cmd_PSel rjmp PhX Ph3: ldi YL,DDS_Ph3 ldi YH,DDS_PSEL3+DDS_Cmd_PSel PhX: ldi Cnt,DDS_Cmd_WrFrDef+DDS_Ph_LSB add Cnt,YL mov temp,tempL rcall DDS_Wr ldi Cnt,DDS_Cmd_WrFr+DDS_Ph_MSB add Cnt,YL mov temp,tempH rcall DDS_Wr mov Cnt,YH rcall DDS_Wr pop Cnt pop YH pop YL ret ;---------------------------------------------------------------------------- ;Set DDS Frequency: ;Input: tempH:tempN:tempM:tempL - frequency code ; fF0 - frequency register 0 flag ;Out: fF0 = !fF0 DDS_Fr: push YL push YH push Cnt bbrc Flags,fF0,Freq1 ;r5 = YL, r6 = YH Freq0: clbr Flags,fF0 ldi YL,DDS_Fr0 ldi YH,DDS_Cmd_FSel+DDS_FSEL0 rjmp FreqS Freq1: stbr Flags,fF0 ldi YL,DDS_Fr1 ldi YH,DDS_Cmd_FSel+DDS_FSEL1 FreqS: ldi Cnt,DDS_Cmd_WrFrDef+DDS_Fr_L_LSB add Cnt,YL mov temp,tempL rcall DDS_Wr ldi Cnt,DDS_Cmd_WrFr+DDS_Fr_H_LSB add Cnt,YL mov temp,tempM rcall DDS_Wr ldi Cnt,DDS_Cmd_WrFrDef+DDS_Fr_L_MSB add Cnt,YL mov temp,tempN rcall DDS_Wr ldi Cnt,DDS_Cmd_WrFr+DDS_Fr_H_MSB add Cnt,YL mov temp,tempH rcall DDS_Wr mov Cnt,YH rcall DDS_Wr pop Cnt pop YH pop YL ret ;---------------------------------------------------------------------------- ;Init DDS: iDDS: ldi Cnt,DDS_Cmd_Cnt2+DDS_SLEEP+DDS_RESET+DDS_CLR rcall DDS_Wr ldi Cnt,DDS_Cmd_Cnt1+DDS_SYNC+DDS_SELSRC rcall DDS_Wr clr tempL clr tempM clr tempN clr tempH rcall DDS_Fr ;frequency = 0 rcall DDS_Ph ;phase = 0 ldi Cnt,DDS_Cmd_Cnt2 rcall DDS_Wr ret ;---------------------------------------------------------------------------- ;DDS Write: ;Input: Cnt - control byte ; temp - data byte DDS_Wr: Port_FSYNC_0 push temp mov temp,Cnt rcall SPIWr0 pop temp rcall SPIWr0 Port_FSYNC_1 ret ;---------------------------------------------------------------------------- ;Write data via serial bus (SPI mode 0): ;Data clocked on the falling edge of SCLK. ;Input: temp - data byte SPIWr0: push Cnt ldi Cnt,8 ws_bit: rol temp brcs ws_1 ws_0: Port_SDATA_0 rjmp ws_clk ws_1: Port_SDATA_1 ws_clk: nop nop Port_SCLK_0 nop nop Port_SCLK_1 dec Cnt brne ws_bit pop Cnt ret ;----------------------------------------------------------------------------