My favorites | Sign in
Project Home Downloads Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* A simple AD9851 Arduino script - non SPI version
* see http://www.rocketnumbernine.com/2011/10/25/programming-the-ad9851-dds-synthesizer
* Andrew Smallbone <andrew@rocketnumbernine.com>
* Use freely.
*/

#define FQ_UD 6 // connected to AD9851 device select pin
#define W_CLK 13 // connected to AD9851 clock pin
#define DATA 11 // connected to AD9851 D7 (serial data) pin

#define pulseHigh(pin) {digitalWrite(pin, HIGH); digitalWrite(pin, LOW); }

// transfer a byte a bit at a time LSB first to DATA
void tfr_byte(byte data)
{
for (int i=0; i<8; i++, data>>=1) {
digitalWrite(DATA, data & 0x01);
pulseHigh(W_CLK);
}
}

// frequency of signwave (datasheet page 12) will be <sys clock> * <frequency tuning word> / 2^32
void sendFrequency(double frequency) {
int32_t freq = frequency * 4294967296.0 / 180.0e6;
for (int b=0; b<4; b++, freq>>=8) {
tfr_byte(freq & 0xFF);
}
tfr_byte(0x001);
pulseHigh(FQ_UD);
}

void setup() {
// all pins to outputs
pinMode(FQ_UD, OUTPUT);
pinMode(W_CLK, OUTPUT);
pinMode(DATA, OUTPUT);

// if your board needs it, connect RESET pin and pulse it to reset AD9851
// pulseHigh(RESET)

// set serial load enable (Datasheet page 15 Fig. 17)
pulseHigh(W_CLK);
pulseHigh(FQ_UD);
}

void loop() {
sendFrequency(1.303e3);
while(1);
}



Change log

r10 by and...@rocketnumbernine.com on Oct 24, 2011   Diff
added url
Go to: 
Project members, sign in to write a code review

Older revisions

r8 by and...@rocketnumbernine.com on Oct 24, 2011   Diff
First version
All revisions of this file

File info

Size: 1323 bytes, 53 lines
Powered by Google Project Hosting