ADC - Analog to Digital Converter
Description
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 |
ADC initialization structure, common for single conversion and scan sequence.
|
|
struct | ADC_InitScanInput_TypeDef |
Scan input configuration.
|
|
struct | ADC_InitScan_TypeDef |
Scan sequence initialization structure.
|
|
struct | ADC_InitSingle_TypeDef |
Single conversion initialization structure.
|
|
Functions |
|
uint32_t | ADC_DataSingleGet (ADC_TypeDef *adc) |
Get a single conversion result.
|
|
uint32_t | ADC_DataSinglePeek (ADC_TypeDef *adc) |
Peek single conversion result.
|
|
uint32_t | ADC_DataScanGet (ADC_TypeDef *adc) |
Get a scan result.
|
|
uint32_t | ADC_DataScanPeek (ADC_TypeDef *adc) |
Peek scan result.
|
|
void | ADC_Init (ADC_TypeDef *adc, const ADC_Init_TypeDef *init) |
Initialize ADC.
|
|
void | ADC_Reset (ADC_TypeDef *adc) |
Reset ADC to a state that it was in after a hardware reset.
|
|
void | ADC_InitScan (ADC_TypeDef *adc, const ADC_InitScan_TypeDef *init) |
Initialize the ADC scan sequence.
|
|
void | ADC_InitSingle (ADC_TypeDef *adc, const ADC_InitSingle_TypeDef *init) |
Initialize the single ADC sample conversion.
|
|
uint8_t | ADC_TimebaseCalc (uint32_t hfperFreq) |
Calculate a timebase value to get a timebase providing at least 1 us.
|
|
uint8_t | ADC_PrescaleCalc (uint32_t adcFreq, uint32_t hfperFreq) |
Calculate the prescaler value used to determine the ADC clock.
|
|
void | ADC_IntClear (ADC_TypeDef *adc, uint32_t flags) |
Clear one or more pending ADC interrupts.
|
|
void | ADC_IntDisable (ADC_TypeDef *adc, uint32_t flags) |
Disable one or more ADC interrupts.
|
|
void | ADC_IntEnable (ADC_TypeDef *adc, uint32_t flags) |
Enable one or more ADC interrupts.
|
|
uint32_t | ADC_IntGet (ADC_TypeDef *adc) |
Get pending ADC interrupt flags.
|
|
uint32_t | ADC_IntGetEnabled (ADC_TypeDef *adc) |
Get enabled and pending ADC interrupt flags.
|
|
void | ADC_IntSet (ADC_TypeDef *adc, uint32_t flags) |
Set one or more pending ADC interrupts from software.
|
|
void | ADC_Start (ADC_TypeDef *adc, ADC_Start_TypeDef cmd) |
Start scan sequence and/or single conversion.
|
|
Macros |
|
#define | ADC_INIT_DEFAULT |
Default configuration for ADC initialization structure.
|
|
#define | ADC_INITSCAN_DEFAULT |
Default configuration for ADC scan initialization structure.
|
|
#define | ADC_INITSINGLE_DEFAULT |
Default configuration for ADC single conversion initialization structure.
|
|
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 } |
Acquisition time (in ADC clock cycles).
|
|
enum |
ADC_LPFilter_TypeDef
{
adcLPFilterBypass = _ADC_CTRL_LPFMODE_BYPASS, adcLPFilterRC = _ADC_CTRL_LPFMODE_RCFILT, adcLPFilterDeCap = _ADC_CTRL_LPFMODE_DECAP } |
Lowpass filter mode.
|
|
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 } |
Oversample rate select.
|
|
enum |
ADC_PRSSEL_TypeDef
{
adcPRSSELCh0 = _ADC_SINGLECTRL_PRSSEL_PRSCH0, adcPRSSELCh1 = _ADC_SINGLECTRL_PRSSEL_PRSCH1, adcPRSSELCh2 = _ADC_SINGLECTRL_PRSSEL_PRSCH2, adcPRSSELCh3 = _ADC_SINGLECTRL_PRSSEL_PRSCH3 } |
Peripheral Reflex System signal used to trigger a single sample.
|
|
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 } |
Single and scan mode voltage references.
|
|
enum |
ADC_Res_TypeDef
{
adcRes12Bit = _ADC_SINGLECTRL_RES_12BIT, adcRes8Bit = _ADC_SINGLECTRL_RES_8BIT, adcRes6Bit = _ADC_SINGLECTRL_RES_6BIT, adcResOVS = _ADC_SINGLECTRL_RES_OVS } |
Sample resolution.
|
|
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 } |
Single sample input selection.
|
|
enum |
ADC_Start_TypeDef
{
adcStartSingle = ADC_CMD_SINGLESTART, adcStartScan = ADC_CMD_SCANSTART, adcStartScanAndSingle = ADC_CMD_SCANSTART | ADC_CMD_SINGLESTART } |
ADC start command.
|
|
enum |
ADC_Warmup_TypeDef
{
adcWarmupNormal = _ADC_CTRL_WARMUPMODE_NORMAL, adcWarmupFastBG = _ADC_CTRL_WARMUPMODE_FASTBG, adcWarmupKeepScanRefWarm = _ADC_CTRL_WARMUPMODE_KEEPSCANREFWARM, adcWarmupKeepADCWarm = _ADC_CTRL_WARMUPMODE_KEEPADCWARM } |
Warm-up mode.
|
|
Function Documentation
◆ ADC_DataSingleGet()
|
inline |
Get a single conversion result.
- Note
- Check data valid flag before calling this function.
- Parameters
-
[in] adc
A pointer to the ADC peripheral register block.
- Returns
- Single conversion data.
◆ ADC_DataSinglePeek()
|
inline |
Peek single conversion result.
- Note
- Check data valid flag before calling this function.
- Parameters
-
[in] adc
A pointer to the ADC peripheral register block.
- Returns
- Single conversion data.
◆ ADC_DataScanGet()
|
inline |
Get a scan result.
- Note
- Check data valid flag before calling this function.
- Parameters
-
[in] adc
A pointer to the ADC peripheral register block.
- Returns
- Scan conversion data.
◆ ADC_DataScanPeek()
|
inline |
Peek scan result.
- Note
- Check data valid flag before calling this function.
- Parameters
-
[in] adc
A pointer to the ADC peripheral register block.
- Returns
- Scan conversion data.
◆ ADC_Init()
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. 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.
- Parameters
-
[in] adc
A pointer to the ADC peripheral register block. [in] init
A pointer to the ADC initialization structure.
◆ ADC_Reset()
void ADC_Reset | ( | ADC_TypeDef * |
adc
|
) |
Reset ADC to a state that it was in after a hardware reset.
- Note
- The ROUTE register is NOT reset by this function to allow a centralized setup of this feature.
- Parameters
-
[in] adc
A pointer to ADC peripheral register block.
◆ ADC_InitScan()
void ADC_InitScan | ( | ADC_TypeDef * |
adc,
|
const ADC_InitScan_TypeDef * |
init
|
||
) |
Initialize the ADC scan sequence.
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.
- Parameters
-
[in] adc
A pointer to the ADC peripheral register block. [in] init
A pointer to the ADC initialization structure.
◆ ADC_InitSingle()
void ADC_InitSingle | ( | ADC_TypeDef * |
adc,
|
const ADC_InitSingle_TypeDef * |
init
|
||
) |
Initialize the single ADC sample conversion.
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.
- Parameters
-
[in] adc
A pointer to the ADC peripheral register block. [in] init
A pointer to the ADC initialization structure.
◆ ADC_TimebaseCalc()
uint8_t ADC_TimebaseCalc | ( | uint32_t |
hfperFreq
|
) |
Calculate a timebase value to get a timebase providing at least 1 us.
- Parameters
-
[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.
◆ ADC_PrescaleCalc()
uint8_t ADC_PrescaleCalc | ( | uint32_t |
adcFreq,
|
uint32_t |
hfperFreq
|
||
) |
Calculate the prescaler value used to determine the ADC clock.
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.
- Parameters
-
[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.
- Returns
-
A prescaler value to use for ADC in order to achieve a clock value <=
adcFreq
.
◆ ADC_IntClear()
|
inline |
Clear one or more pending ADC interrupts.
- Parameters
-
[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).
◆ ADC_IntDisable()
|
inline |
Disable one or more ADC interrupts.
- Parameters
-
[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).
◆ ADC_IntEnable()
|
inline |
Enable one or more ADC interrupts.
- 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.
- Parameters
-
[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).
◆ ADC_IntGet()
|
inline |
Get pending ADC interrupt flags.
- Note
- This function does not clear event bits.
- Parameters
-
[in] adc
A pointer to the 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).
◆ ADC_IntGetEnabled()
|
inline |
Get enabled and pending ADC interrupt flags.
Useful for handling more interrupt sources in the same interrupt handler.
- Parameters
-
[in] adc
A pointer to the ADC peripheral register block.
- 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).
◆ ADC_IntSet()
|
inline |
Set one or more pending ADC interrupts from software.
- Parameters
-
[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).
◆ ADC_Start()
|
inline |
Start scan sequence and/or single conversion.
- Parameters
-
[in] adc
A pointer to the ADC peripheral register block. [in] cmd
A command indicating which type of sampling to start.
Macro Definition Documentation
◆ ADC_INIT_DEFAULT
#define ADC_INIT_DEFAULT |
Default configuration for ADC initialization structure.
◆ ADC_INITSCAN_DEFAULT
#define ADC_INITSCAN_DEFAULT |
Default configuration for ADC scan initialization structure.
◆ ADC_INITSINGLE_DEFAULT
#define ADC_INITSINGLE_DEFAULT |
Default configuration for ADC single conversion initialization structure.
Enumeration Type Documentation
◆ ADC_AcqTime_TypeDef
enum ADC_AcqTime_TypeDef |
Acquisition time (in ADC clock cycles).
◆ ADC_LPFilter_TypeDef
enum ADC_LPFilter_TypeDef |
◆ ADC_OvsRateSel_TypeDef
Oversample rate select.
◆ ADC_PRSSEL_TypeDef
enum ADC_PRSSEL_TypeDef |
◆ ADC_Ref_TypeDef
enum 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
◆ ADC_Res_TypeDef
enum ADC_Res_TypeDef |
◆ ADC_SingleInput_TypeDef
Single sample input selection.
◆ ADC_Start_TypeDef
enum ADC_Start_TypeDef |
◆ ADC_Warmup_TypeDef
enum ADC_Warmup_TypeDef |
Warm-up mode.