BLDC control on ATAVRMC303 with ATxMega128A1
adc_driver.h File Reference

XMEGA ADC driver header file. More...

#include "avr_compiler.h"
Include dependency graph for adc_driver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ADC_BandgapReference_Disable(_adc)   ((_adc)->REFCTRL &= ~ADC_BANDGAP_bm)
 This macro disables the pre enabled the Bandgap Reference. More...
 
#define ADC_BandgapReference_Enable(_adc)   ((_adc)->REFCTRL |= ADC_BANDGAP_bm)
 This macro pre enables the Bandgap Reference. More...
 
#define ADC_Ch_Conversion_Complete(_adc_ch)   (((_adc_ch)->INTFLAGS & ADC_CH_CHIF_bm) != 0x00)
 This macro returns the channel conversion complete flag.. More...
 
#define ADC_Ch_Conversion_Start(_adc_ch)   ((_adc_ch)->CTRL |= ADC_CH_START_bm)
 This macro start one channel conversion. More...
 
#define ADC_Ch_InputMode_and_Gain_Config(_adc_ch, _inputMode, _gain)
 This macro configures the input mode and gain to a specific virtual channel. More...
 
#define ADC_Ch_InputMux_Config(_adc_ch, _posInput, _negInput)   ((_adc_ch)->MUXCTRL = (uint8_t) _posInput | _negInput)
 This macro configures the Positiv and negativ inputs. More...
 
#define ADC_Ch_Interrupts_Config(_adc_ch, _interruptMode, _interruptLevel)
 This macro configures the interrupt mode and level for one channel. More...
 
#define ADC_CompareValue_Set(_adc, _value)   ((_adc)->CMP = _value)
 This macro sets the value in the ADC compare register. More...
 
#define ADC_Conversions_Start(_adc, _channelMask)
 This macro start multiple channel conversions. More...
 
#define ADC_ConvMode_and_Resolution_Config(_adc, _signedMode, _resolution)
 This macro set the conversion mode and resolution in the selected adc. More...
 
#define ADC_Disable(_adc)   ((_adc)->CTRLA = (_adc)->CTRLA & (~ADC_ENABLE_bm))
 This macro disables the selected adc. More...
 
#define ADC_Enable(_adc)   ((_adc)->CTRLA |= ADC_ENABLE_bm)
 This macro enables the selected adc. More...
 
#define ADC_Events_Config(_adc, _eventChannels, _eventMode)
 This macro configures the event channels used and the event mode. More...
 
#define ADC_FreeRunning_Disable(_adc)   ((_adc)->CTRLB = (_adc)->CTRLB & (~ADC_FREERUN_bm))
 This macro disables the Free Running mode in the selected adc. More...
 
#define ADC_FreeRunning_Enable(_adc)   ((_adc)->CTRLB |= ADC_FREERUN_bm)
 This macro enables the Free Running mode in the selected adc. More...
 
#define ADC_Pipeline_Flush(_adc)   ((_adc)->CTRLA |= ADC_FLUSH_bm)
 This macro flushes the pipline in the selected adc. More...
 
#define ADC_Prescaler_Config(_adc, _div)   ((_adc)->PRESCALER = ((_adc)->PRESCALER & (~ADC_PRESCALER_gm)) | _div)
 This macro set the prescaler factor in the selected adc. More...
 
#define ADC_Referance_Config(_adc, _convRef)   ((_adc)->REFCTRL = ((_adc)->REFCTRL & ~(ADC_REFSEL_gm)) | _convRef)
 This macro set the conversion referance in the selected adc. More...
 
#define ADC_SweepChannels_Config(_adc, _sweepChannels)   ((_adc)->EVCTRL = ((_adc)->EVCTRL & (~ADC_SWEEP_gm)) | _sweepChannels)
 This macro sets the sweep channel settings. More...
 
#define ADC_TempReference_Disable(_adc)   ((_adc)->REFCTRL = (_adc)->REFCTRL & (~ADC_TEMPREF_bm))
 This macro disables the temperature reference. More...
 
#define ADC_TempReference_Enable(_adc)   ((_adc)->REFCTRL |= ADC_TEMPREF_bm)
 This macro makes sure that the temperature reference circuitry is enabled. More...
 
#define COMMEN_MODE_CYCLES   16
 

Functions

void ADC_CalibrationValues_Set (ADC_t *adc)
 This function get the calibration data from the production calibration. More...
 
uint8_t ADC_Offset_Get (ADC_t *adc)
 This function get the offset of the ADC. More...
 
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. More...
 
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. More...
 
uint16_t ADC_ResultCh_GetWord (ADC_CH_t *adc_ch, uint8_t offset)
 This function clears the interrupt flag and returns the coversion result. More...
 
void ADC_Wait_32MHz (ADC_t *adc)
 This function waits until the adc common mode is settled. More...
 
void ADC_Wait_8MHz (ADC_t *adc)
 This function waits until the adc common mode is settled. More...
 
uint8_t SP_ReadCalibrationByte (uint8_t index)
 

Detailed Description

XMEGA ADC driver header file.

This file contains the function prototypes and enumerator definitions for various configuration parameters for the XMEGA ADC driver that is implemented in C.

The driver is not intended for size and/or speed critical code, since most functions are just a few lines of code, and the function call overhead would decrease code performance. The driver is intended for rapid prototyping and documentation purposes for getting started with the XMEGA ADC module.

For size and/or speed critical code, it is recommended to copy the function contents directly into your application instead of making a function call.

Application note:
AVR1300: Using the XMEGA ADC
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author
Atmel Corporation: http://www.atmel.com
Support email: avr@a.nosp@m.tmel.nosp@m..com
Revision
1569
Date
2008-04-22 13:03:43 +0200 (ti, 22 apr 2008)


Copyright (c) 2008, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file adc_driver.h.

Macro Definition Documentation

◆ ADC_BandgapReference_Disable

#define ADC_BandgapReference_Disable (   _adc)    ((_adc)->REFCTRL &= ~ADC_BANDGAP_bm)

This macro disables the pre enabled the Bandgap Reference.

Parameters
_adcPointer to ADC module register section.

Definition at line 298 of file adc_driver.h.

◆ ADC_BandgapReference_Enable

#define ADC_BandgapReference_Enable (   _adc)    ((_adc)->REFCTRL |= ADC_BANDGAP_bm)

This macro pre enables the Bandgap Reference.

Note
If the ADC is enabled the Bandgap Reference is automaticly enabled.
Parameters
_adcPointer to ADC module register section.

Definition at line 291 of file adc_driver.h.

◆ ADC_Ch_Conversion_Complete

#define ADC_Ch_Conversion_Complete (   _adc_ch)    (((_adc_ch)->INTFLAGS & ADC_CH_CHIF_bm) != 0x00)

This macro returns the channel conversion complete flag..

Parameters
_adc_chPointer to ADC Channel register section.
Returns
value of channels conversion complete flag.

Definition at line 222 of file adc_driver.h.

Referenced by ADC_Offset_Get(), and mc_ADC_Scheduler().

◆ ADC_Ch_Conversion_Start

#define ADC_Ch_Conversion_Start (   _adc_ch)    ((_adc_ch)->CTRL |= ADC_CH_START_bm)

This macro start one channel conversion.

Use the ADC_GetWordResultCh or ADC_GetByteResultCh functions to retrieve the conversion result. This macro is not to be used when the ADC is running in free-running mode.

Parameters
_adc_chPointer to ADC Channel module register section.

Definition at line 265 of file adc_driver.h.

Referenced by ADC_Offset_Get().

◆ ADC_Ch_InputMode_and_Gain_Config

#define ADC_Ch_InputMode_and_Gain_Config (   _adc_ch,
  _inputMode,
  _gain 
)
Value:
(_adc_ch)->CTRL = ((_adc_ch)->CTRL & \
(~(ADC_CH_INPUTMODE_gm|ADC_CH_GAINFAC_gm))) | \
((uint8_t) _inputMode|_gain)

This macro configures the input mode and gain to a specific virtual channel.

Parameters
_adc_chPointer to ADC channel register section.
_inputModeInput mode for this channel, differential, single-ended, gain etc. Use ADC_CH_INPUTMODE_t type.
_gainThe preamplifiers gain value. Use ADC_CH_GAINFAC_t type.

Definition at line 197 of file adc_driver.h.

Referenced by ADC_Init(), and ADC_Offset_Get().

◆ ADC_Ch_InputMux_Config

#define ADC_Ch_InputMux_Config (   _adc_ch,
  _posInput,
  _negInput 
)    ((_adc_ch)->MUXCTRL = (uint8_t) _posInput | _negInput)

This macro configures the Positiv and negativ inputs.

Parameters
_adc_chWhich ADC channel to configure.
_posInputWhich pin (or internal signal) to connect to positive ADC input. Use ADC_CH_MUXPOS_enum type.
_negInputWhich pin to connect to negative ADC input. Use ADC_CH_MUXNEG_t type.
Note
The negative input is connected to GND for single-ended and internal input modes.

Definition at line 212 of file adc_driver.h.

Referenced by ADC_Init(), and ADC_Offset_Get().

◆ ADC_Ch_Interrupts_Config

#define ADC_Ch_Interrupts_Config (   _adc_ch,
  _interruptMode,
  _interruptLevel 
)
Value:
(_adc_ch)->INTCTRL = (((_adc_ch)->INTCTRL & \
(~(ADC_CH_INTMODE_gm | ADC_CH_INTLVL_gm))) | \
((uint8_t) _interruptMode | _interruptLevel))

This macro configures the interrupt mode and level for one channel.

The interrupt mode affects the interrupt flag for the virtual channel, and thus also affects code that polls this flag instead of using interrupts.

Note
When using the result comparator function, the compare value must be set using the ADC_SetCompareValue function.
Parameters
_adc_chPointer to ADC channel register section.
_interruptModeInterrupt mode, flag on complete or above/below compare value. Use ADC_CH_INTMODE_t type.
_interruptLevelDisable or set low/med/high priority for this virtual channel. Use ADC_CH_INTLVL_t type.

Definition at line 182 of file adc_driver.h.

◆ ADC_CompareValue_Set

#define ADC_CompareValue_Set (   _adc,
  _value 
)    ((_adc)->CMP = _value)

This macro sets the value in the ADC compare register.

The value in the ADC compare register is used by the result comparator for channels that are configured to notify when result is above or below this value. Even if the ADC compare value register is always left adjusted, the input to this function is adjusted according to the result presentation setup for the ADC. This means that the value will be right adjusted unless the "12-bit left adjust" result mode is selected with ADC_ConvMode_and_Resolution_Config.

Parameters
_adcPointer to ADC module register section.
_value12-bit value used by the result comparator. Use uint16_t type.

Definition at line 239 of file adc_driver.h.

◆ ADC_Conversions_Start

#define ADC_Conversions_Start (   _adc,
  _channelMask 
)
Value:
(_adc)->CTRLA |= _channelMask & \
(ADC_CH0START_bm | ADC_CH1START_bm | \
ADC_CH2START_bm | ADC_CH3START_bm)

This macro start multiple channel conversions.

This macro starts a conversion for the channels selected by the channel mask parameter. Use the bit mask defines for each channel and combine them into one byte using bitwise OR. The available masks are ADC_CH0START_bm, ADC_CH1START_bm, ADC_CH2START_bm and ADC_CH3START_bm.

Parameters
_adcPointer to ADC module register section.
_channelMaskA bitmask selecting which channels to check.

Definition at line 279 of file adc_driver.h.

◆ ADC_ConvMode_and_Resolution_Config

#define ADC_ConvMode_and_Resolution_Config (   _adc,
  _signedMode,
  _resolution 
)
Value:
((_adc)->CTRLB = ((_adc)->CTRLB & (~(ADC_RESOLUTION_gm|ADC_CONMODE_bm)))| \
(_resolution| ( _signedMode? ADC_CONMODE_bm : 0)))

This macro set the conversion mode and resolution in the selected adc.

This macro configures the conversion mode to signed or unsigned and set the resolution in and the way the results are put in the result registers.

Parameters
_adcPointer to ADC module register section
_signedModeSelects conversion mode: signed (true) or unsigned (false). USE bool type.
_resolutionResolution and presentation selection. Use ADC_RESOLUTION_t type.

Definition at line 110 of file adc_driver.h.

Referenced by ADC_Init(), and ADC_Offset_Get().

◆ ADC_Disable

#define ADC_Disable (   _adc)    ((_adc)->CTRLA = (_adc)->CTRLA & (~ADC_ENABLE_bm))

This macro disables the selected adc.

Parameters
_adcPointer to ADC module register section

Definition at line 89 of file adc_driver.h.

Referenced by ADC_Offset_Get().

◆ ADC_Enable

#define ADC_Enable (   _adc)    ((_adc)->CTRLA |= ADC_ENABLE_bm)

This macro enables the selected adc.

Before the ADC is enabled the first time the function ADC_CalibrationValues_Set should be used to reduce the gain error in the ADC.

Note
After the ADC is enabled the commen mode voltage in the ADC is ready after 12 ADC clock cycels. Do one dummy conversion or wait the required number of clock cycles to reasure correct conversion.
Parameters
_adcPointer to ADC module register section.

Definition at line 83 of file adc_driver.h.

Referenced by ADC_Init(), and ADC_Offset_Get().

◆ ADC_Events_Config

#define ADC_Events_Config (   _adc,
  _eventChannels,
  _eventMode 
)
Value:
\ \
(_adc)->EVCTRL = ((_adc)->EVCTRL & (~(ADC_EVSEL_gm | ADC_EVACT_gm))) | \
((uint8_t) _eventChannels | _eventMode)

This macro configures the event channels used and the event mode.

This macro configures the way events are used to trigger conversions for the virtual channels. Use the eventChannels parameter to select which event channel to associate with virtual channel 0 or to trigger a conversion sweep, depending on the selected eventMode parameter.

Parameters
_adcPointer to ADC module register section.
_eventChannelsThe first event channel to be used for triggering. Use ADC_EVSEL_t type.
_eventModeSelect event trigger mode. Use ADC_EVACT_t type.

Definition at line 163 of file adc_driver.h.

◆ ADC_FreeRunning_Disable

#define ADC_FreeRunning_Disable (   _adc)    ((_adc)->CTRLB = (_adc)->CTRLB & (~ADC_FREERUN_bm))

This macro disables the Free Running mode in the selected adc.

Parameters
_adcPointer to ADC module register section.

Definition at line 253 of file adc_driver.h.

◆ ADC_FreeRunning_Enable

#define ADC_FreeRunning_Enable (   _adc)    ((_adc)->CTRLB |= ADC_FREERUN_bm)

This macro enables the Free Running mode in the selected adc.

Parameters
_adcPointer to ADC module register section.

Definition at line 246 of file adc_driver.h.

Referenced by ADC_Init().

◆ ADC_Pipeline_Flush

#define ADC_Pipeline_Flush (   _adc)    ((_adc)->CTRLA |= ADC_FLUSH_bm)

This macro flushes the pipline in the selected adc.

Parameters
_adcPointer to ADC module register section

Definition at line 95 of file adc_driver.h.

◆ ADC_Prescaler_Config

#define ADC_Prescaler_Config (   _adc,
  _div 
)    ((_adc)->PRESCALER = ((_adc)->PRESCALER & (~ADC_PRESCALER_gm)) | _div)

This macro set the prescaler factor in the selected adc.

This macro configures the division factor between the XMEGA IO-clock and the ADC clock. Given a certain IO-clock, the prescaler must be configured so the the ADC clock is within recommended limits. A faster IO-clock required higher division factors.

Note
The maximum ADC sample rate is always one fourth of the IO clock.
Parameters
_adcPointer to ADC module register section.
_divADC prescaler division factor setting. Use ADC_PRESCALER_t type

Definition at line 127 of file adc_driver.h.

Referenced by ADC_Init(), and ADC_Offset_Get().

◆ ADC_Referance_Config

#define ADC_Referance_Config (   _adc,
  _convRef 
)    ((_adc)->REFCTRL = ((_adc)->REFCTRL & ~(ADC_REFSEL_gm)) | _convRef)

This macro set the conversion referance in the selected adc.

Parameters
_adcPointer to ADC module register section.
_convRefSelects reference voltage for all conversions. Use ADC_REFSEL_t type.

Definition at line 137 of file adc_driver.h.

Referenced by ADC_Init(), and ADC_Offset_Get().

◆ ADC_SweepChannels_Config

#define ADC_SweepChannels_Config (   _adc,
  _sweepChannels 
)    ((_adc)->EVCTRL = ((_adc)->EVCTRL & (~ADC_SWEEP_gm)) | _sweepChannels)

This macro sets the sweep channel settings.

Parameters
_adcPointer to ADC module register section.
_sweepChannelsSweep channel selection. Use uint8_t type

Definition at line 146 of file adc_driver.h.

◆ ADC_TempReference_Disable

#define ADC_TempReference_Disable (   _adc)    ((_adc)->REFCTRL = (_adc)->REFCTRL & (~ADC_TEMPREF_bm))

This macro disables the temperature reference.

Parameters
_adcPointer to ADC module register section.

Definition at line 314 of file adc_driver.h.

◆ ADC_TempReference_Enable

#define ADC_TempReference_Enable (   _adc)    ((_adc)->REFCTRL |= ADC_TEMPREF_bm)

This macro makes sure that the temperature reference circuitry is enabled.

Note
Enabling the temperature reference automatically enables the bandgap reference.
Parameters
_adcPointer to ADC module register section.

Definition at line 307 of file adc_driver.h.

◆ COMMEN_MODE_CYCLES

#define COMMEN_MODE_CYCLES   16

Definition at line 66 of file adc_driver.h.

Referenced by ADC_Wait_32MHz(), and ADC_Wait_8MHz().

Function Documentation

◆ ADC_CalibrationValues_Set()

void ADC_CalibrationValues_Set ( ADC_t *  adc)

This function get the calibration data from the production calibration.

The calibration data is loaded from flash and stored in the calibration register. The calibration data reduces the gain error in the adc.

Parameters
adcPointer to ADC module register section.

Definition at line 77 of file adc_driver.c.

References SP_ReadCalibrationByte().

Referenced by ADC_Init().

78 {
79  if(&ADCA == adc){
80  /* Get ADCCAL0 from byte address 0x20 (Word address 0x10. */
81  adc->CAL = SP_ReadCalibrationByte(0x20);
82  }else {
83  /* Get ADCCAL0 from byte address 0x24 (Word address 0x12. */
84  adc->CAL = SP_ReadCalibrationByte(0x24);
85  }
86 }
uint8_t SP_ReadCalibrationByte(uint8_t index)
Here is the call graph for this function:

◆ ADC_Offset_Get()

uint8_t ADC_Offset_Get ( ADC_t *  adc)

This function get the offset of the ADC.

This function make an internal coupling to the same pin and calculate the internal offset in the ADC.

Note
This function only return the low byte of the 12-bit convertion, because the offset should never be more than +-8 LSB off.
Parameters
adcPointer to the ADC to calculate offset from.
Returns
Offset on the selected ADC

Definition at line 241 of file adc_driver.c.

References ADC_Ch_Conversion_Complete, ADC_Ch_Conversion_Start, ADC_Ch_InputMode_and_Gain_Config, ADC_Ch_InputMux_Config, ADC_ConvMode_and_Resolution_Config, ADC_Disable, ADC_Enable, ADC_Prescaler_Config, ADC_Referance_Config, ADC_ResultCh_GetLowByte(), ADC_Wait_32MHz(), offset, and SP_ReadCalibrationByte().

Referenced by ADC_Init().

242 {
243  uint8_t offset;
244 
245  /* Set up ADC to get offset. */
246  ADC_ConvMode_and_Resolution_Config(adc, true, ADC_RESOLUTION_12BIT_gc);
247 
248  ADC_Prescaler_Config(adc , ADC_PRESCALER_DIV8_gc);
249 
250  ADC_Referance_Config(adc , ADC_REFSEL_INTVCC_gc);
251 
253  ADC_CH_INPUTMODE_DIFF_gc,
254  ADC_CH_GAIN_1X_gc);
255 
256  ADC_Ch_InputMux_Config(&(adc->CH0), ADC_CH_MUXPOS_PIN0_gc, ADC_CH_MUXNEG_PIN0_gc);
257 
258  /* Enable ADC. */
259  ADC_Enable(adc);
260 
261  /* Wait until ADC is ready. */
262  ADC_Wait_32MHz(adc);
263 
264  /* Do one conversion to find offset. */
265  ADC_Ch_Conversion_Start(&(adc->CH0));
266 
267  do{
268  }while(!ADC_Ch_Conversion_Complete(&(adc->CH0)));
269  offset = ADC_ResultCh_GetLowByte(&(adc->CH0), 0x00);
270 
271  /* Disable ADC. */
272  ADC_Disable(adc);
273 
274  return offset;
275 }
#define ADC_Disable(_adc)
This macro disables the selected adc.
Definition: adc_driver.h:89
#define ADC_ConvMode_and_Resolution_Config(_adc, _signedMode, _resolution)
This macro set the conversion mode and resolution in the selected adc.
Definition: adc_driver.h:110
#define ADC_Ch_InputMode_and_Gain_Config(_adc_ch, _inputMode, _gain)
This macro configures the input mode and gain to a specific virtual channel.
Definition: adc_driver.h:197
void ADC_Wait_32MHz(ADC_t *adc)
This function waits until the adc common mode is settled.
Definition: adc_driver.c:214
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
#define ADC_Prescaler_Config(_adc, _div)
This macro set the prescaler factor in the selected adc.
Definition: adc_driver.h:127
#define ADC_Ch_Conversion_Complete(_adc_ch)
This macro returns the channel conversion complete flag..
Definition: adc_driver.h:222
#define ADC_Ch_InputMux_Config(_adc_ch, _posInput, _negInput)
This macro configures the Positiv and negativ inputs.
Definition: adc_driver.h:212
#define ADC_Referance_Config(_adc, _convRef)
This macro set the conversion referance in the selected adc.
Definition: adc_driver.h:137
#define ADC_Ch_Conversion_Start(_adc_ch)
This macro start one channel conversion.
Definition: adc_driver.h:265
#define ADC_Enable(_adc)
This macro enables the selected adc.
Definition: adc_driver.h:83
volatile char offset
Definition: mc_drv.c:47
Here is the call graph for this function:

◆ ADC_ResultCh_GetHighByte()

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.

This funtion should be used together with the ADC_ResultCh_ConversionComplete. When the conversion result is ready this funciton reads out the result.

Note
If this function is used with 12-bit right adjusted results, it returns the 8 LSB only. Offset is not compensated.
If ADC interrupts are enabled, the interrupt handler will clear the interrupt flag before the polling loop can detect it, and this function will hang forever. Therefore, do not use interrupts with this function. Instead, read the result registers directly.
Parameters
adc_chPointer to ADC channel register section.
Returns
High byte of conversion result.

Definition at line 160 of file adc_driver.c.

161 {
162  /* Clear interrupt flag.*/
163  adc_ch->INTFLAGS = ADC_CH_CHIF_bm;
164 
165  /* Return low byte result register contents.*/
166  return adc_ch->RESH;
167 }

◆ ADC_ResultCh_GetLowByte()

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.

This funtion should be used together with the ADC_Ch_Conversion_Complete. When the conversion result is ready this funciton reads out the result.

Note
If this function is used with 12-bit right adjusted results, it returns the 8 LSB only.
Parameters
adc_chPointer to ADC channel register section.
offsetCompansation offset value.
Returns
Low byte of conversion result.

Definition at line 131 of file adc_driver.c.

References offset.

Referenced by ADC_Offset_Get().

132 {
133  uint8_t answer;
134 
135  /* Clear interrupt flag.*/
136  adc_ch->INTFLAGS = ADC_CH_CHIF_bm;
137  /* Return result register contents*/
138  answer = adc_ch->RESL - offset;
139 
140  return answer;
141 }
volatile char offset
Definition: mc_drv.c:47

◆ ADC_ResultCh_GetWord()

uint16_t ADC_ResultCh_GetWord ( ADC_CH_t *  adc_ch,
uint8_t  offset 
)

This function clears the interrupt flag and returns the coversion result.

This function should be used together with the ADC_Ch_Conversion_Complete. When the conversion result is ready this funciton reads out the result.

Parameters
adc_chPointer to ADC channel register section.
offsetOffset value that is compansated for.
Returns
Conversion result.

Definition at line 98 of file adc_driver.c.

Referenced by mc_ADC_Scheduler().

99 {
100  uint16_t answer;
101  uint16_t signedOffset = (uint16_t) offset;
102 
103  /* Append 16-bit signed value if offset (signed) is negative. */
104  if (offset >= 128){
105  signedOffset |= 0xFF00;
106  }
107 
108  /* Clear interrupt flag.*/
109  adc_ch->INTFLAGS = ADC_CH_CHIF_bm;
110 
111  /* Return result register contents*/
112  answer = adc_ch->RES - signedOffset;
113 
114  return answer;
115 }
volatile char offset
Definition: mc_drv.c:47

◆ ADC_Wait_32MHz()

void ADC_Wait_32MHz ( ADC_t *  adc)

This function waits until the adc common mode is settled.

After the ADC clock has been turned on, the common mode voltage in the ADC need some time to settle. The time it takes equals one dummy conversion. Instead of doing a dummy conversion this function waits until the common mode is settled.

Note
The function sets the prescaler to the minimum value possible when the clock speed is larger than 8 MHz to minimize the time it takes the common mode to settle.
The ADC clock is turned off every time the ADC i disabled or the device goes into sleep (not Idle sleep mode).
Parameters
adcPointer to ADC module register section.

Definition at line 214 of file adc_driver.c.

References COMMEN_MODE_CYCLES.

Referenced by ADC_Offset_Get().

215 {
216  /* Store old prescaler value. */
217  uint8_t prescaler_val = adc->PRESCALER;
218 
219  /* Set prescaler value to minimum value. */
220  adc->PRESCALER = ADC_PRESCALER_DIV8_gc;
221 
222  /* wait 8*COMMEN_MODE_CYCLES for common mode to settle*/
223  delay_us(8*COMMEN_MODE_CYCLES);
224 
225  /* Set prescaler to old value*/
226  adc->PRESCALER = prescaler_val;
227 }
#define COMMEN_MODE_CYCLES
Definition: adc_driver.h:66

◆ ADC_Wait_8MHz()

void ADC_Wait_8MHz ( ADC_t *  adc)

This function waits until the adc common mode is settled.

After the ADC clock has been turned on, the common mode voltage in the ADC need some time to settle. The time it takes equals one dummy conversion. Instead of doing a dummy conversion this function waits until the common mode is settled.

Note
The function sets the prescaler to the minimum value to minimize the time it takes the common mode to settle. If the clock speed is higher than 8 MHz use the ADC_wait_32MHz function.
Parameters
adcPointer to ADC module register section.

Definition at line 182 of file adc_driver.c.

References COMMEN_MODE_CYCLES.

Referenced by ADC_Init().

183 {
184  /* Store old prescaler value. */
185  uint8_t prescaler_val = adc->PRESCALER;
186 
187  /* Set prescaler value to minimum value. */
188  adc->PRESCALER = ADC_PRESCALER_DIV4_gc;
189 
190  /* Wait 4*COMMEN_MODE_CYCLES for common mode to settle. */
191  delay_us(4*COMMEN_MODE_CYCLES);
192 
193  /* Set prescaler to old value*/
194  adc->PRESCALER = prescaler_val;
195 }
#define COMMEN_MODE_CYCLES
Definition: adc_driver.h:66

◆ SP_ReadCalibrationByte()

uint8_t SP_ReadCalibrationByte ( uint8_t  index)