Digital to Analog Conversion

Using the Config tool, write a DAC0_Init function in a c program, dac0.c, to configure DAC0 to be enabled (and initialized to 0), to update on a Timer2 overflow, and to be right justified. Also configure the Reference Control Register in this routine so that the Reference Buffer Control specifies using the Internal Vref and the internal bias generator is enabled.

You will also need a Timer2_Init function to configure Timer 2 for 16-bit auto-reload mode  and to use the default system clock..

Now we will write a simple main function  to slowly (so we can see each .1V interval on the multimeter) swing the DAC output voltage from 0V to the reference, 2.4V. Synchronize conversions with the Timer2 overflow using polling. (do not forget to clear that overflow flag each time it goes high!) Your program should be written so that it is easy to change the auto-reload value, since this may need adjustment for the sweep rate. It is helpful to use the sfr16 declaration keyword to define DAC0 and the RCAP2 register.

You can access the DAC0 output on pin3 of the J20 terminal block. Analog GND is available on pin 8 on the terminal block.