BLDC control on ATAVRMC303 with ATxMega128A1
adc_driver.h
Go to the documentation of this file.
1 /* This file has been prepared for Doxygen automatic documentation generation.*/
60 #ifndef ADC_DRIVER_H
61 #define ADC_DRIVER_H
62 
63 #include "avr_compiler.h"
64 
65 
66 #define COMMEN_MODE_CYCLES 16
67 
68 
69 /* Macros */
70 
83 #define ADC_Enable(_adc) ((_adc)->CTRLA |= ADC_ENABLE_bm)
84 
89 #define ADC_Disable(_adc) ((_adc)->CTRLA = (_adc)->CTRLA & (~ADC_ENABLE_bm))
90 
95 #define ADC_Pipeline_Flush(_adc) ((_adc)->CTRLA |= ADC_FLUSH_bm)
96 
97 
110 #define ADC_ConvMode_and_Resolution_Config(_adc, _signedMode, _resolution) \
111  ((_adc)->CTRLB = ((_adc)->CTRLB & (~(ADC_RESOLUTION_gm|ADC_CONMODE_bm)))| \
112  (_resolution| ( _signedMode? ADC_CONMODE_bm : 0)))
113 
114 
127 #define ADC_Prescaler_Config(_adc, _div) \
128  ((_adc)->PRESCALER = ((_adc)->PRESCALER & (~ADC_PRESCALER_gm)) | _div)
129 
130 
137 #define ADC_Referance_Config(_adc, _convRef) \
138  ((_adc)->REFCTRL = ((_adc)->REFCTRL & ~(ADC_REFSEL_gm)) | _convRef)
139 
140 
146 #define ADC_SweepChannels_Config(_adc, _sweepChannels) \
147  ((_adc)->EVCTRL = ((_adc)->EVCTRL & (~ADC_SWEEP_gm)) | _sweepChannels)
148 
149 
163 #define ADC_Events_Config(_adc, _eventChannels, _eventMode) \ \
164  (_adc)->EVCTRL = ((_adc)->EVCTRL & (~(ADC_EVSEL_gm | ADC_EVACT_gm))) | \
165  ((uint8_t) _eventChannels | _eventMode)
166 
167 
182 #define ADC_Ch_Interrupts_Config(_adc_ch, _interruptMode, _interruptLevel) \
183  (_adc_ch)->INTCTRL = (((_adc_ch)->INTCTRL & \
184  (~(ADC_CH_INTMODE_gm | ADC_CH_INTLVL_gm))) | \
185  ((uint8_t) _interruptMode | _interruptLevel))
186 
187 
197 #define ADC_Ch_InputMode_and_Gain_Config(_adc_ch, _inputMode, _gain) \
198  (_adc_ch)->CTRL = ((_adc_ch)->CTRL & \
199  (~(ADC_CH_INPUTMODE_gm|ADC_CH_GAINFAC_gm))) | \
200  ((uint8_t) _inputMode|_gain)
201 
212 #define ADC_Ch_InputMux_Config(_adc_ch, _posInput, _negInput) \
213  ((_adc_ch)->MUXCTRL = (uint8_t) _posInput | _negInput)
214 
215 
222 #define ADC_Ch_Conversion_Complete(_adc_ch) \
223  (((_adc_ch)->INTFLAGS & ADC_CH_CHIF_bm) != 0x00)
224 
225 
239 #define ADC_CompareValue_Set(_adc, _value) ((_adc)->CMP = _value)
240 
241 
246 #define ADC_FreeRunning_Enable(_adc) ((_adc)->CTRLB |= ADC_FREERUN_bm)
247 
248 
253 #define ADC_FreeRunning_Disable(_adc) \
254  ((_adc)->CTRLB = (_adc)->CTRLB & (~ADC_FREERUN_bm))
255 
256 
265 #define ADC_Ch_Conversion_Start(_adc_ch) ((_adc_ch)->CTRL |= ADC_CH_START_bm)
266 
267 
279 #define ADC_Conversions_Start(_adc, _channelMask) \
280  (_adc)->CTRLA |= _channelMask & \
281  (ADC_CH0START_bm | ADC_CH1START_bm | \
282  ADC_CH2START_bm | ADC_CH3START_bm)
283 
284 
291 #define ADC_BandgapReference_Enable(_adc) ((_adc)->REFCTRL |= ADC_BANDGAP_bm)
292 
293 
298 #define ADC_BandgapReference_Disable(_adc) ((_adc)->REFCTRL &= ~ADC_BANDGAP_bm)
299 
300 
307 #define ADC_TempReference_Enable(_adc) ((_adc)->REFCTRL |= ADC_TEMPREF_bm)
308 
309 
314 #define ADC_TempReference_Disable(_adc) \
315  ((_adc)->REFCTRL = (_adc)->REFCTRL & (~ADC_TEMPREF_bm))
316 
317 
318 /* Prototype for assembly macro. */
319 uint8_t SP_ReadCalibrationByte( uint8_t index );
320 
321 /* Prototypes for functions. */
322 void ADC_CalibrationValues_Set(ADC_t * adc);
323 uint16_t ADC_ResultCh_GetWord(ADC_CH_t * adc_ch, uint8_t offset);
324 uint8_t ADC_ResultCh_GetLowByte(ADC_CH_t * adc_ch, uint8_t offset);
325 uint8_t ADC_ResultCh_GetHighByte(ADC_CH_t * adc_ch);
326 void ADC_Wait_8MHz(ADC_t * adc);
327 void ADC_Wait_32MHz(ADC_t * adc);
328 uint8_t ADC_Offset_Get(ADC_t * adc);
329 
330 #endif
331 
uint8_t ADC_ResultCh_GetLowByte(ADC_CH_t *adc_ch, uint8_t offset)
This function clears the interrupt flag and returns the low byte of the coversion result...
Definition: adc_driver.c:131
uint16_t ADC_ResultCh_GetWord(ADC_CH_t *adc_ch, uint8_t offset)
This function clears the interrupt flag and returns the coversion result.
Definition: adc_driver.c:98
uint8_t ADC_Offset_Get(ADC_t *adc)
This function get the offset of the ADC.
Definition: adc_driver.c:241
This file implements some macros that makes the IAR C-compiler and avr-gcc work with the same code ba...
void ADC_CalibrationValues_Set(ADC_t *adc)
This function get the calibration data from the production calibration.
Definition: adc_driver.c:77
uint8_t ADC_ResultCh_GetHighByte(ADC_CH_t *adc_ch)
This function clears the interrupt flag and returns the high byte of the coversion result...
Definition: adc_driver.c:160
uint8_t SP_ReadCalibrationByte(uint8_t index)
void ADC_Wait_8MHz(ADC_t *adc)
This function waits until the adc common mode is settled.
Definition: adc_driver.c:182
void ADC_Wait_32MHz(ADC_t *adc)
This function waits until the adc common mode is settled.
Definition: adc_driver.c:214
volatile char offset
Definition: mc_drv.c:47