ADC - Analog to Digital Converter#
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.
Modules#
Enumerations#
Acquisition time (in ADC clock cycles).
Lowpass filter mode.
Oversample rate select.
Peripheral Reflex System signal used to trigger a single sample.
Single and scan mode voltage references.
Sample resolution.
Single sample input selection.
ADC start command.
Warm-up mode.
Functions#
Initialize ADC.
Initialize the ADC scan sequence.
Initialize the single ADC sample conversion.
Calculate the prescaler value used to determine the ADC clock.
Reset ADC to a state that it was in after a hardware reset.
Calculate a timebase value to get a timebase providing at least 1 us.
Get a single conversion result.
Peek single conversion result.
Get a scan result.
Peek scan result.
Clear one or more pending ADC interrupts.
Disable one or more ADC interrupts.
Enable one or more ADC interrupts.
Get pending ADC interrupt flags.
Get enabled and pending ADC interrupt flags.
Set one or more pending ADC interrupts from software.
Start scan sequence and/or single conversion.
Macros#
Default configuration for ADC initialization structure.
Default configuration for ADC scan initialization structure.
Default configuration for ADC single conversion initialization structure.
Enumeration Documentation#
ADC_AcqTime_TypeDef#
ADC_AcqTime_TypeDef
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. |
53
of file platform/emlib/inc/em_adc.h
ADC_LPFilter_TypeDef#
ADC_LPFilter_TypeDef
Lowpass filter mode.
Enumerator | |
---|---|
adcLPFilterBypass | No filter or decoupling capacitor. |
adcLPFilterRC | On-chip RC filter. |
adcLPFilterDeCap | On-chip decoupling capacitor. |
67
of file platform/emlib/inc/em_adc.h
ADC_OvsRateSel_TypeDef#
ADC_OvsRateSel_TypeDef
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. |
80
of file platform/emlib/inc/em_adc.h
ADC_PRSSEL_TypeDef#
ADC_PRSSEL_TypeDef
Peripheral Reflex System signal used to trigger a single sample.
Enumerator | |
---|---|
adcPRSSELCh0 | PRS channel 0. |
adcPRSSELCh1 | PRS channel 1. |
adcPRSSELCh2 | PRS channel 2. |
adcPRSSELCh3 | PRS channel 3. |
adcPRSSELCh4 | PRS channel 4. |
adcPRSSELCh5 | PRS channel 5. |
119
of file platform/emlib/inc/em_adc.h
ADC_Ref_TypeDef#
ADC_Ref_TypeDef
Single and scan mode voltage references.
Using unshifted enumerations and or in ADC_CTRLX_VREFSEL_REG to select the extension register CTRLX_VREFSEL. ADC Reference
Enumerator | |
---|---|
adcRef1V25 | Internal 1.25 V reference. |
adcRef2V5 | Internal 2.5 V reference. |
adcRefVDD | Buffered VDD. |
adcRef5VDIFF | Internal differential 5 V reference. |
adcRefExtSingle | Single-ended external reference from pin 6. |
adcRef2xExtDiff | Differential external reference from pin 6 and 7. |
adcRef2xVDD | Unbuffered 2xVDD. |
185
of file platform/emlib/inc/em_adc.h
ADC_Res_TypeDef#
ADC_Res_TypeDef
Sample resolution.
Enumerator | |
---|---|
adcRes12Bit | 12 bit sampling. |
adcRes8Bit | 8 bit sampling. |
adcRes6Bit | 6 bit sampling. |
adcResOVS | Oversampling. |
261
of file platform/emlib/inc/em_adc.h
ADC_SingleInput_TypeDef#
ADC_SingleInput_TypeDef
Single sample input selection.
Enumerator | |
---|---|
adcSingleInputCh0 | Channel 0. |
adcSingleInputCh1 | Channel 1. |
adcSingleInputCh2 | Channel 2. |
adcSingleInputCh3 | Channel 3. |
adcSingleInputCh4 | Channel 4. |
adcSingleInputCh5 | Channel 5. |
adcSingleInputCh6 | Channel 6. |
adcSingleInputCh7 | Channel 7. |
adcSingleInputTemp | Temperature reference. |
adcSingleInputVDDDiv3 | VDD divided by 3. |
adcSingleInputVDD | VDD. |
adcSingleInputVSS | VSS. |
adcSingleInputVrefDiv2 | Vref divided by 2. |
adcSingleInputDACOut0 | DAC output 0. |
adcSingleInputDACOut1 | DAC output 1. |
adcSingleInputATEST | ATEST. |
adcSingleInputCh0Ch1 | Positive Ch0, negative Ch1. |
adcSingleInputCh2Ch3 | Positive Ch2, negative Ch3. |
adcSingleInputCh4Ch5 | Positive Ch4, negative Ch5. |
adcSingleInputCh6Ch7 | Positive Ch6, negative Ch7. |
adcSingleInputDiff0 | Differential 0. |
270
of file platform/emlib/inc/em_adc.h
ADC_Start_TypeDef#
ADC_Start_TypeDef
ADC start command.
Enumerator | |
---|---|
adcStartSingle | Start a single conversion. |
adcStartScan | Start a scan sequence. |
adcStartScanAndSingle | Start a scan sequence and single conversion, typically used when tailgating a single conversion after a scan sequence. |
721
of file platform/emlib/inc/em_adc.h
ADC_Warmup_TypeDef#
ADC_Warmup_TypeDef
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 at warmup allowing continuous conversion. |
736
of file platform/emlib/inc/em_adc.h
Function Documentation#
ADC_Init#
void ADC_Init (ADC_TypeDef * adc, const ADC_Init_TypeDef * init)
Initialize ADC.
[in] | adc | A pointer to the ADC peripheral register block. |
[in] | init | A pointer to the ADC initialization structure. |
Initializes common parts for both single conversion and scan sequence. In addition, single and/or scan control configuration must be done. See 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.
Note
This function will stop any ongoing conversion.
373
of file platform/emlib/src/em_adc.c
ADC_InitScan#
void ADC_InitScan (ADC_TypeDef * adc, const ADC_InitScan_TypeDef * init)
Initialize the ADC scan sequence.
[in] | adc | A pointer to the ADC peripheral register block. |
[in] | init | A pointer to the ADC initialization structure. |
See ADC_Start() for starting a 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.
Note
This function will stop any ongoing scan sequence.
719
of file platform/emlib/src/em_adc.c
ADC_InitSingle#
void ADC_InitSingle (ADC_TypeDef * adc, const ADC_InitSingle_TypeDef * init)
Initialize the single ADC sample conversion.
[in] | adc | A pointer to the ADC peripheral register block. |
[in] | init | A pointer to the ADC initialization structure. |
See ADC_Start() for starting a 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.
856
of file platform/emlib/src/em_adc.c
ADC_PrescaleCalc#
uint8_t ADC_PrescaleCalc (uint32_t adcFreq, uint32_t hfperFreq)
Calculate the prescaler value used to determine the ADC clock.
[in] | adcFreq | ADC frequency wanted. The frequency will automatically be adjusted to a valid range according to the reference manual. |
[in] | hfperFreq | Frequency in Hz of reference HFPER/HFPERC clock. Set to 0 to use currently defined HFPER/HFPERC clock setting. |
The ADC clock is given by: (HFPERCLK or HFPERCCLK) / (prescale + 1).
Note
The return value is clamped to the maximum prescaler value that the hardware supports.
Returns
A prescaler value to use for ADC in order to achieve a clock value <=
adcFreq
.
1018
of file platform/emlib/src/em_adc.c
ADC_Reset#
void ADC_Reset (ADC_TypeDef * adc)
Reset ADC to a state that it was in after a hardware reset.
[in] | adc | A pointer to ADC peripheral register block. |
Note
The ROUTE register is NOT reset by this function to allow a centralized setup of this feature.
1063
of file platform/emlib/src/em_adc.c
ADC_TimebaseCalc#
uint8_t ADC_TimebaseCalc (uint32_t hfperFreq)
Calculate a timebase value to get a timebase providing at least 1 us.
[in] | hfperFreq | Frequency in Hz of the reference HFPER/HFPERC clock. Set to 0 to use currently defined HFPER/HFPERC clock setting. |
Returns
A timebase value to use for ADC to achieve at least 1 us.
1114
of file platform/emlib/src/em_adc.c
ADC_DataSingleGet#
uint32_t ADC_DataSingleGet (ADC_TypeDef * adc)
Get a single conversion result.
[in] | adc | A pointer to the ADC peripheral register block. |
Note
Check data valid flag before calling this function.
Returns
Single conversion data.
1073
of file platform/emlib/inc/em_adc.h
ADC_DataSinglePeek#
uint32_t ADC_DataSinglePeek (ADC_TypeDef * adc)
Peek single conversion result.
[in] | adc | A pointer to the ADC peripheral register block. |
Note
Check data valid flag before calling this function.
Returns
Single conversion data.
1091
of file platform/emlib/inc/em_adc.h
ADC_DataScanGet#
uint32_t ADC_DataScanGet (ADC_TypeDef * adc)
Get a scan result.
[in] | adc | A pointer to the ADC peripheral register block. |
Note
Check data valid flag before calling this function.
Returns
Scan conversion data.
1109
of file platform/emlib/inc/em_adc.h
ADC_DataScanPeek#
uint32_t ADC_DataScanPeek (ADC_TypeDef * adc)
Peek scan result.
[in] | adc | A pointer to the ADC peripheral register block. |
Note
Check data valid flag before calling this function.
Returns
Scan conversion data.
1127
of file platform/emlib/inc/em_adc.h
ADC_IntClear#
void ADC_IntClear (ADC_TypeDef * adc, uint32_t flags)
Clear one or more pending ADC interrupts.
[in] | adc | A pointer to the 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). |
1166
of file platform/emlib/inc/em_adc.h
ADC_IntDisable#
void ADC_IntDisable (ADC_TypeDef * adc, uint32_t flags)
Disable one or more ADC interrupts.
[in] | adc | A pointer to the 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). |
1182
of file platform/emlib/inc/em_adc.h
ADC_IntEnable#
void ADC_IntEnable (ADC_TypeDef * adc, uint32_t flags)
Enable one or more ADC interrupts.
[in] | adc | A pointer to the 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). |
Note
Depending on use, a pending interrupt may already be set prior to enabling the interrupt. Consider using ADC_IntClear() prior to enabling if the pending interrupt should be ignored.
1203
of file platform/emlib/inc/em_adc.h
ADC_IntGet#
uint32_t ADC_IntGet (ADC_TypeDef * adc)
Get pending ADC interrupt flags.
[in] | adc | A pointer to the ADC peripheral register block. |
Note
This function does not clear event bits.
Returns
ADC interrupt sources pending. A bitwise logic OR combination of valid interrupt flags for the ADC module (ADC_IF_nnn).
1222
of file platform/emlib/inc/em_adc.h
ADC_IntGetEnabled#
uint32_t ADC_IntGetEnabled (ADC_TypeDef * adc)
Get enabled and pending ADC interrupt flags.
[in] | adc | A pointer to the ADC peripheral register block. |
Useful for handling more interrupt sources in the same interrupt handler.
Note
This function does not clear interrupt flags.
Returns
Pending and enabled ADC interrupt sources. The return value is the bitwise AND combination of
the OR combination of enabled interrupt sources in ADCx_IEN_nnn register (ADCx_IEN_nnn) and
the OR combination of valid interrupt flags of the ADC module (ADCx_IF_nnn).
1246
of file platform/emlib/inc/em_adc.h
ADC_IntSet#
void ADC_IntSet (ADC_TypeDef * adc, uint32_t flags)
Set one or more pending ADC interrupts from software.
[in] | adc | A pointer to the 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). |
1269
of file platform/emlib/inc/em_adc.h
ADC_Start#
void ADC_Start (ADC_TypeDef * adc, ADC_Start_TypeDef cmd)
Start scan sequence and/or single conversion.
[in] | adc | A pointer to the ADC peripheral register block. |
[in] | cmd | A command indicating which type of sampling to start. |
1284
of file platform/emlib/inc/em_adc.h
Macro Definition Documentation#
ADC_INIT_DEFAULT#
#define ADC_INIT_DEFAULTValue:
Default configuration for ADC initialization structure.
819
of file platform/emlib/inc/em_adc.h
ADC_INITSCAN_DEFAULT#
#define ADC_INITSCAN_DEFAULTValue:
Default configuration for ADC scan initialization structure.
925
of file platform/emlib/inc/em_adc.h
ADC_INITSINGLE_DEFAULT#
#define ADC_INITSINGLE_DEFAULTValue:
Default configuration for ADC single conversion initialization structure.
1026
of file platform/emlib/inc/em_adc.h