EFM32 Gecko Software Documentation
efm32g-doc-5.1.2
|
Analog to Digital Converter (ADC) Peripheral API.
This module contains functions to control the ADC peripheral of Silicon Labs 32-bit MCUs and SoCs. The ADC is used to convert analog signals into a digital representation.
Data Structures | |
struct | ADC_Init_TypeDef |
struct | ADC_InitScan_TypeDef |
struct | ADC_InitScanInput_TypeDef |
struct | ADC_InitSingle_TypeDef |
Macros | |
#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, adcPRSSELCh4 = _ADC_SINGLECTRL_PRSSEL_PRSCH4, adcPRSSELCh5 = _ADC_SINGLECTRL_PRSSEL_PRSCH5, adcPRSSELCh6 = _ADC_SINGLECTRL_PRSSEL_PRSCH6, adcPRSSELCh7 = _ADC_SINGLECTRL_PRSSEL_PRSCH7 } |
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 { adcSingleInputCh0 = _ADC_SINGLECTRL_INPUTSEL_CH0, adcSingleInputCh1 = _ADC_SINGLECTRL_INPUTSEL_CH1, adcSingleInputCh2 = _ADC_SINGLECTRL_INPUTSEL_CH2, adcSingleInputCh3 = _ADC_SINGLECTRL_INPUTSEL_CH3, adcSingleInputCh4 = _ADC_SINGLECTRL_INPUTSEL_CH4, adcSingleInputCh5 = _ADC_SINGLECTRL_INPUTSEL_CH5, adcSingleInputCh6 = _ADC_SINGLECTRL_INPUTSEL_CH6, adcSingleInputCh7 = _ADC_SINGLECTRL_INPUTSEL_CH7, adcSingleInputTemp = _ADC_SINGLECTRL_INPUTSEL_TEMP, adcSingleInputVDDDiv3 = _ADC_SINGLECTRL_INPUTSEL_VDDDIV3, adcSingleInputVDD = _ADC_SINGLECTRL_INPUTSEL_VDD, adcSingleInputVSS = _ADC_SINGLECTRL_INPUTSEL_VSS, adcSingleInputVrefDiv2 = _ADC_SINGLECTRL_INPUTSEL_VREFDIV2, adcSingleInputDACOut0 = _ADC_SINGLECTRL_INPUTSEL_DAC0OUT0, adcSingleInputDACOut1 = _ADC_SINGLECTRL_INPUTSEL_DAC0OUT1, adcSingleInputATEST = 15, adcSingleInputCh0Ch1 = _ADC_SINGLECTRL_INPUTSEL_CH0CH1, adcSingleInputCh2Ch3 = _ADC_SINGLECTRL_INPUTSEL_CH2CH3, adcSingleInputCh4Ch5 = _ADC_SINGLECTRL_INPUTSEL_CH4CH5, adcSingleInputCh6Ch7 = _ADC_SINGLECTRL_INPUTSEL_CH6CH7, adcSingleInputDiff0 = 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_DataScanGet (ADC_TypeDef *adc) |
Get scan result. More... | |
__STATIC_INLINE uint32_t | ADC_DataScanPeek (ADC_TypeDef *adc) |
Peek scan result. More... | |
__STATIC_INLINE uint32_t | ADC_DataSingleGet (ADC_TypeDef *adc) |
Get single conversion result. More... | |
__STATIC_INLINE uint32_t | ADC_DataSinglePeek (ADC_TypeDef *adc) |
Peek single conversion result. More... | |
void | ADC_Init (ADC_TypeDef *adc, const ADC_Init_TypeDef *init) |
Initialize ADC. More... | |
void | ADC_InitScan (ADC_TypeDef *adc, const ADC_InitScan_TypeDef *init) |
Initialize ADC scan sequence. More... | |
void | ADC_InitSingle (ADC_TypeDef *adc, const ADC_InitSingle_TypeDef *init) |
Initialize single ADC sample conversion. More... | |
__STATIC_INLINE void | ADC_IntClear (ADC_TypeDef *adc, uint32_t flags) |
Clear one or more pending ADC interrupts. More... | |
__STATIC_INLINE void | ADC_IntDisable (ADC_TypeDef *adc, uint32_t flags) |
Disable one or more ADC interrupts. More... | |
__STATIC_INLINE void | ADC_IntEnable (ADC_TypeDef *adc, uint32_t flags) |
Enable one or more ADC interrupts. More... | |
__STATIC_INLINE uint32_t | ADC_IntGet (ADC_TypeDef *adc) |
Get pending ADC interrupt flags. More... | |
__STATIC_INLINE uint32_t | ADC_IntGetEnabled (ADC_TypeDef *adc) |
Get enabled and pending ADC interrupt flags. Useful for handling more interrupt sources in the same interrupt handler. More... | |
__STATIC_INLINE void | ADC_IntSet (ADC_TypeDef *adc, uint32_t flags) |
Set one or more pending ADC interrupts from SW. More... | |
uint8_t | ADC_PrescaleCalc (uint32_t adcFreq, uint32_t hfperFreq) |
Calculate prescaler value used to determine ADC clock. More... | |
void | ADC_Reset (ADC_TypeDef *adc) |
Reset ADC to same state as after a HW reset. More... | |
__STATIC_INLINE void | ADC_Start (ADC_TypeDef *adc, ADC_Start_TypeDef cmd) |
Start scan sequence and/or single conversion. More... | |
uint8_t | ADC_TimebaseCalc (uint32_t hfperFreq) |
Calculate timebase value in order to get a timebase providing at least 1us. More... | |
#define ADC_INIT_DEFAULT |
Default config for ADC init structure.
Definition at line 836 of file em_adc.h.
Referenced by adcInit(), MIC_init(), and TOUCH_Init().
#define ADC_INITSCAN_DEFAULT |
Default config for ADC scan init structure.
Definition at line 946 of file em_adc.h.
Referenced by MIC_init().
#define ADC_INITSINGLE_DEFAULT |
Default config for ADC single conversion init structure.
Definition at line 1049 of file em_adc.h.
Referenced by adcInit().
enum ADC_AcqTime_TypeDef |
Acquisition time (in ADC clock cycles).
enum ADC_LPFilter_TypeDef |
Oversample rate select.
enum ADC_PRSSEL_TypeDef |
enum ADC_Ref_TypeDef |
Single and scan mode voltage references. Using unshifted enums and or in ADC_CTRLX_VREFSEL_REG to select the extension register CTRLX_VREFSEL.
enum ADC_Res_TypeDef |
Single sample input selection.
enum ADC_Start_TypeDef |
enum ADC_Warmup_TypeDef |
Warm-up mode.
__STATIC_INLINE uint32_t ADC_DataScanGet | ( | ADC_TypeDef * | adc | ) |
Get scan result.
[in] | adc | Pointer to ADC peripheral register block. |
Definition at line 1134 of file em_adc.h.
References ADC_TypeDef::SCANDATA.
__STATIC_INLINE uint32_t ADC_DataScanPeek | ( | ADC_TypeDef * | adc | ) |
Peek scan result.
[in] | adc | Pointer to ADC peripheral register block. |
Definition at line 1153 of file em_adc.h.
References ADC_TypeDef::SCANDATAP.
__STATIC_INLINE uint32_t ADC_DataSingleGet | ( | ADC_TypeDef * | adc | ) |
Get single conversion result.
[in] | adc | Pointer to ADC peripheral register block. |
Definition at line 1096 of file em_adc.h.
References ADC_TypeDef::SINGLEDATA.
Referenced by ADC0_IRQHandler(), and getAdcSample().
__STATIC_INLINE uint32_t ADC_DataSinglePeek | ( | ADC_TypeDef * | adc | ) |
Peek single conversion result.
[in] | adc | Pointer to ADC peripheral register block. |
Definition at line 1115 of file em_adc.h.
References ADC_TypeDef::SINGLEDATAP.
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. For ADC architectures with the ADCn->SCANINPUTSEL register, use ADC_ScanSingleEndedInputAdd() to configure single-ended scan inputs or ADC_ScanDifferentialInputAdd() to configure differential scan inputs. ADC_ScanInputClear() is also provided for applications that need to update the input configuration.
[in] | adc | Pointer to ADC peripheral register block. |
[in] | init | Pointer to ADC initialization structure. |
Definition at line 371 of file em_adc.c.
References _ADC_CTRL_LPFMODE_MASK, _ADC_CTRL_LPFMODE_SHIFT, _ADC_CTRL_OVSRSEL_SHIFT, _ADC_CTRL_PRESC_MASK, _ADC_CTRL_PRESC_SHIFT, _ADC_CTRL_TIMEBASE_MASK, _ADC_CTRL_TIMEBASE_SHIFT, _ADC_CTRL_WARMUPMODE_SHIFT, ADC0, ADC_CMD_SCANSTOP, ADC_CMD_SINGLESTOP, ADC_CTRL_TAILGATE, ADC_IntClear(), ADC_PrescaleCalc(), BUS_RegMaskedWrite(), ADC_TypeDef::CMD, ADC_TypeDef::CTRL, 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.
Referenced by adcInit(), MIC_init(), and TOUCH_Init().
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. For ADC architectures with the ADCn->SCANINPUTSEL register, use ADC_ScanSingleEndedInputAdd() to configure single-ended scan inputs or ADC_ScanDifferentialInputAdd() to configure differential scan inputs. ADC_ScanInputClear() is also provided for applications that need to update the input configuration.
[in] | adc | Pointer to ADC peripheral register block. |
[in] | init | Pointer to ADC initialization structure. |
Definition at line 710 of file em_adc.c.
References _ADC_SCANCTRL_AT_SHIFT, _ADC_SCANCTRL_PRSSEL_SHIFT, _ADC_SCANCTRL_REF_SHIFT, _ADC_SCANCTRL_RES_SHIFT, ADC_InitScan_TypeDef::acqTime, ADC_CMD_SCANSTOP, ADC_SCANCTRL_ADJ_LEFT, ADC_SCANCTRL_DIFF, ADC_SCANCTRL_PRSEN, ADC_SCANCTRL_REP, BUS_RegBitWrite(), ADC_TypeDef::CMD, ADC_TypeDef::CTRL, 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, ADC_InitScan_TypeDef::resolution, ADC_TypeDef::SCANCTRL, and ADC_TypeDef::STATUS.
Referenced by MIC_init().
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.
[in] | adc | Pointer to ADC peripheral register block. |
[in] | init | Pointer to ADC initialization structure. |
Definition at line 854 of file em_adc.c.
References _ADC_SINGLECTRL_AT_MASK, _ADC_SINGLECTRL_AT_SHIFT, _ADC_SINGLECTRL_INPUTSEL_SHIFT, _ADC_SINGLECTRL_PRSSEL_SHIFT, _ADC_SINGLECTRL_REF_SHIFT, _ADC_SINGLECTRL_RES_SHIFT, ADC_InitSingle_TypeDef::acqTime, ADC_CMD_SINGLESTOP, ADC_SINGLECTRL_ADJ_LEFT, ADC_SINGLECTRL_DIFF, ADC_SINGLECTRL_PRSEN, ADC_SINGLECTRL_REP, adcAcqTime8, adcRef1V25, ADC_TypeDef::BIASPROG, BUS_RegBitWrite(), ADC_TypeDef::CMD, ADC_TypeDef::CTRL, 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, ADC_InitSingle_TypeDef::resolution, ADC_TypeDef::SINGLECTRL, and ADC_TypeDef::STATUS.
Referenced by ADC0_IRQHandler(), adcInit(), and TOUCH_Init().
__STATIC_INLINE void ADC_IntClear | ( | ADC_TypeDef * | adc, |
uint32_t | flags | ||
) |
Clear one or more pending ADC interrupts.
[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 1194 of file em_adc.h.
References ADC_TypeDef::IFC.
Referenced by ADC0_IRQHandler(), ADC_Init(), and TOUCH_Init().
__STATIC_INLINE void ADC_IntDisable | ( | ADC_TypeDef * | adc, |
uint32_t | flags | ||
) |
Disable one or more ADC interrupts.
[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 1211 of file em_adc.h.
References ADC_TypeDef::IEN.
Referenced by TOUCH_GetPos(), and TOUCH_Init().
__STATIC_INLINE void ADC_IntEnable | ( | ADC_TypeDef * | adc, |
uint32_t | flags | ||
) |
Enable one or more ADC interrupts.
[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 1233 of file em_adc.h.
References ADC_TypeDef::IEN.
Referenced by TOUCH_GetPos(), and TOUCH_Init().
__STATIC_INLINE uint32_t ADC_IntGet | ( | ADC_TypeDef * | adc | ) |
Get pending ADC interrupt flags.
[in] | adc | Pointer to ADC peripheral register block. |
Definition at line 1253 of file em_adc.h.
References ADC_TypeDef::IF.
Referenced by getAdcSample().
__STATIC_INLINE uint32_t ADC_IntGetEnabled | ( | ADC_TypeDef * | adc | ) |
Get enabled and pending ADC interrupt flags. Useful for handling more interrupt sources in the same interrupt handler.
[in] | adc | Pointer to ADC peripheral register block. |
Definition at line 1278 of file em_adc.h.
References ADC_TypeDef::IEN, and ADC_TypeDef::IF.
__STATIC_INLINE void ADC_IntSet | ( | ADC_TypeDef * | adc, |
uint32_t | flags | ||
) |
Set one or more pending ADC interrupts from SW.
[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 1302 of file em_adc.h.
References ADC_TypeDef::IFS.
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).
[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. |
adcFreq
. Definition at line 1025 of file em_adc.c.
References CMU_ClockFreqGet(), and cmuClock_HFPER.
Referenced by ADC_Init(), adcInit(), MIC_init(), and TOUCH_Init().
void ADC_Reset | ( | ADC_TypeDef * | adc | ) |
Reset ADC to same state as after a HW reset.
[in] | adc | Pointer to ADC peripheral register block. |
Definition at line 1066 of file em_adc.c.
References _ADC_BIASPROG_RESETVALUE, _ADC_CTRL_RESETVALUE, _ADC_IEN_RESETVALUE, _ADC_IFC_MASK, _ADC_SCANCTRL_RESETVALUE, _ADC_SINGLECTRL_RESETVALUE, ADC_CMD_SCANSTOP, ADC_CMD_SINGLESTOP, adcRef1V25, ADC_TypeDef::BIASPROG, ADC_TypeDef::CMD, ADC_TypeDef::CTRL, ADC_TypeDef::IEN, ADC_TypeDef::IFC, ADC_TypeDef::SCANCTRL, and ADC_TypeDef::SINGLECTRL.
__STATIC_INLINE void ADC_Start | ( | ADC_TypeDef * | adc, |
ADC_Start_TypeDef | cmd | ||
) |
Start scan sequence and/or single conversion.
[in] | adc | Pointer to ADC peripheral register block. |
[in] | cmd | Command indicating which type of sampling to start. |
Definition at line 1318 of file em_adc.h.
References ADC_TypeDef::CMD.
Referenced by ADC0_IRQHandler(), getAdcSample(), and TOUCH_Init().
uint8_t ADC_TimebaseCalc | ( | uint32_t | hfperFreq | ) |
Calculate timebase value in order to get a timebase providing at least 1us.
[in] | hfperFreq | Frequency in Hz of reference HFPER clock. Set to 0 to use currently defined HFPER clock setting. |
Definition at line 1118 of file em_adc.c.
References CMU_ClockFreqGet(), and cmuClock_HFPER.
Referenced by adcInit(), and MIC_init().