AD9833-Library-Arduino
AD9833-Library-Arduino copied to clipboard
Add minimal example to documentation
Hi. I am attempting to use your library to control an AD9833 board module. I can see the default ~1000Hz sine wave on my scope. I am trying to generate a sine wave of a different frequency, say 300 Hz. I can program the frequency and read it back with GetActualProgrammedFrequency.
****** AD9833 Frequency Menu ******
Current programmed frequency is 999.96106 Enter an float frequency (HZ) > Sine wave frequency 300.00 Hz.
****** AD9833 Frequency Menu ******
Current programmed frequency is 299.97900 Enter an float frequency (HZ) >
The sine wave on the scope is still ~1000Hz, however. The fact that I can read back a programmed frequency close to 300 Hz indicates to me that my comms are fine. The only thing I can think of is that I have to latch the new configuration somehow.
Could you please add a minimal example that changes the default waveform to a different frequency? What I am using (shown below) is close to minimal but still doesn't work. I've tried different combination of EnableOutput and Reset, etc, trying to get the frequency to change but still no dice. A minimal example would be a useful addition I think. Thanks.
void setup() {
while (!Serial); // Delay until terminal opens
Serial.begin(9600);
// This MUST be the first command after declaring the AD9833 object
gen.Begin(); // The loaded defaults are 1000 Hz SINE_WAVE using REG0
// The output is OFF, Sleep mode is disabled
gen.EnableOutput(true);
PrintMenu(); // Display menu for the first time
}
void StartWave(float hz)
{
if (hz < 0)
{
Serial.print(F("*** Invalid frequency "));
Serial.print(hz);
Serial.println(F(" ignored ***"));
return;
}
gen.ApplySignal(SINE_WAVE,REG0,hz);
Serial.print(F("Sine wave frequency "));
Serial.print(hz);
Serial.println(F(" Hz."));
}
void loop() {
if ( Serial.available() ) {
float hz = Serial.parseFloat();
StartWave(hz);
PrintMenu();
}
}
/*
* Display the command menu
*/
void PrintMenu () {
float programmedFrequency = gen.GetActualProgrammedFrequency(REG0);
char buffer[20]; // 14 characters actually needed for display
dtostrf(programmedFrequency,14,5,buffer);
Serial.println(); Serial.println();
Serial.println(F("****** AD9833 Frequency Menu ******\n"));
Serial.print(F("Current programmed frequency is "));
Serial.println(buffer);
Serial.println(F("Enter an float frequency (HZ) >"));
}
Hi,
I'm sorry you're having so much trouble. I copied your sample code and ran it and, unfortunately, it worked fine for me. I'm at a loss to explain why you are not seeing the frequency change. Perhaps a bad connection on the FNC, CLK, or MOSI pins? Note that the value returned by GetActualProgrammedFrequency will be reporting correctly even if there is no communication with the AD9833, since the calculations are done in the library, not in the chip itself.
I will add another sketch showing the simplest setups.
Thanks for your comments and good luck. Let me know if you find the problem.
Bill
Poor connection to FNC was indeed the problem. It was my mistake assuming the GetActual was doing comms with the chip, which led me down the wrong debugging path assuming connections were fine. I fixed FNC and now I get clean signals at the commanded frequency.
Great!
Hi I'm struggling with this AD 9833 module. In fact, where does the FNC need to be connected? Thank you