A sine wave generator using AD9833 and AD9850 using STM32F103RB

Dependencies:   mbed

This is a sine wave generator using DDS IC' AD9833 and AD9850. The STM32F1 microcontroller produces the SPI commands for the two DDS.

Learn more about STM32F1 in my blog: https://www.teachmemicro.com

Revision:
0:6069c0f2a245
Child:
1:9dcccb399f0b
diff -r 000000000000 -r 6069c0f2a245 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 21 11:24:25 2017 +0000
@@ -0,0 +1,29 @@
+#include "mbed.h"
+#include "AD9833.h"
+#include "AD9850.h"
+
+AD9833 gen;       // AD9833 object. Defaults to 25MHz internal reference frequency
+AD9850 dds;       // AD9850 object.
+
+double GENfreq = 10000;            //frequency for the AD9833
+double DDSfreq = 10000000;         //frequency for the AD9850
+double DDStrimFreq = 124999500;    //frequency used by AD9850 to calibrate
+int DDSphase = 0;                  //phase for the AD9850
+
+int main() { 
+    
+    // Sequence to follow to generate waveform using AD9833
+    gen.Begin();              // The loaded defaults are 1000 Hz SINE_WAVE using REG0
+                             // The output is OFF, Sleep mode is disabled
+    gen.EnableOutput(false);  // Turn ON the output
+    WaveformType waveType = SINE_WAVE;    //set waveform type. other possible value: TRIANGLE_WAVE, SQUARE_WAVE, HALF_SQUARE WAVE
+    gen.SetWaveform(REG0,waveType);       //set wave type to register
+    gen.SetGENFrequency(REG0,GENfreq);    //set frequency to register 
+    gen.SetOutputSource(REG0);            //output waveform with GENfreq as frequency
+    
+    // Sequence to follow to generate waveform using AD9850
+    dds.Begin();                         //begin generating for the AD9850
+    dds.CalibrateDDS(DDStrimFreq);       //calibrate to match crystal oscillator
+    dds.SetDDSFrequency(DDSfreq, DDSphase);
+}
+