Skip to main content

Pulsed Arbitrary Output Waveform

The Quarto can act an arbitrary waveform generator. But more than that, its output can be externally controlled. In this example, the Quarto outputs 10 periods of a 10 kHz sine wave whenever trigger signal goes high.

This code will use an IntervalTimer to set how often the DAC is updated.

Code

IntervalTimer DAC_Timer; //Use an interval timer to set update rate for DAC
unsigned int DACcounts = 0; //store how many DAC updates have been complete
const uint updateRate = 1; // in microseconds
const float frequency = 10e3; // 10 kHz sine wave
const uint numberOfPeriods = 10; // show 10 periods

void setup() {
triggerMode(1, INPUT); // Set trigger1 as input
enableInterruptTrigger(1,RISING_EDGE,&start_pattern); //On rising edge, run start_pattern
}

void start_pattern() {
DACcounts = 0; //reset DACcounts

// start timer to run at update rate (every 1 µs) and call updateDAC
DAC_Timer.begin(updateDAC, updateRate);
}

void updateDAC() {
float value = 2.5 * sin(DACcounts * 2 * PI * frequency * updateRate * 1e-6) ; //generate sin wave
writeDAC(1,value); //write value to DAC
DACcounts++; // increment DACcounts by one.

// after number number of Periods stop. Convert to number of updates
if (DACcounts == numberOfPeriods / (frequency*updateRate * 1e-6) ) {
DAC_Timer.end();
}
}

Data

Using this code, if when you send trigger 1 high, you'll get 10 cycles of a 10 kHz sine wave as shown below.

img