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

Committer:
roland_tmm
Date:
Tue Nov 21 11:24:25 2017 +0000
Revision:
0:6069c0f2a245
Child:
1:9dcccb399f0b
Version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
roland_tmm 0:6069c0f2a245 1 #include "mbed.h"
roland_tmm 0:6069c0f2a245 2 #include "AD9833.h"
roland_tmm 0:6069c0f2a245 3 #include "AD9850.h"
roland_tmm 0:6069c0f2a245 4
roland_tmm 0:6069c0f2a245 5 AD9833 gen; // AD9833 object. Defaults to 25MHz internal reference frequency
roland_tmm 0:6069c0f2a245 6 AD9850 dds; // AD9850 object.
roland_tmm 0:6069c0f2a245 7
roland_tmm 0:6069c0f2a245 8 double GENfreq = 10000; //frequency for the AD9833
roland_tmm 0:6069c0f2a245 9 double DDSfreq = 10000000; //frequency for the AD9850
roland_tmm 0:6069c0f2a245 10 double DDStrimFreq = 124999500; //frequency used by AD9850 to calibrate
roland_tmm 0:6069c0f2a245 11 int DDSphase = 0; //phase for the AD9850
roland_tmm 0:6069c0f2a245 12
roland_tmm 0:6069c0f2a245 13 int main() {
roland_tmm 0:6069c0f2a245 14
roland_tmm 0:6069c0f2a245 15 // Sequence to follow to generate waveform using AD9833
roland_tmm 0:6069c0f2a245 16 gen.Begin(); // The loaded defaults are 1000 Hz SINE_WAVE using REG0
roland_tmm 0:6069c0f2a245 17 // The output is OFF, Sleep mode is disabled
roland_tmm 0:6069c0f2a245 18 gen.EnableOutput(false); // Turn ON the output
roland_tmm 0:6069c0f2a245 19 WaveformType waveType = SINE_WAVE; //set waveform type. other possible value: TRIANGLE_WAVE, SQUARE_WAVE, HALF_SQUARE WAVE
roland_tmm 0:6069c0f2a245 20 gen.SetWaveform(REG0,waveType); //set wave type to register
roland_tmm 0:6069c0f2a245 21 gen.SetGENFrequency(REG0,GENfreq); //set frequency to register
roland_tmm 0:6069c0f2a245 22 gen.SetOutputSource(REG0); //output waveform with GENfreq as frequency
roland_tmm 0:6069c0f2a245 23
roland_tmm 0:6069c0f2a245 24 // Sequence to follow to generate waveform using AD9850
roland_tmm 0:6069c0f2a245 25 dds.Begin(); //begin generating for the AD9850
roland_tmm 0:6069c0f2a245 26 dds.CalibrateDDS(DDStrimFreq); //calibrate to match crystal oscillator
roland_tmm 0:6069c0f2a245 27 dds.SetDDSFrequency(DDSfreq, DDSphase);
roland_tmm 0:6069c0f2a245 28 }
roland_tmm 0:6069c0f2a245 29