Xmega Application Note


dac_example.c

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00059 #include "dac_driver.h"
00060 
00061 
00068 int main( void )
00069 {
00070         uint16_t angle;
00071 
00072         /*  Given 2 MHz CPU speed, this is configured to 2µs separation time and
00073          *  16µs refresh time.
00074          */
00075         DAC_DualChannel_Enable( &DACA,
00076                                 DAC_REFSEL_AVCC_gc,
00077                                 false,
00078                                 DAC_CONINTVAL_4CLK_gc,
00079                                 DAC_REFRESH_32CLK_gc );
00080 
00081         /*  Use a 12 bit variable to output two triangle waves, separated by
00082          *  180 degrees phase, as fast as possible.
00083          */
00084         while (1) {
00085                 for ( angle = 0; angle < 0x1000; ++angle ) {
00086                         while ( DAC_Channel_DataEmpty( &DACA, CH0 ) == false ) {
00087                                 /* Blocking code waiting for empty register. */
00088                         }
00089                         DAC_Channel_Write( &DACA, angle, CH0 );
00090                         while ( DAC_Channel_DataEmpty( &DACA, CH1 ) == false ) {
00091                                 /* Blocking code waiting for empty register. */
00092                         }
00093                         DAC_Channel_Write( &DACA, 0xFFF - angle, CH1 );
00094                 }
00095                 for ( angle = 0; angle < 0x1000; ++angle ) {
00096                         while ( DAC_Channel_DataEmpty( &DACA, CH0 ) == false ) {
00097                                 /* Blocking code waiting for empty register. */
00098                         }
00099                         DAC_Channel_Write( &DACA, 0xFFF - angle, CH0 );
00100                         while ( DAC_Channel_DataEmpty( &DACA, CH1 ) == false ) {
00101                                 /* Blocking code waiting for empty register. */
00102                         }
00103                         DAC_Channel_Write( &DACA, angle, CH1 );
00104                 }
00105         }
00106 }
@DOC_TITLE@
Generated on Wed May 14 16:11:05 2008 for AVR1301 Using the XMEGA DAC by doxygen 1.5.5