I want to use such a generator (based on arduino)
https://github.com/Billwilliams1952/AD9833-Library-ArduinoAnd then he wants to change changing frequency of the generator base oryginal 25 MHz change to 10 MHz
The question is, where there in the code to insert an entry to the generator base was frequency 10 MHz?
File AD9833.hCode :
ifndef __AD9833__
#define __AD9833__
#include <Arduino.h>
#include <SPI.h>
//#define FNC_PIN 4 // Define FNC_PIN for fast digital writes
#ifdef FNC_PIN
// Use digitalWriteFast for a speedup
#include "digitalWriteFast.h"
#define WRITE_FNCPIN(Val) digitalWriteFast2(FNC_PIN,(Val))
#else // otherwise, just use digitalWrite
#define WRITE_FNCPIN(Val) digitalWrite(FNCpin,(Val))
#endif
#define pow2_28 268435456L // 2^28 used in frequency word calculation
#define BITS_PER_DEG 11.3777777777778 // 4096 / 360
#define RESET_CMD 0x0100 // Reset enabled (also CMD RESET)
/* Sleep mode
* D7 1 = internal clock is disabled
* D6 1 = put DAC to sleep
*/
#define SLEEP_MODE 0x00C0 // Both DAC and Internal Clock
#define DISABLE_DAC 0x0040
#define DISABLE_INT_CLK 0x0080
#define PHASE_WRITE_CMD 0xC000 // Setup for Phase write
#define PHASE1_WRITE_REG 0x2000 // Which phase register
#define FREQ0_WRITE_REG 0x4000 //
#define FREQ1_WRITE_REG 0x8000
#define PHASE1_OUTPUT_REG 0x0400 // Output is based off REG0/REG1
#define FREQ1_OUTPUT_REG 0x0800 // ditto
typedef enum { SINE_WAVE = 0x2000, TRIANGLE_WAVE = 0x2002,
SQUARE_WAVE = 0x2028, HALF_SQUARE_WAVE = 0x2020 } WaveformType;
typedef enum { REG0, REG1, SAME_AS_REG0 } Registers;
class AD9833 {
public:
AD9833 ( uint8_t FNCpin, uint32_t referenceFrequency = 25000000UL );
// Must be the first command after creating the AD9833 object.
void Begin ( void );
// Setup and apply a signal. Note that any calls to EnableOut,
// SleepMode, DisableDAC, or DisableInternalClock remain in effect
void ApplySignal ( WaveformType waveType, Registers freqReg,
float frequencyInHz,
Registers phaseReg = SAME_AS_REG0, float phaseInDeg = 0.0 );
// Resets internal registers to 0, which corresponds to an output of
// midscale - digital output at 0. See EnableOutput function
void Reset ( void );
// Update just the frequency in REG0 or REG1
void SetFrequency ( Registers freqReg, float frequency );
// Increment the selected frequency register by freqIncHz
void IncrementFrequency ( Registers freqReg, float freqIncHz );
// Update just the phase in REG0 or REG1
void SetPhase ( Registers phaseReg, float phaseInDeg );
// Increment the selected phase register by phaseIncDeg
void IncrementPhase ( Registers phaseReg, float phaseIncDeg );
// Set the output waveform for the selected frequency register
// SINE_WAVE, TRIANGLE_WAVE, SQUARE_WAVE, HALF_SQUARE_WAVE,
void SetWaveform ( Registers waveFormReg, WaveformType waveType );
// Output based on the contents of REG0 or REG1
void SetOutputSource ( Registers freqReg, Registers phaseReg = SAME_AS_REG0 );
// Turn ON / OFF output using the RESET command.
void EnableOutput ( bool enable );
// Enable/disable Sleep mode. Internal clock and DAC disabled
void SleepMode ( bool enable );
// Enable / Disable DAC
void DisableDAC ( bool enable );
// Enable / Disable Internal Clock
void DisableInternalClock ( bool enable );
// Return actual frequency programmed in register
float GetActualProgrammedFrequency ( Registers reg );
// Return actual phase programmed in register
float GetActualProgrammedPhase ( Registers reg );
// Return frequency resolution
float GetResolution ( void );
private:
void WriteRegister ( int16_t dat );
void WriteControlRegister ( void );
uint16_t waveForm0, waveForm1;
#ifndef FNC_PIN
uint8_t FNCpin;
#endif
uint8_t outputEnabled, DacDisabled, IntClkDisabled;
uint32_t refFrequency;
float frequency0, frequency1, phase0, phase1;
Registers activeFreq, activePhase;
};
#endif
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
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,1000);
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
}
void loop() {
// To change the signal, you can just call ApplySignal again with a new frequency and/or signal
// type.
}