My favorites
▼
|
Sign in
rocketnumbernine
Open source project code from www.rocketnumbernine.com
Project Home
Downloads
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
AVR
/
AD9851
/
ad9851-spi.pde
‹r7
r13
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
/*
* A simple AD9851 Arduino script - SPI version
* see http://www.rocketnumbernine.com/2011/10/25/programming-the-ad9851-dds-synthesizer
* Andrew Smallbone <andrew@rocketnumbernine.com>
* Use freely.
*/
#include <SPI.h>
#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); }
// 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;
// send each byte of the frequency lowest byte first
for (int b=0; b<4; b++, freq>>=8) {
SPI.transfer(freq & 0xFF);
}
// control byte - all zero except last digit (clock multiplier enable)
// see datasheet table III. page 16.
SPI.transfer(0x001);
pulseHigh(FQ_UD);
}
void setup() {
// all pins to outputs
pinMode(FQ_UD, OUTPUT);
pinMode(W_CLK, OUTPUT);
pinMode(DATA, OUTPUT);
SPI.begin();
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(LSBFIRST);
// 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.331e6);
while(1);
}
Show details
Hide details
Change log
r9
by and...@rocketnumbernine.com on Oct 24, 2011
Diff
added url
Go to:
/trunk/AVR/AD9851/ad9851-spi.pde
Project members,
sign in
to write a code review
Older revisions
r7
by and...@rocketnumbernine.com on Oct 24, 2011
Diff
first version
All revisions of this file
File info
Size: 1404 bytes, 51 lines
View raw file
Powered by
Google Project Hosting