Calculate tuning value for the AD9850 DDS.


Results 1 to 17 of 17

Threaded View

  1. #2
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Calculate tuning value for the AD9850 DDS.

    Very interesting Henrik.

    I have only skimped through the wiki just now and will read properly offline.

    I'm currently using one of the cheap ebay modules on a board i designed and a 16f628 to produce a tunable signal generator dds, this is other peoples code in asm though. One other code is a sweep generator/signal generator with decade digit selection by rotary encoder.

    I had been trying to do the maths (Nowhere near my capability) to use a rotary encoder in pbp. I did achieve an incrementing counter in pbp with it but got no further to convert to the tuning word.
    I was also able to get it to any frequency by inserting the byte sequence for the tuning word into the code. I had all the amateur bands set up as subs and using a pushbutton could step through them.

    I wanted to do the dds in pbp so I could add further features such as keypad freq entry, vfo a and vfo b, along with band switching outputs for a ham radio transceiver I'm building.

    Below is some sample code. I did move on much further but then got into a jam with ideas.

    Regards,
    Rob


    Code:
    '****************************************************************
    '*  Name    : DDS Frequency Generator                           *
    '*  Author  :                                    *                               *
    '*  Date    : 10/29/2012                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : Uses ebay DDS board and rotary encoder            *
    '*          :                                                   *
    '****************************************************************
    
    '
    ;  16f628a
    ;  __config _CP_OFF&_LVP_OFF&_BODEN_OFF&_PWRTE_OFF&_WDT_OFF&_INTRC_OSC_NOCLKOUT
    ; 
    '       
    '
            '
            '       LCD Display
            '       -----------
            '      
            '
    Define LCD_DREG PORTB          ' Port for LCD Data
    Define LCD_DBIT 0              ' Use lower 4 bits of Port
    Define LCD_RSREG PORTB         ' Port for RegisterSelect (RS) bit
    Define LCD_RSBIT 6             ' Port Pin for RS bit
    Define LCD_RWBIT 5             ' Port Pin for RS bit
    Define LCD_EREG PORTB          ' Port for Enable (E) bit
    Define LCD_EBIT 4              ' Port Pin for E bit
    Define LCB_BITS 4              ' Using 4-bit bus
    Define LCD_LINES 2             ' Using 2 line Display
    Define LCD_COMMANDUS 1200      ' Command Delay (uS)
    DEFINE LCD_DATAUS 50           ' Data Delay (uS)
            '
            '      Control Buttons/Lines
            '      ---------------------
    PB_1 var PortA.4              ' Take this pin low momentarily to change step
    PB_2 var PortA.3              ' Take this pin low momentarily to change band
    PB_3 var PortA.2              ' Take this pin low momentarily to RESET
    EncoderRight var PortA.1       ' rotary encoder pin
    EncoderLeft var PortA.0      ' rotary encoder pin
    
    
    ddsload var PortB.7           ' dds control word pin
    ddsdata var PortB.3           ' dds data input
    ddsclock var PortB.2          ' dds clock input
    
    
    
    fStep var byte
    fcount var byte
    Counter var word
    
    
        CMCON=7      'sets 16f628 comparator pins to digital
        TRISA=%00011111       'Button & encoder inputs
    
    Counter = 0
    fcount = 0
    fstep = 1     ;start at 1 digit count
    
        LOW DDSLOAD
    
    'CONFIGURE DISPLAY
        pause 1000
        LCDOUT $FE,1    ' Clear screen
        pause 10
        lcdout $fe,$c0,dec5 counter        ; reset to zero on start
    
    
    ddstart:
        shiftout ddsdata,ddsclock,0,[ $07,$2B,$02,$0C ]   ;start value
        toggle ddsload
        pause 100
    
    ;Rotary Encoder Code################################################
    
    mainloop1:
    
        if EncoderRight=0 then                 'here is switch 2 of the rotary encoder
            counter=counter+1
            gosub up
            gosub dds
            gosub lcd
        endif
    
    'IF PB_1=0 THEN inc_step
    
        if EncoderLeft=0 then                 'here is switch 1 of the rotary encoder
            counter = counter-1
            gosub down
            gosub dds
            gosub lcd
        endif
    
        goto mainloop1
        
    lcd:
        lcdout $fe,$c0,dec5 counter
        while (EncoderLeft=0 or EncoderRight=0):pause 10:wend
        return
    
    
    inc_step:
        fcount=fcount+1
        if fcount=2 then fstep=100
        if fcount=1 then fstep=10
        fcount=1
        return
    
    dds:
        shiftout ddsdata,ddsclock,0,[counter]
        toggle ddsload
        return
    
    up:
    
        counter[0]=counter[0]+1
        if counter[0]>99 then
            counter[0]=0
            counter[1]=counter[1]+1
            if counter[1]>99 then
                counter[1]=0
                counter[2]=counter[2]+1
                if counter[2]>99 then
                    counter[2]=0
                    counter[3]=counter[3]+1
                    if counter[3]>99 then
                        counter[3]=0     ;reset to zero
                    endif
                endif
            endif
        endif
    return
    
    down:
    
        counter[0]=counter[0]-1
        if counter[0]<1 then
            counter[0]=0
            counter[1]=counter[1]-1
            if counter[1]<1 then
                counter[1]=99
                counter[2]=counter[2]-1
                if counter[2]<1 then
                    counter[2]=99
                    counter[3]=counter[3]-1
                    if counter[3]<1 then
                        counter[3]=99
                    endif
                endif
            endif
        endif
    return
    
    end
    Last edited by tasmod; - 6th January 2013 at 17:26.

Similar Threads

  1. OSCTUNE Tuning range
    By MikeBZH in forum Schematics
    Replies: 3
    Last Post: - 8th June 2009, 06:54
  2. Need help in controlling DDS AD9850/51
    By vu2iia in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th March 2007, 13:40
  3. RF video reciever - digital tuning
    By RYTECH in forum Schematics
    Replies: 13
    Last Post: - 15th September 2006, 01:05
  4. calculate with date
    By Pedro Pinto in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th October 2005, 17:49
  5. iButton CRC-8 Calculate
    By Pesa in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th May 2005, 10:05

Members who have read this thread : 1

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

Posting Permissions

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