A sine wave generator using AD9833 and AD9850 using STM32F103RB
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
AD9850.h@0:6069c0f2a245, 2017-11-21 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
roland_tmm | 0:6069c0f2a245 | 1 | /****************************************************************************************************************** |
roland_tmm | 0:6069c0f2a245 | 2 | * Arduino library for AD9850 |
roland_tmm | 0:6069c0f2a245 | 3 | * Created 23/08/2014 |
roland_tmm | 0:6069c0f2a245 | 4 | * Christophe Caiveau f4goj@free.fr |
roland_tmm | 0:6069c0f2a245 | 5 | * |
roland_tmm | 0:6069c0f2a245 | 6 | * Use this library freely |
roland_tmm | 0:6069c0f2a245 | 7 | * |
roland_tmm | 0:6069c0f2a245 | 8 | * Hardware connections : |
roland_tmm | 0:6069c0f2a245 | 9 | * W_CLK -> any pin |
roland_tmm | 0:6069c0f2a245 | 10 | * FQ_UD -> any pin |
roland_tmm | 0:6069c0f2a245 | 11 | * DATA/D7 -> any pin |
roland_tmm | 0:6069c0f2a245 | 12 | * RESET -> any pin |
roland_tmm | 0:6069c0f2a245 | 13 | * |
roland_tmm | 0:6069c0f2a245 | 14 | * Functions : |
roland_tmm | 0:6069c0f2a245 | 15 | * dds.begin(W_CLK pin, FQ_UD pin, DATA pin, RESET pin); Initialize the output pins and master reset the AD9850 |
roland_tmm | 0:6069c0f2a245 | 16 | * dds.calibrate(frequency); Compensation of crystal oscillator frequency |
roland_tmm | 0:6069c0f2a245 | 17 | * dds.setfreq(frequency,phase); frequency in Hz, phase coded on 5 bits |
roland_tmm | 0:6069c0f2a245 | 18 | * dds.down(); power down mode reducing the dissipated power from 380mW to 30mW @5V |
roland_tmm | 0:6069c0f2a245 | 19 | * dds.up(); wake-up the AD9850 |
roland_tmm | 0:6069c0f2a245 | 20 | * |
roland_tmm | 0:6069c0f2a245 | 21 | * AD9850 datasheet at http://www.analog.com/static/imported-files/data_sheets/AD9850.pdf |
roland_tmm | 0:6069c0f2a245 | 22 | * |
roland_tmm | 0:6069c0f2a245 | 23 | *****************************************************************************************************************/ |
roland_tmm | 0:6069c0f2a245 | 24 | |
roland_tmm | 0:6069c0f2a245 | 25 | |
roland_tmm | 0:6069c0f2a245 | 26 | #ifndef AD9850_H |
roland_tmm | 0:6069c0f2a245 | 27 | #define AD9850_H |
roland_tmm | 0:6069c0f2a245 | 28 | #include <stdint.h> |
roland_tmm | 0:6069c0f2a245 | 29 | |
roland_tmm | 0:6069c0f2a245 | 30 | class AD9850 |
roland_tmm | 0:6069c0f2a245 | 31 | { |
roland_tmm | 0:6069c0f2a245 | 32 | public: |
roland_tmm | 0:6069c0f2a245 | 33 | AD9850(); |
roland_tmm | 0:6069c0f2a245 | 34 | |
roland_tmm | 0:6069c0f2a245 | 35 | void Begin();//int w_clk, int fq_ud, int data, int reset); |
roland_tmm | 0:6069c0f2a245 | 36 | void SetDDSFrequency(double f, uint8_t p); |
roland_tmm | 0:6069c0f2a245 | 37 | void down(); |
roland_tmm | 0:6069c0f2a245 | 38 | void up(); |
roland_tmm | 0:6069c0f2a245 | 39 | void CalibrateDDS(double TrimFreq); |
roland_tmm | 0:6069c0f2a245 | 40 | |
roland_tmm | 0:6069c0f2a245 | 41 | private: |
roland_tmm | 0:6069c0f2a245 | 42 | int W_CLK; |
roland_tmm | 0:6069c0f2a245 | 43 | int FQ_UD; |
roland_tmm | 0:6069c0f2a245 | 44 | int DATA; |
roland_tmm | 0:6069c0f2a245 | 45 | int RESET; |
roland_tmm | 0:6069c0f2a245 | 46 | uint32_t deltaphase; |
roland_tmm | 0:6069c0f2a245 | 47 | uint8_t phase; |
roland_tmm | 0:6069c0f2a245 | 48 | void update(); |
roland_tmm | 0:6069c0f2a245 | 49 | void begin_priv(); |
roland_tmm | 0:6069c0f2a245 | 50 | // void pulse(int pin); |
roland_tmm | 0:6069c0f2a245 | 51 | double calibFreq; |
roland_tmm | 0:6069c0f2a245 | 52 | }; |
roland_tmm | 0:6069c0f2a245 | 53 | |
roland_tmm | 0:6069c0f2a245 | 54 | #endif |