PDA

View Full Version : AD9850 DDS code



cunninghamjohn
- 12th February 2013, 22:29
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

Ioannis
- 13th February 2013, 08:18
Did you remembered to make all port A digital? Normally Port A defaults to Analog or Comparator.

Ioannis

HenrikOlsson
- 13th February 2013, 08:32
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

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.

cunninghamjohn
- 14th February 2013, 06:01
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

cunninghamjohn
- 20th February 2013, 18:54
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

HenrikOlsson
- 22nd February 2013, 23:20
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:

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:
6850

/Henrik.

HenrikOlsson
- 23rd February 2013, 10:22
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.

6851

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.

cunninghamjohn
- 24th February 2013, 19:19
I now have the circuit working. I dont quite understand why the first attempt didnt work, but the following works for me. Thankyou for taking the time to solve my problem.

DEFINE OSC 4 ;WE ARE USING A 4MHZ XTAL OSCILLATOR

CLOCK VAR PortB.6 ;CLOCK SIGNAL IS ON RB6, PIN 12
DATAPIN VAR PortB.5;DATA SIGNAL IS ON RB5, PIN 11
FQUD VAR PortB.4 ;FREQUENCY UPDATE ON RB4, PIN 10

TRISB = 0 ;SET ALL OF PORTB AS OUTPUTS
PORTB = 0 ;SET ALL OF PORTB LOW

Pause 1000 ;WAIT FOR CIRCUIT TO STABILISE
PULSOUT FQUD,10 ;RESET DDS
SHIFTOUT DATAPIN, CLOCK, 0, [$DD, $24, $06, $01, $00] ;SEND SERIAL DATA TO DDS
PULSOUT FQUD,10 ;LOAD NEW FREQUENCY 500KHZ

SHIFTOUT DATAPIN, CLOCK, 0, [$DD, $24, $06, $01, $00] ;SEND SERIAL DATA TO DDS
PULSOUT FQUD,10 ;LOAD NEW FREQUENCY 500KHZ
;SERIAL DATA IS SENT TWICE, IF ONLY SENT ONCE DDS CHIP SOMETIMES LOCKS UP
END

iw2fvo
- 4th April 2013, 14:37
Hi Henrik,
I will like to understand what are OUTPUT_1 and OUTPUT_2 : any help? Sine or square ?
What about the other two outputs ?
What is the purpose of R_13 Trim ?

I do not have any schematics for this board nor manual to read ! My board is exactly the one shown in your photo.

Thanks again for the great help .
Bye
Ambrogio
IW2FVO

HenrikOlsson
- 4th April 2013, 16:44
Hi,
Not sure, I don't know much about the hardware I'm afraid. I wrote the code and put the board on the shelf.... I'd look at the AD9850 datasheet for details.
I think both outputs are Sine outputs, the phase relationship between the two outputs is what you set with CONTROL word.

/Henrik.

mark_s
- 4th April 2013, 17:30
Here's a schematic for the above module

As I recall the pot will change the duty cycle on the square wave
and will skew the sine wave



6955

iw2fvo
- 5th April 2013, 07:02
Henrik and Mark_s,
thanks for the assistance.
regards,
Ambrogio
IW2FVO

sean-h
- 14th April 2013, 20:44
I will like to understand what are OUTPUT_1 and OUTPUT_2 : any help? Sine or square ?
What about the other two outputs ?
What is the purpose of R_13 Trim ?


The module has two outputs for Sine Wave and two outputs for Square wave.

In Henriks handy pin-out picture he shows the two sine waves outputs, the next two pins above are the square wave outputs.

Played with a module today and the code examples Henrik supplied work great and thank you Henrik.

The Pic Chips tend to max out at 25khz when pulsing stepper drivers which retricts the speed when running them at say 2000 pulses per revolution. It limits you to a max of around 500 RPM.

Now with the DDS boards + Pic Chip combination, I had some stepper motors here today hitting over 5000 RPM no problems at all.

Great little modules and good prices.

Cheers

Sean.

iw2fvo
- 15th April 2013, 06:53
Sean,
could I have the circuit diagram for your stepper motor implementation ?
Thanks
Ambrogio

iw2fvo
- 22nd April 2013, 15:58
Henrik,

I have used my module today , it is the same model that is shown in your picture.
I have discovered an intermittent sine wave stream at the two output. This was due to the RESET line that has to be connected to ground.
This is in my circuit lay_out.
I hope it will help in some cases.
Ambrogio

HenrikOlsson
- 22nd April 2013, 18:39
Hi,
Thank you very much for that post!
I haven't noticed it any of my (two) breadboard sesions with the module. Just measured it and the Reset pin is indeed floating - must have been pure luck it worked for me.

I wish I could fix the "schematic" but I can't....

Thanks again!
/Henrik.