I'll give you a rough idea how to do it.
But, the real problem comes into being able to send out the samples fast enough.
- To start, you generate a table of samples that represents one period of the waveform.
- Then, you will write each sample to a DAC at a fixed rate between each write.
Repeating the table when you reach the end.
- The rate you write the samples will determine the frequency of the waveform.
- Then, the DAC output would go to an op-amp for scaling and DC offset.
As an example:
Consider a single cycle of a sine wave which you would write to a 8-bit DAC.
Assuming a DAC like an MCP4802 which outputs a 0 to 4 volt signal.
As you sequence through the table, the DAC will generate the sine wave one cycle at a time.
Where writing a 0 to the DAC outputs 0 volts and writing a 255 to the DAC outputs 4 volts.
The table represents one cycle of the waveform which will be repeated.
You can put any waveform shape you wish to generate into the table (hence "arbitrary" waveform).
Like I said, the frequency is a function of the rate you sequence through the table.
There are two ways to change the frequency.
- One is the rate you write each sample to the DAC.
- The second, is by using a constant sample rate but skipping samples (i.e. every other sample or every third sample).
- Or a combination of both depending on how fine the samples are.
This works fairly well for a micro-controller to clock the samples to a DAC to generate audio frequencies. For higher frequencies, the process really needs to be done in hardware (like a AD9834 DDS chip for instance). In order to generate a frequency, you would want to have at least 10 samples per cycle. Therefore, the rate you write samples would be at least 10 times faster than the frequency you want to generate.
In my opinion, arbitrary waveforms are over rated. In the majority of cases, a sine, triangle or square wave will satisfy test conditions.