2 * A simple single freq AD9850 Arduino test script
3 * Original AD9851 DDS sketch by Andrew Smallbone at www.rocketnumbernine.com
4 * Modified for testing the inexpensive AD9850 ebay DDS modules
5 * Pictures and pinouts at nr8o.dhlpilotcentral.com
6 * 9850 datasheet at http://www.analog.com/static/imported-files/data_sheets/AD9850.pdf
10 #define W_CLK 8 // Pin 8 - connect to AD9850 module word load clock pin (CLK)
11 #define FQ_UD 9 // Pin 9 - connect to freq update pin (FQ)
12 #define DATA 10 // Pin 10 - connect to serial data load pin (DATA)
13 #define RESET 11 // Pin 11 - connect to reset pin (RST).
15 #define pulseHigh(pin) {digitalWrite(pin, HIGH); digitalWrite(pin, LOW); }
17 // transfers a byte, a bit at a time, LSB first to the 9850 via serial DATA line
18 void tfr_byte(byte data)
20 for (int i=0; i<8; i++, data>>=1) {
21 digitalWrite(DATA, data & 0x01);
22 pulseHigh(W_CLK); //after each bit sent, CLK is pulsed high
26 // frequency calc from datasheet page 8 = <sys clock> * <frequency tuning word>/2^32
27 void sendFrequency(double frequency) {
28 int32_t freq = frequency * 4294967295/125000000; // note 125 MHz clock on 9850
29 for (int b=0; b<4; b++, freq>>=8) {
30 tfr_byte(freq & 0xFF);
32 tfr_byte(0x000); // Final control byte, all 0 for 9850 chip
33 pulseHigh(FQ_UD); // Done! Should see output
37 // configure arduino data pins for output
38 pinMode(FQ_UD, OUTPUT);
39 pinMode(W_CLK, OUTPUT);
40 pinMode(DATA, OUTPUT);
41 pinMode(RESET, OUTPUT);
45 pulseHigh(FQ_UD); // this pulse enables serial mode - Datasheet page 12 figure 10
49 sendFrequency(10.e6); // 10.e6 freq