### AD9833 Constructor Examples Source: https://github.com/robtillaart/ad9833/blob/master/README.md Examples of how to instantiate the AD9833 library using hardware or software SPI. ```cpp #include "AD9833.h" // Constructor HW SPI. // AD9833(uint8_t selectPin, SPIClassRP2040 * mySPI = &SPI) // AD9833(uint8_t selectPin, SPIClass * mySPI = &SPI ) // Constructor SW SPI. // AD9833(uint8_t selectPin, uint8_t dataPin, uint8_t clockPin) ``` -------------------------------- ### AD9833 Library Example Source: https://github.com/robtillaart/ad9833/blob/master/README.md This example demonstrates basic usage of the AD9833 library, including setting frequency, phase, and waveform. ```cpp #include #include "AD9833.h" // Define SPI pins (adjust if needed) #define AD9833_FSYNC 10 #define AD9833_SCLK 13 #define AD9833_SDATA 11 // Initialize AD9833 object AD9833 AD(AD9833_FSYNC, AD9833_SCLK, AD9833_SDATA); void setup() { Serial.begin(115200); Serial.println("AD9833 Basic Test"); // Initialize SPI communication SPI.begin(); // Initialize AD9833 AD.begin(); // Set frequency to 1000 Hz, waveform sine (default) AD.setFrequency(1000); // Set phase to 90 degrees AD.setPhase(90); // Set waveform to square AD.setWaveform(AD9833_SQUARE); // Set frequency to 2000 Hz, waveform triangle AD.setFrequency(2000, AD9833_TRIANGLE); // Set phase to 180 degrees AD.setPhase(180); // Set frequency to 3000 Hz, waveform sine AD.setFrequency(3000, AD9833_SINE); // Set phase to 270 degrees AD.setPhase(270); // Turn off output AD.powerDown(); delay(1000); // Turn on output AD.powerUp(); delay(1000); // Set frequency to 500 Hz, waveform square AD.setFrequency(500, AD9833_SQUARE); delay(1000); // Set frequency to 0 Hz (effectively off) AD.setFrequency(0); } void loop() { // Nothing to do here for this example } ``` -------------------------------- ### AD9833 Library Example with Hardware SPI Source: https://github.com/robtillaart/ad9833/blob/master/README.md This example demonstrates using the AD9833 library with hardware SPI, which is generally faster and more reliable. ```cpp #include #include "AD9833.h" // Define FSYNC pin (adjust if needed) #define AD9833_FSYNC 10 // Initialize AD9833 object using hardware SPI AD9833 AD(AD9833_FSYNC); void setup() { Serial.begin(115200); Serial.println("AD9833 Hardware SPI Test"); // Initialize SPI communication (hardware SPI) SPI.begin(); // Initialize AD9833 AD.begin(); // Set frequency to 1000 Hz, waveform sine AD.setFrequency(1000); delay(1000); // Set frequency to 2000 Hz, waveform square AD.setFrequency(2000, AD9833_SQUARE); delay(1000); // Set frequency to 3000 Hz, waveform triangle AD.setFrequency(3000, AD9833_TRIANGLE); delay(1000); // Turn off output AD.powerDown(); delay(1000); // Turn on output AD.powerUp(); delay(1000); // Set frequency to 500 Hz, waveform sine AD.setFrequency(500, AD9833_SINE); delay(1000); // Set frequency to 0 Hz (effectively off) AD.setFrequency(0); } void loop() { // Nothing to do here for this example } ``` -------------------------------- ### Waveform Selection Source: https://github.com/robtillaart/ad9833/blob/master/README.md Shows how to set and get the output waveform for the AD9833. ```cpp // void setWave(uint8_t waveform) // uint8_t getWave() ``` -------------------------------- ### Power Mode Settings Source: https://github.com/robtillaart/ad9833/blob/master/README.md Demonstrates setting and getting the power mode of the AD9833 module. ```cpp // setPowerMode(uint8_t mode = 0) // Default is 0, wake up. So use setPowerMode(0) to wake up the device. // Returns false if mode is out of range. // Details see datasheet. // uint8_t getPowerMode() returns current powerMode bits. ``` -------------------------------- ### External FSYNC Control Example Source: https://github.com/robtillaart/ad9833/blob/master/README.md Demonstrates how to manually control the FSYNC line to select a device, set its frequency, and then update the setting. ```cpp setFsyncLow(5); // select device 5 AD.setFrequency(440); // set a new frequency setFsyncHigh(5); // update the setting. ``` -------------------------------- ### Frequency Setting and Getting Source: https://github.com/robtillaart/ad9833/blob/master/README.md Functions to set and retrieve the output frequency for a selected channel. ```cpp // float setFrequency(float freq, uint8_t channel = 0) // SetFrequency sets the frequency and is limited by the MaxFrequency of 12.5 MHz. // Returns the frequency set. // float getFrequency(uint8_t channel = 0) returns the frequency set. // float getMaxFrequency() returns the maximum frequency to set (convenience). // void setFrequencyChannel(uint8_t channel) select the active frequency of channel (0 or 1). // Note: the frequency depends on the internal reference clock which is default 25 MHz. // The library does not support other reference clocks yet. ``` -------------------------------- ### Rounding Control for Frequency and Phase Source: https://github.com/robtillaart/ad9833/blob/master/README.md Example of controlling the rounding behavior for frequency and phase settings. ```cpp // void setUseRounding(bool flag = true) // Set the internal flag to use rounding // The default value is true to be backwards compatible. // bool getUseRounding() get the current status of the flag. // Note: reset() does not affect this flag. ``` -------------------------------- ### Crystal Frequency Adjustment Source: https://github.com/robtillaart/ad9833/blob/master/README.md Functions to set and get the crystal oscillator frequency. ```C++ void setCrystalFrequency(float crystalFrequency = 25000000); float getCrystalFrequency(); ``` -------------------------------- ### Phase Control Source: https://github.com/robtillaart/ad9833/blob/master/README.md Functions to set and get the phase in degrees and radians, with channel selection. ```C++ float setPhase(float phase, uint8_t channel = 0); float getPhase(uint8_t channel = 0); float getMaxPhase(); void setPhaseChannel(uint8_t channel); float setPhaseRadians(float phase, uint8_t channel = 0); float getPhaseRadians(uint8_t channel = 0); ``` -------------------------------- ### Hardware SPI Configuration Source: https://github.com/robtillaart/ad9833/blob/master/README.md Functions to set and get the SPI speed, and check if hardware SPI is used. ```C++ void setSPIspeed(uint32_t speed); uint32_t getSPIspeed(); bool usesHWSPI(); ``` -------------------------------- ### HLB Mode Frequency Setting Source: https://github.com/robtillaart/ad9833/blob/master/README.md Functions to set frequency in coarse (MSB) and fine (LSB) steps for HLB mode. ```C++ void writeFrequencyRegisterLSB(uint8_t channel, uint16_t LSB); void writeFrequencyRegisterMSB(uint8_t channel, uint16_t MSB); ``` -------------------------------- ### Low-level API - Register Access Source: https://github.com/robtillaart/ad9833/blob/master/README.md Functions for direct register access to the AD9833 device. ```C++ void writeControlRegister(uint16_t value); uint16_t readControlRegisterCache(); void writeFrequencyRegister(uint8_t channel, uint32_t freq); void writePhaseRegister(uint8_t channel, uint16_t value); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.