Xmega Application Note


adc_driver.h

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00060 #ifndef ADC_DRIVER_H
00061 #define ADC_DRIVER_H
00062 
00063 #include "avr_compiler.h"
00064 
00065 
00066 #define COMMON_MODE_CYCLES 16
00067 
00068 
00069 /* Macros */
00070 
00083 #define ADC_Enable(_adc) ((_adc)->CTRLA |= ADC_ENABLE_bm)
00084 
00089 #define ADC_Disable(_adc) ((_adc)->CTRLA = (_adc)->CTRLA & (~ADC_ENABLE_bm))
00090 
00095 #define ADC_Pipeline_Flush(_adc) ((_adc)->CTRLA |= ADC_FLUSH_bm)
00096 
00097 
00111 #define ADC_ConvMode_and_Resolution_Config(_adc, _signedMode, _resolution)     \
00112         ((_adc)->CTRLB = ((_adc)->CTRLB & (~(ADC_RESOLUTION_gm|ADC_CONMODE_bm)))|  \
00113                 (_resolution| ( _signedMode? ADC_CONMODE_bm : 0)))
00114 
00119 #define ADC_ConvMode_Signed true
00120 
00125 #define ADC_ConvMode_Unsigned false
00126 
00127 
00140 #define ADC_Prescaler_Config(_adc, _div)                                       \
00141         ((_adc)->PRESCALER = ((_adc)->PRESCALER & (~ADC_PRESCALER_gm)) | _div)
00142 
00143 
00150 #define ADC_Reference_Config(_adc, _convRef)                                   \
00151         ((_adc)->REFCTRL = ((_adc)->REFCTRL & ~(ADC_REFSEL_gm)) | _convRef)
00152 
00153 
00159 #define ADC_SweepChannels_Config(_adc, _sweepChannels)                         \
00160         ((_adc)->EVCTRL = ((_adc)->EVCTRL & (~ADC_SWEEP_gm)) | _sweepChannels)
00161 
00162 
00176 #define ADC_Events_Config(_adc, _eventChannels, _eventMode)                    \                                                                           \
00177         (_adc)->EVCTRL = ((_adc)->EVCTRL & (~(ADC_EVSEL_gm | ADC_EVACT_gm))) | \
00178                          ((uint8_t) _eventChannels | _eventMode)
00179 
00180 
00195 #define ADC_Ch_Interrupts_Config(_adc_ch, _interruptMode, _interruptLevel)     \
00196         (_adc_ch)->INTCTRL = (((_adc_ch)->INTCTRL &                            \
00197                               (~(ADC_CH_INTMODE_gm | ADC_CH_INTLVL_gm))) |     \
00198                               ((uint8_t) _interruptMode | _interruptLevel))
00199 
00200 
00210 #define ADC_Ch_InputMode_and_Gain_Config(_adc_ch, _inputMode, _gain)           \
00211         (_adc_ch)->CTRL = ((_adc_ch)->CTRL &                                   \
00212                           (~(ADC_CH_INPUTMODE_gm|ADC_CH_GAINFAC_gm))) |        \
00213                           ((uint8_t) _inputMode|_gain)
00214 
00215 
00220 #define ADC_DRIVER_CH_GAIN_NONE ADC_CH_GAIN_1X_gc
00221 
00222 
00233 #define ADC_Ch_InputMux_Config(_adc_ch, _posInput, _negInput)                  \
00234         ((_adc_ch)->MUXCTRL = (uint8_t) _posInput | _negInput)
00235 
00236 
00243 #define ADC_Ch_Conversion_Complete(_adc_ch)                                    \
00244         (((_adc_ch)->INTFLAGS & ADC_CH_CHIF_bm) != 0x00)
00245 
00246 
00260 #define ADC_CompareValue_Set(_adc, _value) ((_adc)->CMP = _value)
00261 
00262 
00267 #define ADC_FreeRunning_Enable(_adc)  ((_adc)->CTRLB |= ADC_FREERUN_bm)
00268 
00269 
00274 #define ADC_FreeRunning_Disable(_adc)                                          \
00275         ((_adc)->CTRLB = (_adc)->CTRLB & (~ADC_FREERUN_bm))
00276 
00277 
00286 #define ADC_Ch_Conversion_Start(_adc_ch) ((_adc_ch)->CTRL |= ADC_CH_START_bm)
00287 
00288 
00300 #define ADC_Conversions_Start(_adc, _channelMask)                         \
00301         (_adc)->CTRLA |= _channelMask &                                   \
00302                       (ADC_CH0START_bm | ADC_CH1START_bm |                \
00303                        ADC_CH2START_bm | ADC_CH3START_bm)
00304 
00305 
00312 #define ADC_BandgapReference_Enable(_adc) ((_adc)->REFCTRL |= ADC_BANDGAP_bm)
00313 
00314 
00319 #define ADC_BandgapReference_Disable(_adc) ((_adc)->REFCTRL &= ~ADC_BANDGAP_bm)
00320 
00321 
00328 #define ADC_TempReference_Enable(_adc) ((_adc)->REFCTRL |= ADC_TEMPREF_bm)
00329 
00330 
00335 #define ADC_TempReference_Disable(_adc)                                        \
00336         ((_adc)->REFCTRL = (_adc)->REFCTRL & (~ADC_TEMPREF_bm))
00337 
00338 
00339 /* Prototype for assembly macro. */
00340 uint8_t SP_ReadCalibrationByte( uint8_t index );
00341 
00342 /* Prototypes for functions. */
00343 void ADC_CalibrationValues_Load(ADC_t * adc);
00344 
00345 uint16_t ADC_ResultCh_GetWord_Unsigned(ADC_CH_t * adc_ch, uint8_t offset);
00346 int16_t ADC_ResultCh_GetWord_Signed(ADC_CH_t * adc_ch, int8_t offset);
00347 
00348 uint8_t ADC_Offset_Get_Unsigned(ADC_t * adc, ADC_CH_t *ch, bool oversampling);
00349 int8_t ADC_Offset_Get_Signed(ADC_t * adc, ADC_CH_t *ch, bool oversampling);
00350 
00351 uint16_t ADC_ResultCh_GetWord(ADC_CH_t * adc_ch);
00352 uint8_t ADC_ResultCh_GetLowByte(ADC_CH_t * adc_ch);
00353 uint8_t  ADC_ResultCh_GetHighByte(ADC_CH_t * adc_ch);
00354 
00355 void ADC_Wait_8MHz(ADC_t * adc);
00356 void ADC_Wait_32MHz(ADC_t * adc);
00357 
00363 #define ADC_Referance_Config(_adc, _convRef) ADC_Reference_Config(_adc, _convRef)
00364 #define ADC_CalibrationValues_Set(_adc) ADC_CalibrationValues_Load(_adc)
00365 
00366 
00367 
00373 #ifndef ADCACAL0_offset
00374 
00375 #define ADCACAL0_offset 0x20
00376 #define ADCACAL1_offset 0x21
00377 #define ADCBCAL0_offset 0x24
00378 #define ADCBCAL1_offset 0x25
00379 #endif
00380 
00381 
00382 #endif
@DOC_TITLE@
Generated on Tue Aug 4 13:31:15 2009 for AVR1300 Using the XMEGA ADC by doxygen 1.5.3