Chapter 17. DAC

The Digital-to-Analog Converter (DAC) takes a digital value from software and generates an analog signal.

ZDev provides APIs to generate voltages on DAC channels. The DAC API also supports value scaling similar to the ADC API. The DAC functions are declared in dac.h. The no. of DAC channels is indicated by the constant DAC_NCHANNELS. The following example generates a 1Hz sawtooth wave on DAC channel 0.

Listing 17.1. 1Hz Sawtooth

#include <board.h>
#include <delay.h>
#include <dac.h>

int main()
{
        int i;

        board_init();
        delay_init();
        dac_init(); /* Initialize the DAC. */

        while (1) {
                for (i = 0; i < 256; i++) {
                        /* Write the sample to the DAC channel 0. */
                        dac_write8(0, i);
                        mdelay(4);
                }
        }
}