ADC
[EM_Library]

Analog to Digital Converter (ADC) Peripheral API. More...

Collaboration diagram for ADC:

Data Structures

struct  ADC_Init_TypeDef
struct  ADC_InitScan_TypeDef
struct  ADC_InitSingle_TypeDef

Defines

#define ADC_INIT_DEFAULT
#define ADC_INITSCAN_DEFAULT
#define ADC_INITSINGLE_DEFAULT

Enumerations

enum  ADC_AcqTime_TypeDef {
  adcAcqTime1 = _ADC_SINGLECTRL_AT_1CYCLE,
  adcAcqTime2 = _ADC_SINGLECTRL_AT_2CYCLES,
  adcAcqTime4 = _ADC_SINGLECTRL_AT_4CYCLES,
  adcAcqTime8 = _ADC_SINGLECTRL_AT_8CYCLES,
  adcAcqTime16 = _ADC_SINGLECTRL_AT_16CYCLES,
  adcAcqTime32 = _ADC_SINGLECTRL_AT_32CYCLES,
  adcAcqTime64 = _ADC_SINGLECTRL_AT_64CYCLES,
  adcAcqTime128 = _ADC_SINGLECTRL_AT_128CYCLES,
  adcAcqTime256 = _ADC_SINGLECTRL_AT_256CYCLES
}
enum  ADC_LPFilter_TypeDef {
  adcLPFilterBypass = _ADC_CTRL_LPFMODE_BYPASS,
  adcLPFilterRC = _ADC_CTRL_LPFMODE_RCFILT,
  adcLPFilterDeCap = _ADC_CTRL_LPFMODE_DECAP
}
enum  ADC_OvsRateSel_TypeDef {
  adcOvsRateSel2 = _ADC_CTRL_OVSRSEL_X2,
  adcOvsRateSel4 = _ADC_CTRL_OVSRSEL_X4,
  adcOvsRateSel8 = _ADC_CTRL_OVSRSEL_X8,
  adcOvsRateSel16 = _ADC_CTRL_OVSRSEL_X16,
  adcOvsRateSel32 = _ADC_CTRL_OVSRSEL_X32,
  adcOvsRateSel64 = _ADC_CTRL_OVSRSEL_X64,
  adcOvsRateSel128 = _ADC_CTRL_OVSRSEL_X128,
  adcOvsRateSel256 = _ADC_CTRL_OVSRSEL_X256,
  adcOvsRateSel512 = _ADC_CTRL_OVSRSEL_X512,
  adcOvsRateSel1024 = _ADC_CTRL_OVSRSEL_X1024,
  adcOvsRateSel2048 = _ADC_CTRL_OVSRSEL_X2048,
  adcOvsRateSel4096 = _ADC_CTRL_OVSRSEL_X4096
}
enum  ADC_PRSSEL_TypeDef {
  adcPRSSELCh0 = _ADC_SINGLECTRL_PRSSEL_PRSCH0,
  adcPRSSELCh1 = _ADC_SINGLECTRL_PRSSEL_PRSCH1,
  adcPRSSELCh2 = _ADC_SINGLECTRL_PRSSEL_PRSCH2,
  adcPRSSELCh3 = _ADC_SINGLECTRL_PRSSEL_PRSCH3
}
enum  ADC_Ref_TypeDef {
  adcRef1V25 = _ADC_SINGLECTRL_REF_1V25,
  adcRef2V5 = _ADC_SINGLECTRL_REF_2V5,
  adcRefVDD = _ADC_SINGLECTRL_REF_VDD,
  adcRef5VDIFF = _ADC_SINGLECTRL_REF_5VDIFF,
  adcRefExtSingle = _ADC_SINGLECTRL_REF_EXTSINGLE,
  adcRef2xExtDiff = _ADC_SINGLECTRL_REF_2XEXTDIFF,
  adcRef2xVDD = _ADC_SINGLECTRL_REF_2XVDD
}
enum  ADC_Res_TypeDef {
  adcRes12Bit = _ADC_SINGLECTRL_RES_12BIT,
  adcRes8Bit = _ADC_SINGLECTRL_RES_8BIT,
  adcRes6Bit = _ADC_SINGLECTRL_RES_6BIT,
  adcResOVS = _ADC_SINGLECTRL_RES_OVS
}
enum  ADC_SingleInput_TypeDef {
  adcSingleInpCh0 = _ADC_SINGLECTRL_INPUTSEL_CH0,
  adcSingleInpCh1 = _ADC_SINGLECTRL_INPUTSEL_CH1,
  adcSingleInpCh2 = _ADC_SINGLECTRL_INPUTSEL_CH2,
  adcSingleInpCh3 = _ADC_SINGLECTRL_INPUTSEL_CH3,
  adcSingleInpCh4 = _ADC_SINGLECTRL_INPUTSEL_CH4,
  adcSingleInpCh5 = _ADC_SINGLECTRL_INPUTSEL_CH5,
  adcSingleInpCh6 = _ADC_SINGLECTRL_INPUTSEL_CH6,
  adcSingleInpCh7 = _ADC_SINGLECTRL_INPUTSEL_CH7,
  adcSingleInpTemp = _ADC_SINGLECTRL_INPUTSEL_TEMP,
  adcSingleInpVDDDiv3 = _ADC_SINGLECTRL_INPUTSEL_VDDDIV3,
  adcSingleInpVDD = _ADC_SINGLECTRL_INPUTSEL_VDD,
  adcSingleInpVSS = _ADC_SINGLECTRL_INPUTSEL_VSS,
  adcSingleInpVrefDiv2 = _ADC_SINGLECTRL_INPUTSEL_VREFDIV2,
  adcSingleInpDACOut0 = _ADC_SINGLECTRL_INPUTSEL_DAC0OUT0,
  adcSingleInpDACOut1 = _ADC_SINGLECTRL_INPUTSEL_DAC0OUT1,
  adcSingleInpATEST = 15,
  adcSingleInpCh0Ch1 = _ADC_SINGLECTRL_INPUTSEL_CH0CH1,
  adcSingleInpCh2Ch3 = _ADC_SINGLECTRL_INPUTSEL_CH2CH3,
  adcSingleInpCh4Ch5 = _ADC_SINGLECTRL_INPUTSEL_CH4CH5,
  adcSingleInpCh6Ch7 = _ADC_SINGLECTRL_INPUTSEL_CH6CH7,
  adcSingleInpDiff0 = 4
}
enum  ADC_Start_TypeDef {
  adcStartSingle = ADC_CMD_SINGLESTART,
  adcStartScan = ADC_CMD_SCANSTART,
  adcStartScanAndSingle = ADC_CMD_SCANSTART | ADC_CMD_SINGLESTART
}
enum  ADC_Warmup_TypeDef {
  adcWarmupNormal = _ADC_CTRL_WARMUPMODE_NORMAL,
  adcWarmupFastBG = _ADC_CTRL_WARMUPMODE_FASTBG,
  adcWarmupKeepScanRefWarm = _ADC_CTRL_WARMUPMODE_KEEPSCANREFWARM,
  adcWarmupKeepADCWarm = _ADC_CTRL_WARMUPMODE_KEEPADCWARM
}

Functions

__STATIC_INLINE uint32_t ADC_DataSingleGet (ADC_TypeDef *adc)
 Get single conversion result.
__STATIC_INLINE uint32_t ADC_DataScanGet (ADC_TypeDef *adc)
 Get scan result.
void ADC_Init (ADC_TypeDef *adc, const ADC_Init_TypeDef *init)
 Initialize ADC.
void ADC_InitScan (ADC_TypeDef *adc, const ADC_InitScan_TypeDef *init)
 Initialize ADC scan sequence.
void ADC_InitSingle (ADC_TypeDef *adc, const ADC_InitSingle_TypeDef *init)
 Initialize single ADC sample conversion.
__STATIC_INLINE void ADC_IntClear (ADC_TypeDef *adc, uint32_t flags)
 Clear one or more pending ADC interrupts.
__STATIC_INLINE void ADC_IntDisable (ADC_TypeDef *adc, uint32_t flags)
 Disable one or more ADC interrupts.
__STATIC_INLINE void ADC_IntEnable (ADC_TypeDef *adc, uint32_t flags)
 Enable one or more ADC interrupts.
__STATIC_INLINE uint32_t ADC_IntGet (ADC_TypeDef *adc)
 Get pending ADC interrupt flags.
__STATIC_INLINE void ADC_IntSet (ADC_TypeDef *adc, uint32_t flags)
 Set one or more pending ADC interrupts from SW.
uint8_t ADC_PrescaleCalc (uint32_t adcFreq, uint32_t hfperFreq)
 Calculate prescaler value used to determine ADC clock.
__STATIC_INLINE void ADC_Start (ADC_TypeDef *adc, ADC_Start_TypeDef cmd)
 Start scan sequence and/or single conversion.
void ADC_Reset (ADC_TypeDef *adc)
 Reset ADC to same state as after a HW reset.
uint8_t ADC_TimebaseCalc (uint32_t hfperFreq)
 Calculate timebase value in order to get a timebase providing at least 1us.

Detailed Description

Analog to Digital Converter (ADC) Peripheral API.


Define Documentation

#define ADC_INIT_DEFAULT
Value:
{ adcOvsRateSel2,                /* 2x oversampling (if enabled). */       \
    adcLPFilterBypass,             /* No input filter selected. */           \
    adcWarmupNormal,               /* ADC shutdown after each conversion. */ \
    _ADC_CTRL_TIMEBASE_DEFAULT,    /* Use HW default value. */               \
    _ADC_CTRL_PRESC_DEFAULT,       /* Use HW default value. */               \
    false                          /* Do not use tailgate. */                \
  }

Default config for ADC init structure.

Definition at line 302 of file em_adc.h.

#define ADC_INITSCAN_DEFAULT
Value:
{ adcPRSSELCh0,              /* PRS ch0 (if enabled). */                          \
    adcAcqTime1,               /* 1 ADC_CLK cycle acquisition time. */              \
    adcRef1V25,                /* 1.25V internal reference. */                      \
    adcRes12Bit,               /* 12 bit resolution. */                             \
    0,                         /* No input selected. */                             \
    false,                     /* Single ended input. */                            \
    false,                     /* PRS disabled. */                                  \
    false,                     /* Right adjust. */                                  \
    false                      /* Deactivate conversion after one scan sequence. */ \
  }

Default config for ADC scan init structure.

Definition at line 355 of file em_adc.h.

#define ADC_INITSINGLE_DEFAULT
Value:
{ adcPRSSELCh0,              /* PRS ch0 (if enabled). */                          \
    adcAcqTime1,               /* 1 ADC_CLK cycle acquisition time. */              \
    adcRef1V25,                /* 1.25V internal reference. */                      \
    adcRes12Bit,               /* 12 bit resolution. */                             \
    adcSingleInpCh0,           /* CH0 input selected. */                            \
    false,                     /* Single ended input. */                            \
    false,                     /* PRS disabled. */                                  \
    false,                     /* Right adjust. */                                  \
    false                      /* Deactivate conversion after one scan sequence. */ \
  }

Default config for ADC single conversion init structure.

Definition at line 409 of file em_adc.h.


Enumeration Type Documentation

Acquisition time (in ADC clock cycles).

Enumerator:
adcAcqTime1 

1 clock cycle.

adcAcqTime2 

2 clock cycles.

adcAcqTime4 

4 clock cycles.

adcAcqTime8 

8 clock cycles.

adcAcqTime16 

16 clock cycles.

adcAcqTime32 

32 clock cycles.

adcAcqTime64 

64 clock cycles.

adcAcqTime128 

128 clock cycles.

adcAcqTime256 

256 clock cycles.

Definition at line 61 of file em_adc.h.

Lowpass filter mode.

Enumerator:
adcLPFilterBypass 

No filter or decoupling capacitor.

adcLPFilterRC 

On-chip RC filter.

adcLPFilterDeCap 

On-chip decoupling capacitor.

Definition at line 76 of file em_adc.h.

Oversample rate select.

Enumerator:
adcOvsRateSel2 

2 samples per conversion result.

adcOvsRateSel4 

4 samples per conversion result.

adcOvsRateSel8 

8 samples per conversion result.

adcOvsRateSel16 

16 samples per conversion result.

adcOvsRateSel32 

32 samples per conversion result.

adcOvsRateSel64 

64 samples per conversion result.

adcOvsRateSel128 

128 samples per conversion result.

adcOvsRateSel256 

256 samples per conversion result.

adcOvsRateSel512 

512 samples per conversion result.

adcOvsRateSel1024 

1024 samples per conversion result.

adcOvsRateSel2048 

2048 samples per conversion result.

adcOvsRateSel4096 

4096 samples per conversion result.

Definition at line 90 of file em_adc.h.

Peripheral Reflex System signal used to trigger single sample.

Enumerator:
adcPRSSELCh0 

PRS channel 0.

adcPRSSELCh1 

PRS channel 1.

adcPRSSELCh2 

PRS channel 2.

adcPRSSELCh3 

PRS channel 3.

Definition at line 131 of file em_adc.h.

Reference to ADC sample.

Enumerator:
adcRef1V25 

Internal 1.25V reference.

adcRef2V5 

Internal 2.5V reference.

adcRefVDD 

Buffered VDD.

adcRef5VDIFF 

Internal differential 5V reference.

adcRefExtSingle 

Single ended ext. ref. from pin 6.

adcRef2xExtDiff 

Differential ext. ref. from pin 6 and 7.

adcRef2xVDD 

Unbuffered 2xVDD.

Definition at line 165 of file em_adc.h.

Sample resolution.

Enumerator:
adcRes12Bit 

12 bit sampling.

adcRes8Bit 

8 bit sampling.

adcRes6Bit 

6 bit sampling.

adcResOVS 

Oversampling.

Definition at line 191 of file em_adc.h.

Single sample input selection.

Enumerator:
adcSingleInpCh0 

Channel 0.

adcSingleInpCh1 

Channel 1.

adcSingleInpCh2 

Channel 2.

adcSingleInpCh3 

Channel 3.

adcSingleInpCh4 

Channel 4.

adcSingleInpCh5 

Channel 5.

adcSingleInpCh6 

Channel 6.

adcSingleInpCh7 

Channel 7.

adcSingleInpTemp 

Temperature reference.

adcSingleInpVDDDiv3 

VDD divided by 3.

adcSingleInpVDD 

VDD.

adcSingleInpVSS 

VSS.

adcSingleInpVrefDiv2 

Vref divided by 2.

adcSingleInpDACOut0 

DAC output 0.

adcSingleInpDACOut1 

DAC output 1.

adcSingleInpATEST 

ATEST.

adcSingleInpCh0Ch1 

Positive Ch0, negative Ch1.

adcSingleInpCh2Ch3 

Positive Ch2, negative Ch3.

adcSingleInpCh4Ch5 

Positive Ch4, negative Ch5.

adcSingleInpCh6Ch7 

Positive Ch6, negative Ch7.

adcSingleInpDiff0 

Differential 0.

Definition at line 201 of file em_adc.h.

ADC Start command.

Enumerator:
adcStartSingle 

Start single conversion.

adcStartScan 

Start scan sequence.

adcStartScanAndSingle 

Start scan sequence and single conversion, typically used when tailgating single conversion after scan sequence.

Definition at line 233 of file em_adc.h.

Warm-up mode.

Enumerator:
adcWarmupNormal 

ADC shutdown after each conversion.

adcWarmupFastBG 

Do not warm-up bandgap references.

adcWarmupKeepScanRefWarm 

Reference selected for scan mode kept warm.

adcWarmupKeepADCWarm 

ADC and reference selected for scan mode kept warm.

Definition at line 250 of file em_adc.h.


Function Documentation

__STATIC_INLINE uint32_t ADC_DataScanGet ( ADC_TypeDef *  adc  ) 

Get scan result.

Note:
Do only use if scan data valid.
Parameters:
[in] adc Pointer to ADC peripheral register block.

Definition at line 455 of file em_adc.h.

__STATIC_INLINE uint32_t ADC_DataSingleGet ( ADC_TypeDef *  adc  ) 

Get single conversion result.

Note:
Do only use if single conversion data valid.
Parameters:
[in] adc Pointer to ADC peripheral register block.
Returns:

Definition at line 439 of file em_adc.h.

void ADC_Init ( ADC_TypeDef *  adc,
const ADC_Init_TypeDef init 
)

Initialize ADC.

Initializes common parts for both single conversion and scan sequence. In addition, single and/or scan control configuration must be done, please refer to ADC_InitSingle() and ADC_InitScan() respectively.

Note:
This function will stop any ongoing conversion.
Parameters:
[in] adc Pointer to ADC peripheral register block.
[in] init Pointer to ADC initialization structure.

Definition at line 255 of file em_adc.c.

References ADC_Init_TypeDef::lpfMode, ADC_Init_TypeDef::ovsRateSel, ADC_Init_TypeDef::prescale, ADC_Init_TypeDef::tailgate, ADC_Init_TypeDef::timebase, and ADC_Init_TypeDef::warmUpMode.

void ADC_InitScan ( ADC_TypeDef *  adc,
const ADC_InitScan_TypeDef init 
)

Initialize ADC scan sequence.

Please refer to ADC_Start() for starting scan sequence.

When selecting an external reference, the gain and offset calibration must be set explicitly (CAL register). For other references, the calibration is updated with values defined during manufacturing.

Note:
This function will stop any ongoing scan sequence.
Parameters:
[in] adc Pointer to ADC peripheral register block.
[in] init Pointer to ADC initialization structure.

Definition at line 299 of file em_adc.c.

References ADC_InitScan_TypeDef::acqTime, ADC_InitScan_TypeDef::diff, ADC_InitScan_TypeDef::input, ADC_InitScan_TypeDef::leftAdjust, ADC_InitScan_TypeDef::prsEnable, ADC_InitScan_TypeDef::prsSel, ADC_InitScan_TypeDef::reference, ADC_InitScan_TypeDef::rep, and ADC_InitScan_TypeDef::resolution.

void ADC_InitSingle ( ADC_TypeDef *  adc,
const ADC_InitSingle_TypeDef init 
)

Initialize single ADC sample conversion.

Please refer to ADC_Start() for starting single conversion.

When selecting an external reference, the gain and offset calibration must be set explicitly (CAL register). For other references, the calibration is updated with values defined during manufacturing.

Note:
This function will stop any ongoing single conversion.
Parameters:
[in] adc Pointer to ADC peripheral register block.
[in] init Pointer to ADC initialization structure.

Definition at line 361 of file em_adc.c.

References ADC_InitSingle_TypeDef::acqTime, ADC_InitSingle_TypeDef::diff, ADC_InitSingle_TypeDef::input, ADC_InitSingle_TypeDef::leftAdjust, ADC_InitSingle_TypeDef::prsEnable, ADC_InitSingle_TypeDef::prsSel, ADC_InitSingle_TypeDef::reference, ADC_InitSingle_TypeDef::rep, and ADC_InitSingle_TypeDef::resolution.

__STATIC_INLINE void ADC_IntClear ( ADC_TypeDef *  adc,
uint32_t  flags 
)

Clear one or more pending ADC interrupts.

Parameters:
[in] adc Pointer to ADC peripheral register block.
[in] flags Pending ADC interrupt source to clear. Use a bitwise logic OR combination of valid interrupt flags for the ADC module (ADC_IF_nnn).

Definition at line 476 of file em_adc.h.

__STATIC_INLINE void ADC_IntDisable ( ADC_TypeDef *  adc,
uint32_t  flags 
)

Disable one or more ADC interrupts.

Parameters:
[in] adc Pointer to ADC peripheral register block.
[in] flags ADC interrupt sources to disable. Use a bitwise logic OR combination of valid interrupt flags for the ADC module (ADC_IF_nnn).

Definition at line 493 of file em_adc.h.

__STATIC_INLINE void ADC_IntEnable ( ADC_TypeDef *  adc,
uint32_t  flags 
)

Enable one or more ADC interrupts.

Note:
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. Consider using ADC_IntClear() prior to enabling if such a pending interrupt should be ignored.
Parameters:
[in] adc Pointer to ADC peripheral register block.
[in] flags ADC interrupt sources to enable. Use a bitwise logic OR combination of valid interrupt flags for the ADC module (ADC_IF_nnn).

Definition at line 515 of file em_adc.h.

__STATIC_INLINE uint32_t ADC_IntGet ( ADC_TypeDef *  adc  ) 

Get pending ADC interrupt flags.

Note:
The event bits are not cleared by the use of this function.
Parameters:
[in] adc Pointer to ADC peripheral register block.
Returns:
ADC interrupt sources pending. A bitwise logic OR combination of valid interrupt flags for the ADC module (ADC_IF_nnn).

Definition at line 535 of file em_adc.h.

__STATIC_INLINE void ADC_IntSet ( ADC_TypeDef *  adc,
uint32_t  flags 
)

Set one or more pending ADC interrupts from SW.

Parameters:
[in] adc Pointer to ADC peripheral register block.
[in] flags ADC interrupt sources to set to pending. Use a bitwise logic OR combination of valid interrupt flags for the ADC module (ADC_IF_nnn).

Definition at line 552 of file em_adc.h.

uint8_t ADC_PrescaleCalc ( uint32_t  adcFreq,
uint32_t  hfperFreq 
)

Calculate prescaler value used to determine ADC clock.

The ADC clock is given by: HFPERCLK / (prescale + 1).

Parameters:
[in] adcFreq ADC frequency wanted. The frequency will automatically be adjusted to be within valid range according to reference manual.
[in] hfperFreq Frequency in Hz of reference HFPER clock. Set to 0 to use currently defined HFPER clock setting.
Returns:
Prescaler value to use for ADC in order to achieve a clock value <= adcFreq.

Definition at line 420 of file em_adc.c.

References CMU_ClockFreqGet(), and cmuClock_HFPER.

Here is the call graph for this function:

void ADC_Reset ( ADC_TypeDef *  adc  ) 

Reset ADC to same state as after a HW reset.

Note:
The ROUTE register is NOT reset by this function, in order to allow for centralized setup of this feature.
Parameters:
[in] adc Pointer to ADC peripheral register block.

Definition at line 461 of file em_adc.c.

References adcRef1V25.

__STATIC_INLINE void ADC_Start ( ADC_TypeDef *  adc,
ADC_Start_TypeDef  cmd 
)

Start scan sequence and/or single conversion.

Parameters:
[in] adc Pointer to ADC peripheral register block.
[in] cmd Command indicating which type of sampling to start.

Definition at line 570 of file em_adc.h.

uint8_t ADC_TimebaseCalc ( uint32_t  hfperFreq  ) 

Calculate timebase value in order to get a timebase providing at least 1us.

Parameters:
[in] hfperFreq Frequency in Hz of reference HFPER clock. Set to 0 to use currently defined HFPER clock setting.
Returns:
Timebase value to use for ADC in order to achieve at least 1 us.

Definition at line 490 of file em_adc.c.

References CMU_ClockFreqGet(), and cmuClock_HFPER.

Here is the call graph for this function: