AD9850 DDS code


Closed Thread
Results 1 to 16 of 16

Thread: AD9850 DDS code

Hybrid View

  1. #1

    Default AD9850 DDS code

    I have bought a cheap DDS module from CHina and want to start by producing a fixed output of 500kHz, there is no LCD or rotary encoder as yet; This is my code:

    include "modedefs.bas"
    pause 1000; allow circuit 1 sec to stabilise
    pulsout porta.0,100;pulse reset pin
    pause 20
    pulsout porta.3,100;Pulse w_clk
    pause 20
    pulsout porta.2,100;pulse fq_ud to set up serial data mode
    pause 20

    shiftout porta.1,porta.3,0,[%10111000];send out tuning word 1 w0-w7
    ;porta.1 is data, porta.3 is W_CLK

    shiftout porta.1,porta.3,0,[%00100100];send out tuning word 2 w8-w15

    shiftout porta.1,porta.3,0,[%01100000];send out tuning word 3 w16-w23

    shiftout porta.1,porta.3,0,[%10000000];send out tuning word 4 w24-w31

    shiftout porta.1,porta.3,0,[%00000000];send out tuning word 5 w32-w39
    pause 10
    pulsout porta.2,100; pulse FQ_UD on data complete, update DDS
    high portb.4
    pause 2000
    low portb.4;flash LED on portb.4 for 2 secs to show data sent
    end

    Needless to say, it wont work. I have also hardwired D0 and D1 to +Vdd and D2 to GND to force serial mode. Any advice?

    John

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default Re: AD9850 DDS code

    Did you remembered to make all port A digital? Normally Port A defaults to Analog or Comparator.

    Ioannis

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: AD9850 DDS code

    Hi,
    I've only looked briefly at your code but I think your tuning value is wrong.
    For 500kHz you want 500k*2^32/125M = $01 06 24 DD. You're sending $80 60 24 B8 which would equal a frequency way above 60Mhz....

    Try
    Code:
    SHIFTOUT PortA.1, PortA.3, 0, [$DD, $24, $06, $01, $00]
    Also, which PIC are you using? PortA usually contains analog functions which needs to be disabled for the pins to work in digital mode. I don't see that in your code.

    Finaly, when you force serial mode thru the hardware there's no need to do anything else at the startup - atleast I didn't have to. Perhaps your startup code is locking up the AD9850.

    /Henrik.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: AD9850 DDS code

    Thanks for the replies on the matter.
    Did you remembered to make all port A digital? Normally Port A defaults to Analog or Comparator.
    Im using a 16F628, I thought the SHIFTOUT command automatically made the named ports digital outputs, but will insert a line of code as you suggest.

    I've only looked briefly at your code but I think your tuning value is wrong
    Yes you are right, will change the values and see what happens.

    Finaly, when you force serial mode thru the hardware there's no need to do anything else at the startup
    Thanks for that clarification

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: AD9850 DDS code

    This is the latest code. Gave up on the SEROUT command and tryed the following so that i could slow down the sequence and see LEDs representing the signals. Cannot get anything out of the AD9850 still. I know the DDS module works as I proved it with someone elses software.

    trisb=$0;SET ALL OF PORTB TO OUTPUTS

    RESET VAR PORTB.7
    CLOCK VAR PORTB.6
    DATAPIN VAR PORTB.5
    DONE VAR PORTB.4;DEFINE
    P VAR WORD;WIDTH OF DATA PULSE
    P=50
    Q VAR WORD;PAUSE BETWEEN DATA BITS
    Q=10
    R VAR WORD;PAUSE BETWEEN DATA WORDS
    R=30
    W VAR BYTE;VARIABLE REPRESENTING BYTES 0 TO 5
    W0 VAR BYTE;WORD 0
    W1 VAR BYTE;WORD 1
    W2 VAR BYTE;WORD.2
    W3 VAR BYTE;WORD.3
    W4 VAR BYTE;WORD 5

    ;DATA FOR BINARY WORDS
    W0=$DD;WORD 0 HEX
    W1=$24;WORD 1 HEX
    W2=$06;WORD 2 HEW
    W3=$01;WORD 3 HEX
    W4=$00;WORD 4 HEX

    PORTB=$00; SET ALL PINS LOW
    MAIN:
    PAUSE 2000
    HIGH RESET
    PAUSE P
    LOW RESET; PULSE RESET PIN
    PAUSE R
    W=W0
    GOSUB BYTEOUT

    PAUSE R
    W=W1
    GOSUB BYTEOUT

    PAUSE R
    W=W2
    GOSUB BYTEOUT

    PAUSE R
    W=W3
    GOSUB BYTEOUT

    PAUSE R
    W=W4
    GOSUB BYTEOUT

    PAUSE R
    PULSOUT DONE,3000; ALL 40 BITS SENT

    HIGH RESET; REPEAT SEQUENCE AGAIN
    PAUSE P
    LOW RESET; PULSE RESET PIN
    W=W0
    GOSUB BYTEOUT
    PAUSE R
    W=W1
    GOSUB BYTEOUT
    PAUSE R
    W=W2
    GOSUB BYTEOUT
    PAUSE R
    W=W3
    GOSUB BYTEOUT
    PAUSE R
    W=W4
    GOSUB BYTEOUT
    PAUSE R
    PULSOUT DONE,3000; ALL 40 BITS SENT
    END

    BYTEOUT:;SUBROUTINE TO CLOCK OUT BITS 0 TO 7 OF BINARY WORD W

    PAUSE P
    DATAPIN=W.BIT0
    PAUSE 20
    HIGH CLOCK
    PAUSE P
    LOW CLOCK
    PAUSE 20
    LOW DATAPIN; CLOCK OUT BIT0

    PAUSE Q
    DATAPIN=W.BIT1
    PAUSE 2
    HIGH CLOCK
    PAUSE P
    LOW CLOCK
    PAUSE 2
    LOW DATAPIN; CLOCK OUT BIT1

    PAUSE Q
    DATAPIN=W.BIT2
    PAUSE 2
    HIGH CLOCK
    PAUSE P
    LOW CLOCK
    PAUSE 2
    LOW DATAPIN; CLOCK OUT BIT2

    PAUSE Q
    DATAPIN=W.BIT3
    PAUSE 2
    HIGH CLOCK
    PAUSE P
    LOW CLOCK
    PAUSE 2
    LOW DATAPIN; CLOCK OUT BIT3

    PAUSE Q
    DATAPIN=W.BIT4
    PAUSE 2
    HIGH CLOCK
    PAUSE P
    LOW CLOCK
    PAUSE 2
    LOW DATAPIN; CLOCK OUT BIT4

    PAUSE Q
    DATAPIN=W.BIT5
    PAUSE 2
    HIGH CLOCK
    PAUSE P
    LOW CLOCK
    PAUSE 2
    LOW DATAPIN; CLOCK OUT BIT5

    PAUSE Q
    DATAPIN=W.BIT6
    PAUSE 2
    HIGH CLOCK
    PAUSE P
    LOW CLOCK
    PAUSE 2
    LOW DATAPIN; CLOCK OUT BIT6

    PAUSE Q
    DATAPIN=W.BIT7
    PAUSE 2
    HIGH CLOCK
    PAUSE P
    LOW CLOCK
    PAUSE 2
    LOW DATAPIN; CLOCK OUT BIT7
    PAUSE Q
    RETURN

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: AD9850 DDS code

    Hi,
    Sorry for the late reply, you've probably figured it out by now.
    But in case you haven't, have you verified that your PIC is actually running?
    I've just tried the following code here, all wired up on a breadboard using a 16F628 using a 4MHz x-tal and a AD9850 module, compiled with PBP 3.0.6.4. Module forced into serial mode by tying D0,D1 high and D2 low. It outputs a 500kHz signal as expected:
    Code:
    DEFINE OSC 4
    
    Clk VAR PortB.5                 ' Clock output pin
    Dta VAR PortB.6                 ' Data output pin
    FUd VAR PortB.7                 ' Frequency update output pin
    
    PortB = 0
    TRISB = 0                       ' All outputs
    
    Pause 1000                      ' Let everything power up
    
    ' Tuning word for 500kHz = 500000*2^32/125000000 = 17179869 or, in HEX, $010624DD
    ' The AD9850 wants the least significant byte first:
    SHIFTOUT Dta, Clk, 0, [$DD, $24, $06, $01, $00]
    
    ' Now pulse the Frequency update pin
    FUd = 1 : PauseUS 10 : FUd = 0
    
    ' Blink a LED to show we're alive.
    Done:
      Toggle PortB.3
      Pause 100
    Goto Done
    Here's the result:
    Name:  DSX_20130223011754.jpeg
Views: 5200
Size:  102.8 KB

    /Henrik.

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: AD9850 DDS code

    Just a follow up to the previous post.
    For reference, here's the "schematic" for the setup I used with the above code. There are a couple of different modules in circulation so make sure the actual signals and not the pin numbers matches your particular module.

    Name:  AD9850-setup.jpg
Views: 8916
Size:  41.7 KB

    If you're programming the PIC in-circuit perhaps the programmer is loading RB6, RB7 (since they are the programming pins) preventing them from operating the AD9850 properly? I'm doing just that with a PICKit3 on my breadboard and don't see any issues but it's a thought.

    /Henrik.

Similar Threads

  1. Calculate tuning value for the AD9850 DDS.
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 21st July 2018, 00:49
  2. Working code but my layman approach uses too much code space
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th December 2012, 20:44
  3. Code: Why is this code greater than 2000 words?
    By DrDreas in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 1st June 2007, 19:51
  4. Need help in controlling DDS AD9850/51
    By vu2iia in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th March 2007, 12:40

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