Xmega Application Note


dac_driver.c

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00066 #include "dac_driver.h"
00067 
00068 
00079 void DAC_SingleChannel_Enable( volatile DAC_t * dac,
00080                               DAC_REFSEL_t convRef,
00081                               bool leftAdjust )
00082 {
00083         dac->CTRLB = ( dac->CTRLB & ~DAC_CHSEL_gm ) | DAC_CHSEL_SINGLE_gc;
00084         dac->CTRLC = ( dac->CTRLC & ~(DAC_REFSEL_gm | DAC_LEFTADJ_bm) ) |
00085                      convRef | ( leftAdjust ? DAC_LEFTADJ_bm : 0x00 );
00086         dac->CTRLA = ( dac->CTRLA & ~DAC_CH1EN_bm ) |
00087                      DAC_CH0EN_bm | DAC_ENABLE_bm;
00088 }
00089 
00090 
00103 void DAC_DualChannel_Enable( volatile DAC_t * dac,
00104                             DAC_REFSEL_t convRef,
00105                             bool leftAdjust,
00106                             DAC_CONINTVAL_t sampleInterval,
00107                             DAC_REFRESH_t refreshInterval )
00108 {
00109         dac->CTRLB = ( dac->CTRLB & ~DAC_CHSEL_gm ) | DAC_CHSEL_DUAL_gc;
00110         dac->CTRLC = ( dac->CTRLC & ~( DAC_REFSEL_gm | DAC_LEFTADJ_bm ) ) |
00111                      convRef |
00112                      ( leftAdjust ? DAC_LEFTADJ_bm : 0x00 );
00113         dac->TIMCTRL = (uint8_t) sampleInterval | refreshInterval;
00114         dac->CTRLA |= DAC_CH1EN_bm | DAC_CH0EN_bm | DAC_ENABLE_bm;
00115 }
00116 
00117 
00131 void DAC_Channel_Write( volatile DAC_t * dac, uint16_t data, DAC_CH_t channel )
00132 {
00133         if ( channel == CH0 ) {
00134                 dac->CH0DATA = data;
00135         } else {
00136                 dac->CH1DATA = data;
00137         }
00138 }
00139 
00140 
00153 bool DAC_Channel_DataEmpty( volatile DAC_t * dac, DAC_CH_t channel )
00154 {
00155         bool dacStatus = ( dac->STATUS &
00156                          ( channel ? DAC_CH1DRE_bm : DAC_CH0DRE_bm ));
00157         return dacStatus;
00158 }
00159 
00160 
00174 void DAC_EventAction_Set( volatile DAC_t * dac,
00175                           DAC_TRIG_t trigChannel,
00176                           uint8_t eventLine )
00177 {
00178         dac->CTRLB = ( dac->CTRLB & ~DAC_TRIG_1_1 ) | trigChannel;
00179         dac->EVCTRL = eventLine & DAC_EVSEL_gm;
00180 }
@DOC_TITLE@
Generated on Wed May 14 16:11:05 2008 for AVR1301 Using the XMEGA DAC by doxygen 1.5.5