-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAD9850.cpp
More file actions
99 lines (76 loc) · 2.57 KB
/
AD9850.cpp
File metadata and controls
99 lines (76 loc) · 2.57 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//This code was created on 03JUL2015
//The purpose of this code is to set up the AD9850 DDS Signal Generator,
//And to set the output frequency of the AD9850 chip
//This code was created with this reference - http://www.electrodragon.com/w/AD9850_Module_DDS_Signal_Generator_V2
#include "AD9850.h"
#define DEBUG
DDS::DDS(){
// Set pins for DDS output. These pins can be customized to whatever is needed,
// but all pins need to be DI/O pins
W_CLK = 30;
FU_UD = 31;
DATA = 32;
RESET = 33;
//Sine Wave output is on ZOUT1 and ZOUT2
//Square Wave output is on QOUT1 and QOUT2
// OUT1 and OUT2 are inverse waves of eachother
//OUT1
// / / / /
// / / / /
// / / / /
// / / / /
// / / / /
// / / / /
/// / / /
////////////////////////////////////////////////////////////////////////
//OUT2
/// / /
// / / /
// / / /
// / / /
// / / /
// / / /
// / / / /
////////////////////////////////////////////////////////////////////////
//Set pins to output mode
pinMode(W_CLK, OUTPUT);
pinMode(FU_UD, OUTPUT);
pinMode(DATA, OUTPUT);
pinMode(RESET, OUTPUT);
//set pins to serial mode
pulseHigh(RESET);
pulseHigh(W_CLK);
pulseHigh(FU_UD);
#ifdef DEBUG
Serial.println("DDS Initialized");
#endif
}
void DDS::setFreq(double frequency){
//enter frequency as Hz
if(frequency > 40000000){
Serial.println("Frequency is set Higher than board can output");
Serial.println("Setting to Maximum Freq ");
frequency = 40000000;
}
#ifdef DEBUG
Serial.print("Freq: ");
Serial.print(frequency);
Serial.println(" Hz");
#endif
int32_t freq = frequency * 4294967295 / 125000000; // note 125 MHz clock on 9850
for (int b = 0; b < 4; b++, freq>>=8) {
writeByte(freq & 0xFF);
}
writeByte(0x000); // Final control byte
pulseHigh(FU_UD); // Done! Should see output
}
void DDS::writeByte(byte data){
for (int i=0; i<8; i++, data>>=1) {
digitalWrite(DATA, data & 0x01);
pulseHigh(W_CLK); //after each bit sent, CLK is pulsed high
}
}
void DDS::pulseHigh(int pin){
digitalWrite(pin, HIGH);
digitalWrite(pin, LOW);
}