This example shows one way to use the Digital to Analog Converter (DAC) for outputting a sample buffer at a constant conversion rate.
The DAC driver API can be found here.
All AVR XMEGA devices with a DAC can be used.
This example sets up the configured DAC (SPEAKER_DAC) to perform DA conversions on one channel (SPEAKER_DAC_CHANNEL), with output to a pin, every time it receives events in event channel 0. Timer/counter 0 on port C is used to generate the events on overflow. This setup gives a constant conversion rate.
The main loop in the example waits for the DAC channel to get ready for new data, then feeds it with a new sample from a sample buffer that contains one period of a sine wave. The DAC channel is not flagged as ready for new data until a conversion has completed, i.e., after the DAC has received an event.
This software was written for the GNU GCC and IAR for AVR. Other compilers may or may not work.
For further information, visit Microchip.