Today 21:13
Forum: WIKI Discussion
Starter: AlbertoFS
Views: 0
Replies: 6
Today 19:30
Forum: Master Synchronous Serial Port (MSSP) module / 3-wire SPI / I2C / Master and Slave modes
Starter: mjturner
Views: 0
Replies: 6
Today 17:33
Forum: New devices and techniques
Starter: normnet
Views: 0
Replies: 25
Go to last post By: John Drew
Today 02:11
Forum: Absolute Beginners Section
Starter: amod
Views: 0
Replies: 19
Today 02:01
Forum: Proton Plus Compiler v3
Starter: mjturner
Views: 0
Replies: 1
+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Junior Member AlanGC's Avatar
    Join Date
    Feb 2015
    Posts
    38
    Thumbs Up
    Received: 3
    Given: 0
    Total Downloaded
    235.40 MB

    0 Not allowed!

    Default AD9833 calculating tuning hex values/writing to registers

    Good Evening all

    Im trying to make a simple signal generator using a AD9833 module. I have all the hardware rigged up and it works fine. Im
    struggling to calculate the hex serial values for the frequency registers and how they actually work. . The program below produces a 5MHZ output and is fine.

    I used the the calculator at http://www.analog.com/en/design-cent...ls/ad9833.html for the hex values below

    tuning word = freq x 0.09313. The result is then split up into a upper and lower word etc and written to the frequency registers. Im trying to work out how
    5Mhz calcs to FREQ1 = B333 8CCC and FREQ0 = 7333 4CCC - complete output is :- 2100 7333 4CCC B333 8CCC C000 E000 2000 etc

    Thanks in advance

    Alan

    CS_AD = 1
    Start:
    CS_AD = 0
    SHOut DO_AD, SCLK_AD,
    MsbFirst_H, [0x2100 \16 ]
    CS_AD = 1
    CS_AD = 0
    SHOut DO_AD, SCLK_AD,
    MsbFirst_H, [0x7333 \16 ]
    CS_AD = 1
    CS_AD = 0
    SHOut DO_AD, SCLK_AD,
    MsbFirst_H, [0x4ccc \ 16 ]
    CS_AD = 1
    CS_AD = 0
    SHOut DO_AD, SCLK_AD,
    MsbFirst_H, [0xb333 \ 16 ]
    CS_AD = 1
    CS_AD = 0
    SHOut DO_AD, SCLK_AD,
    MsbFirst_H, [0x8ccc \ 16 ]
    CS_AD = 1
    CS_AD = 0
    SHOut DO_AD, SCLK_AD,
    MsbFirst_H, [0xC000 \ 16 ]
    CS_AD = 1
    CS_AD = 0
    SHOut DO_AD, SCLK_AD,
    MsbFirst_H, [0x2000 \ 16 ]
    CS_AD = 1

  2. #2
    Prolific Poster normnet's Avatar
    Join Date
    Jul 2004
    Posts
    2,265
    Thumbs Up
    Received: 132
    Given: 32
    Total Downloaded
    1,016.36 MB

    0 Not allowed!

    Default Re: AD9833 calculating tuning hex values/writing to registers

    From the manual:

    Numeric Representations
    The compiler recognizes several different numeric representations: -
    Binary is prefixed by %. i.e. %01000101
    Hexadecimal is prefixed by $. i.e. $0A
    Character byte is surrounded by quotes. i.e. "a" represents a value of 97
    Decimal values need no prefix.
    Floating point is created by using a decimal point. i.e. 3.14


    Try replacing the 0x2100 for example with $2100.

    Norm

  3. #3
    Junior Member AlanGC's Avatar
    Join Date
    Feb 2015
    Posts
    38
    Thumbs Up
    Received: 3
    Given: 0
    Total Downloaded
    235.40 MB

    0 Not allowed!

    Default Re: AD9833 calculating tuning hex values/writing to registers

    Hi

    Thanks for the reply. Im trying to do a manual calculation to create the correct hex values for the AD9833. My values dont correspond to the calculator link ones, for freq above about 1KHZ.
    For example at 5MHZ FR0 the serial output should be 2100 7333 4CCC B333 8CCC C000 E000 2000 . Tuning dword = freq x 2^28 / 25 MHz. for example this would be 42949673 which is what I get. The calculation after that seems to go wrong for some reason.

    Many Thanks

    Alan

  4. #4
    Junior Member AlanGC's Avatar
    Join Date
    Feb 2015
    Posts
    38
    Thumbs Up
    Received: 3
    Given: 0
    Total Downloaded
    235.40 MB

    0 Not allowed!

    Default Re: AD9833 calculating tuning hex values/writing to registers

    Hi

    This is how you calculate the frequency register , great little device with a max freq of 12.5 Mhz and able to produce square , sine and a triangle waveform ..

    From what you obtained from the calculator:5C29 4A3D is for frequency register 09C29 8A3D is for frequency register 1 Using this formula from AN-1070, For 4MHz output using
    25Mhz



    Get the first 14 bits for LSB, 01110000101001Then add 01 for D15 and D14 for the address of frequency register 0 0101110000101001 = 0x5C29Then the remaining 14 bits for MSB, 00101000111101Then add 01 for D15 and D14 for the address of frequency register 0 0100101000111101 = 0x4A3D

    This is the code :-
    T_W = Freq * 10.7374184
    FTW = T_W
    LSB = FTW & $3FFF
    MSB = FTW >>14 & $3FFF
    LSB.14 = 1 : LSB.15 = 0
    MSB.14 = 1 : MSB.15 = 0
    FR00 = LSB
    FR01 = MSB

    Just do the rest ...

    Thanks

    Alan







  5. #5
    Administrator John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    3,031
    Thumbs Up
    Received: 99
    Given: 28
    Total Downloaded
    2.25 GB

    0 Not allowed!

    Default Re: AD9833 calculating tuning hex values/writing to registers

    G'day Alan,
    When you're happy with your finished code how about a WIKI article?
    I'm sure it would be useful for others, especially as it's not always easy to find content in the forum.
    Best wishes
    John

  6. #6
    Junior Member AlanGC's Avatar
    Join Date
    Feb 2015
    Posts
    38
    Thumbs Up
    Received: 3
    Given: 0
    Total Downloaded
    235.40 MB

    0 Not allowed!

    Default Re: AD9833 calculating tuning hex values/writing to registers

    Yes John I will post some code , they are a great little device good for VFO with a Oled display and rotatory encoder. The 34 and 35 device have higher
    frequency ratings - PS .. the device data sheets are over complicated and not that clear for a simple interface.

    Regards

    Alan

  7. #7
    Junior Member AnthonyHarris's Avatar
    Join Date
    Jan 2006
    Posts
    59
    Thumbs Up
    Received: 1
    Given: 0
    Total Downloaded
    92.65 MB

    0 Not allowed!

    Default Re: AD9833 calculating tuning hex values/writing to registers

    A few years too late but thought id repost anyway in case it helps someone one day

    • Hello everyone

      I thought id post this bit of code i wrote a little while ago, i didnt realsie people where trying to use these devices, Anyway there is a bit of excess code in here but it does work and with a few settings it is easy to select the frequency and shape of the waveform, the device i did this for had two dds ic on it and it is possible to select both chip and both registers. it has also be written entirly in picbasic.

      Hope it helps,

      One word of warning as several people have found out, they are small, very small :-)




      Device = 16F877

      XTAL = 20

      Symbol DPin PORTC.4 'Data port DDS 1
      Symbol CPin = PORTC.3 'Clock port DDS 1
      Symbol DDS_CE1 = PORTC.2 'Chip Enble DDS 1
      Symbol DDS_CE2 = PORTC.1 'Chip Enble DDS 2

      Output DDS_CE1 'Sets Pin to an Output
      Output DDS_CE2 'Sets Pin to an Output


      Dim Frequency As DWord 'Desired Frequency
      Dim DDS_OP As Float 'DDS Output
      Dim FTW As DWord 'Frequency Tunning word
      Dim FTWLSB As FTW.WORD0 'First word LSB of the Frequency tuning word
      Dim FTWMSB As FTW.WORD1 'Second word MSB of the Frequency tuning word
      Dim FTWLSB1 As Word '
      Dim DDS_Chip As Byte 'Selects DDS chip DDS1 = 1, DDS2 = 2
      Dim DDS_Waveform As Byte 'Select Waveforms Type Sine = 1, Triangle = 2, Square = 3 (TTL)
      Dim DDS_Control_Register As Word
      Dim Freq_Reg As Bit 'Selects Frequency Register REG0 or REG1

      Dim var1 As Byte
      Dim key As Byte

      'KEYPAD_PORT PORTB
      Include "proton_4.inc"
      Cls

      'Initialise DDS1
      DDS_CE1 = 0 'Activate DDS (Set Chip Enable Low)
      SHOut DPin,CPin,5, [$2100\16] 'Apply Reset
      SHOut DPin,CPin,5, [$2000\16] 'Remove reset
      DDS_CE1 = 1 'Disable DDS (Set Chip Enable High)

      'Initialise DDS2
      DDS_CE2 = 0 'Activate DDS (Set Chip Enable Low)
      SHOut DPin,CPin,5, [$2100\16] 'Apply Reset
      SHOut DPin,CPin,5, [$2000\16] 'Remove reset
      DDS_CE2 = 1 'Disable DDS (Set Chip Enable High)

      DDS_Control_Register = $2100
      DDS_Chip = 1

      loop:
      key = ""
      var1 = InKey
      key = LookUp var1,["1","2","3","A","4","5","6","B","7","8","9","C ","* ","0","#","D"]
      Print At 1,1,key,

      Select key

      Case "1"
      Print At 1,6,"Button 1"
      Frequency = 1000 'Sets Desired Output Frequency
      DDS_Waveform = 1 'Sets waveform type
      Freq_Reg = 0 'Point to which register
      DDS_Chip = 2 'DDS Chip 1

      GoSub FTW_CALC:

      Case "2"
      Print At 1,6,"Button 2"
      Frequency = 2000 'Sets Desired Output Frequency
      DDS_Waveform = 1 'Sets waveform type
      Freq_Reg = 0 'Point to which register
      DDS_Chip = 2 'DDS Chip 1

      GoSub FTW_CALC

      Case "3"
      Print At 1,6,"Button 3"
      Frequency = 1000 'Sets Desired Output Frequency
      DDS_Waveform = 1 'Sets waveform type
      Freq_Reg = 1 'Point to which register
      DDS_Chip = 2 'DDS Chip 1

      GoSub FTW_CALC

      Case "4"
      Print At 1,6,"Button 4"
      Frequency = 2000 'Sets Desired Output Frequency
      DDS_Waveform = 1 'Sets waveform type
      Freq_Reg = 1 'Point to which register
      DDS_Chip = 2 'DDS Chip 1

      GoSub FTW_CALC

      Case "5"
      Print At 1,6,"Button 5"
      Frequency = 1000 'Sets Desired Output Frequency
      DDS_Waveform = 3 'Sets waveform type
      Freq_Reg = 1 'Point to which register
      DDS_Chip = 2 'DDS Chip 2

      GoSub FTW_CALC

      Case "6"
      Print At 1,6,"Button 6"
      Frequency = 1000 'Sets Desired Output Frequency
      DDS_Waveform = 1 'Sets waveform type
      Freq_Reg = 1 'Point to which register
      DDS_Chip = 2 'DDS Chip 2

      GoSub FTW_CALC

      Case "7"
      Print At 1,6,"Button 7"
      Frequency = 2000 'Sets Desired Output Frequency
      DDS_Waveform = 1 'Sets waveform type
      Freq_Reg = 1 'Point to which register
      DDS_Chip = 2 'DDS Chip 2

      GoSub FTW_CALC

      Case "8"
      Print At 1,6,"Button 8"
      Frequency = 2500 'Sets Desired Output Frequency
      DDS_Waveform = 2 'Sets waveform type
      Freq_Reg = 1 'Point to which register
      DDS_Chip = 2 'DDS Chip 2

      GoSub FTW_CALC

      Case "9"
      Print At 1,6,"Button 9"
      Case "0"
      Print At 1,6,"Button 0"
      Case "A"
      Print At 1,6,"Button A"
      Case "B"
      Print At 1,6,"Button B"
      Case "C"
      Print At 1,6,"Button C"
      Case "D"
      Print At 1,6,"Button D"
      Case "*"
      Print At 1,6,"Button *"
      Case "#"
      Print At 1,6,"Button #"



      Case Else
      Cls
      Print At 2,1, "No Button Press"
      RSOut "hello"

      EndSelect

      GoTo loop



      FTW_CALC: 'Calculates Frequency tuning words


      DDS_OP = Frequency/0.03725290298 'Equation to produce DDS tuning word Master CLK / 2pwr28

      'Extract LSB Tuning Word
      FTW = DDS_OP 'DDS_OP (Float) = Freq tuning word (Dword) << bit shift doesn't work with float
      FTWLSB1 = FTWLSB 'Extract LSB and put it in LSB1

      'Extract MSB tuning word
      FTW = FTW << 2 'Shift Bits Left twice


      ProgrammeDDS:

      Select Freq_Reg

      Case 0
      FTWLSB1.15 = 0 'Set LSB bit 15 & 14 to 01 (Code to write to DDS Freq Reg 0)
      FTWLSB1.14 = 1
      FTWMSB.15 = 0 'Set MSB bit 15 & 14 to 01 (Code to write to DDS Freq Reg 0)
      FTWMSB.14 = 1
      DDS_Control_Register.11 = 0 ' Tells DDS to use Frequency Register 0
      Case 1
      FTWLSB1.15 = 1 'Set LSB bit 15 & 14 to 10 (Code to write to DDS Freq Reg 1)
      FTWLSB1.14 = 0
      FTWMSB.15 = 1 'Set MSB bit 15 & 14 to 10 (Code to write to DDS Freq Reg 1)
      FTWMSB.14 = 0
      DDS_Control_Register.11 = 1 ' Tells DDS to use Frequency Register 1
      EndSelect


      Select DDS_Waveform 'Sets the control register code to produce coressponding waveforms


      Case 1 'Sine
      DDS_Control_Register.5 = 0 DS_Control_Register.1 = 0
      Case 2 'Triangle
      DDS_Control_Register.5 = 0 DS_Control_Register.1 = 1
      Case 3 'Square
      DDS_Control_Register.5 = 1 DS_Control_Register.1 = 0 DS_Control_Register.3 = 1
      EndSelect

      Select DDS_Chip

      Case 1 'Programmes DDS 1

      DDS_CE1 = 0 'Activate DDS (Set Chip Enable Low)
      SHOut DPin,CPin,5, [FTWLSB1\16] 'Set Frequency
      SHOut DPin,CPin,5, [FTWMSB\16]
      DDS_Control_Register.8 = 0 'Removes reset from DDS chip
      SHOut DPin,CPin,5, [DDS_Control_Register\16] 'Writes to Control Register removing reset
      DDS_CE1 = 1 'Disable DDS (Set Chip Enable High)

      Case 2 'Programmes DDS 2

      DDS_CE2 = 0 'Activate DDS (Set Chip Enable Low)
      SHOut DPin,CPin,5, [FTWLSB1\16] 'Set Frequency
      SHOut DPin,CPin,5, [FTWMSB\16]
      DDS_Control_Register.8 = 0 'Removes reset from DDS chip
      SHOut DPin,CPin,5, [DDS_Control_Register\16] 'Writes to Control Register removing reset
      DDS_CE2 = 1 'Disable DDS (Set Chip Enable High)

      EndSelect


      GoTo loop
      End




  8. #8
    Administrator John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    3,031
    Thumbs Up
    Received: 99
    Given: 28
    Total Downloaded
    2.25 GB

    0 Not allowed!

    Default Re: AD9833 calculating tuning hex values/writing to registers

    Hello Anthony,
    Would you create a WIKI article please? Things get lost on the forum and the WIKI makes it easy to find in future. I don't want to do it myself as then you wouldn't be able to edit it in future. If you do agree let me know via a post and I'll publish it for you so that others can see it.
    Cheers
    John

  9. #9
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,201
    Thumbs Up
    Received: 12
    Given: 0
    Total Downloaded
    602.47 MB

    0 Not allowed!

    Default Re: AD9833 calculating tuning hex values/writing to registers

    There are quite a few pre built modules on Ebay. I use this one. It is about 1.3 inches square and has an on-board crystal and adjustable gain amplifier
    Attached Images Attached Images
    My RAM is failing

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Sending Raw hex values using SEROUT
    By Sivaguru in forum Proton Plus Compiler v3
    Replies: 14
    Last Post: 20th March 2016, 14:48
  2. ST's Smart Antenna tuning solution
    By normnet in forum New devices and techniques
    Replies: 0
    Last Post: 24th December 2014, 05:57
  3. Receive seral hex values and store it in array.
    By AlejandroBR89 in forum Amicus 18
    Replies: 8
    Last Post: 13th February 2014, 21:14
  4. Help with AD9833 control using PIC
    By C H Whitehead in forum Proton Plus Compiler v3
    Replies: 31
    Last Post: 20th March 2009, 23:29
  5. [SOLVED !] ad9833 help
    By cipanhensem in forum The Lounge
    Replies: 0
    Last Post: 29th August 2007, 16:22

Members who have read this thread since 14th June 2018, 18:37 : 0

Actions :  (Set Date)  (Clear Date)

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts