Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * ApplySignal.ino
- * 2018 WLWilliams
- *
- * Basic Signal Generator
- * Learnelectronics
- * Aug 15 2020
- * www.youtube.com/learnelectronics
- * arduino0169@gmail.com
- *
- * Library code found at: https://github.com/Billwilliams1952/AD9833-Library-Arduino
- *
- */
- #include <AD9833.h> // Include the library
- #define FNC_PIN 4 // Can be any digital IO pin
- //--------------- Create an AD9833 object ----------------
- // Note, SCK and MOSI must be connected to CLK and DAT pins on the AD9833 for SPI
- AD9833 gen(FNC_PIN); // Defaults to 25MHz internal reference frequency
- int rate = 100;
- int pot = 0;
- void setup() {
- // This MUST be the first command after declaring the AD9833 object
- gen.Begin();
- // Apply a 1000 Hz sine wave using REG0 (register set 0). There are two register sets,
- // REG0 and REG1.
- // Each one can be programmed for:
- // Signal type - SINE_WAVE, TRIANGLE_WAVE, SQUARE_WAVE, and HALF_SQUARE_WAVE
- // Frequency - 0 to 12.5 MHz
- // Phase - 0 to 360 degress (this is only useful if it is 'relative' to some other signal
- // such as the phase difference between REG0 and REG1).
- // In ApplySignal, if Phase is not given, it defaults to 0.
- gen.ApplySignal(SINE_WAVE,REG0,rate);
- gen.EnableOutput(true); // Turn ON the output - it defaults to OFF
- // There should be a 1000 Hz sine wave on the output of the AD9833
- pinMode(A0,INPUT);
- Serial.begin(9600);
- }
- void loop() {
- pot = analogRead(A0);
- rate = map(pot, 0, 1023, 1000, 10000);
- gen.ApplySignal(SINE_WAVE,REG0,rate);
- Serial.println(rate);
- }
Add Comment
Please, Sign In to add comment