Skip to content

Add minimal example to documentation #4

@fluffynukeit

Description

@fluffynukeit

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) >"));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions