ACMP - Analog Comparator
Description
Analog comparator (ACMP) Peripheral API.
The Analog Comparator is used to compare voltage of two analog inputs with a digital output indicating which input voltage is higher. Inputs can either be one of the selectable internal references or from external pins. Response time and current consumption can be configured by altering the current supply to the comparator.
ACMP is available down to EM3 and is able to wake up the system when input signals pass a certain threshold. Use ACMP_IntEnable() to enable an edge interrupt to use this functionality.
This example shows how to use the em_acmp.h API for comparing an input pin to an internal 2.5 V reference voltage.
- Note
- ACMP can also be used to compare two separate input pins.
ACMP also contains specialized hardware for capacitive sensing. This module contains the ACMP_CapsenseInit() function to initialize ACMP for capacitive sensing and the ACMP_CapsenseChannelSet() function to select the current capsense channel.
For applications that require capacitive sensing it is recommended to use a library, such as cslib, which is provided by Silicon Labs.
Data Structures |
|
struct | ACMP_CapsenseInit_TypeDef |
Capsense initialization structure.
|
|
struct | ACMP_Init_TypeDef |
ACMP initialization structure.
|
|
Functions |
|
void | ACMP_CapsenseInit (ACMP_TypeDef *acmp, const ACMP_CapsenseInit_TypeDef *init) |
Set up ACMP for use in capacitive sense applications.
|
|
void | ACMP_CapsenseChannelSet (ACMP_TypeDef *acmp, ACMP_Channel_TypeDef channel) |
Set the ACMP channel used for capacitive sensing.
|
|
void | ACMP_Disable (ACMP_TypeDef *acmp) |
Disable ACMP.
|
|
void | ACMP_Enable (ACMP_TypeDef *acmp) |
Enable ACMP.
|
|
void | ACMP_Reset (ACMP_TypeDef *acmp) |
Reset ACMP to the same state that it was in after a hardware reset.
|
|
void | ACMP_GPIOSetup (ACMP_TypeDef *acmp, uint32_t location, bool enable, bool invert) |
Set up GPIO output from ACMP.
|
|
void | ACMP_ChannelSet (ACMP_TypeDef *acmp, ACMP_Channel_TypeDef negSel, ACMP_Channel_TypeDef posSel) |
Set which channels should be used in ACMP comparisons.
|
|
void | ACMP_Init (ACMP_TypeDef *acmp, const ACMP_Init_TypeDef *init) |
Initialize ACMP.
|
|
void | ACMP_IntClear (ACMP_TypeDef *acmp, uint32_t flags) |
Clear one or more pending ACMP interrupts.
|
|
void | ACMP_IntDisable (ACMP_TypeDef *acmp, uint32_t flags) |
Disable one or more ACMP interrupts.
|
|
void | ACMP_IntEnable (ACMP_TypeDef *acmp, uint32_t flags) |
Enable one or more ACMP interrupts.
|
|
uint32_t | ACMP_IntGet (ACMP_TypeDef *acmp) |
Get pending ACMP interrupt flags.
|
|
uint32_t | ACMP_IntGetEnabled (ACMP_TypeDef *acmp) |
Get enabled and pending ACMP interrupt flags.
|
|
void | ACMP_IntSet (ACMP_TypeDef *acmp, uint32_t flags) |
Set one or more pending ACMP interrupts from software.
|
|
Macros |
|
#define | ACMP_CAPSENSE_INIT_DEFAULT |
A default configuration for capacitive sense mode initialization.
|
|
#define | ACMP_INIT_DEFAULT |
Default configuration for ACMP regular initialization.
|
|
Enumerations |
|
enum |
ACMP_CapsenseResistor_TypeDef
{
acmpResistor0 = _ACMP_INPUTSEL_CSRESSEL_RES0, acmpResistor1 = _ACMP_INPUTSEL_CSRESSEL_RES1, acmpResistor2 = _ACMP_INPUTSEL_CSRESSEL_RES2, acmpResistor3 = _ACMP_INPUTSEL_CSRESSEL_RES3 } |
Resistor values used for the internal capacitive sense resistor.
|
|
enum |
ACMP_HysteresisLevel_TypeDef
{
acmpHysteresisLevel0 = _ACMP_CTRL_HYSTSEL_HYST0, acmpHysteresisLevel1 = _ACMP_CTRL_HYSTSEL_HYST1, acmpHysteresisLevel2 = _ACMP_CTRL_HYSTSEL_HYST2, acmpHysteresisLevel3 = _ACMP_CTRL_HYSTSEL_HYST3, acmpHysteresisLevel4 = _ACMP_CTRL_HYSTSEL_HYST4, acmpHysteresisLevel5 = _ACMP_CTRL_HYSTSEL_HYST5, acmpHysteresisLevel6 = _ACMP_CTRL_HYSTSEL_HYST6, acmpHysteresisLevel7 = _ACMP_CTRL_HYSTSEL_HYST7 } |
Hysteresis level.
|
|
enum |
ACMP_WarmTime_TypeDef
{
acmpWarmTime4 = _ACMP_CTRL_WARMTIME_4CYCLES, acmpWarmTime8 = _ACMP_CTRL_WARMTIME_8CYCLES, acmpWarmTime16 = _ACMP_CTRL_WARMTIME_16CYCLES, acmpWarmTime32 = _ACMP_CTRL_WARMTIME_32CYCLES, acmpWarmTime64 = _ACMP_CTRL_WARMTIME_64CYCLES, acmpWarmTime128 = _ACMP_CTRL_WARMTIME_128CYCLES, acmpWarmTime256 = _ACMP_CTRL_WARMTIME_256CYCLES, acmpWarmTime512 = _ACMP_CTRL_WARMTIME_512CYCLES } |
ACMP warmup time.
|
|
enum |
ACMP_Channel_TypeDef
{
acmpChannel0 = _ACMP_INPUTSEL_NEGSEL_CH0, acmpChannel1 = _ACMP_INPUTSEL_NEGSEL_CH1, acmpChannel2 = _ACMP_INPUTSEL_NEGSEL_CH2, acmpChannel3 = _ACMP_INPUTSEL_NEGSEL_CH3, acmpChannel4 = _ACMP_INPUTSEL_NEGSEL_CH4, acmpChannel5 = _ACMP_INPUTSEL_NEGSEL_CH5, acmpChannel6 = _ACMP_INPUTSEL_NEGSEL_CH6, acmpChannel7 = _ACMP_INPUTSEL_NEGSEL_CH7, acmpChannel1V25 = _ACMP_INPUTSEL_NEGSEL_1V25, acmpChannel2V5 = _ACMP_INPUTSEL_NEGSEL_2V5, acmpChannelVDD = _ACMP_INPUTSEL_NEGSEL_VDD, acmpChannelDAC0Ch0 = _ACMP_INPUTSEL_NEGSEL_DAC0CH0, acmpChannelDAC0Ch1 = _ACMP_INPUTSEL_NEGSEL_DAC0CH1, acmpChannelCapSense = _ACMP_INPUTSEL_NEGSEL_CAPSENSE } |
ACMP inputs.
|
|
Function Documentation
◆ ACMP_CapsenseInit()
void ACMP_CapsenseInit | ( | ACMP_TypeDef * |
acmp,
|
const ACMP_CapsenseInit_TypeDef * |
init
|
||
) |
Set up ACMP for use in capacitive sense applications.
This function sets up ACMP for use in capacitive sense applications. To use the capacitive sense functionality in the ACMP, use the PRS output of the ACMP module to count the number of oscillations in the capacitive sense circuit (possibly using a TIMER).
- Note
- A basic example of capacitive sensing can be found in the STK BSP (capsense demo).
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block. [in] init
A pointer to the initialization structure used to configure ACMP for capacitive sensing operation.
◆ ACMP_CapsenseChannelSet()
void ACMP_CapsenseChannelSet | ( | ACMP_TypeDef * |
acmp,
|
ACMP_Channel_TypeDef |
channel
|
||
) |
Set the ACMP channel used for capacitive sensing.
- Note
- A basic example of capacitive sensing can be found in the STK BSP (capsense demo).
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block. [in] channel
The ACMP channel to use for capacitive sensing (Possel).
◆ ACMP_Disable()
void ACMP_Disable | ( | ACMP_TypeDef * |
acmp
|
) |
Disable ACMP.
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block.
◆ ACMP_Enable()
void ACMP_Enable | ( | ACMP_TypeDef * |
acmp
|
) |
Enable ACMP.
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block.
◆ ACMP_Reset()
void ACMP_Reset | ( | ACMP_TypeDef * |
acmp
|
) |
Reset ACMP to the same state that it was in after a hardware reset.
- Note
- The GPIO ACMP ROUTE register is NOT reset by this function to allow for centralized setup of this feature.
- The peripheral may be enabled and disabled during reset.
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block.
◆ ACMP_GPIOSetup()
void ACMP_GPIOSetup | ( | ACMP_TypeDef * |
acmp,
|
uint32_t |
location,
|
||
bool |
enable,
|
||
bool |
invert
|
||
) |
Set up GPIO output from ACMP.
- Note
-
GPIO must be enabled in the CMU before this function call, i.e.,
CMU_ClockEnable(cmuClock_GPIO, true);
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block. location
The pin location to use. See the data sheet for location to pin mappings. enable
Enable or disable pin output. invert
Invert output.
◆ ACMP_ChannelSet()
void ACMP_ChannelSet | ( | ACMP_TypeDef * |
acmp,
|
ACMP_Channel_TypeDef |
negSel,
|
||
ACMP_Channel_TypeDef |
posSel
|
||
) |
Set which channels should be used in ACMP comparisons.
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block. negSel
A channel to use on the negative input to the ACMP. posSel
A channel to use on the positive input to the ACMP.
◆ ACMP_Init()
void ACMP_Init | ( | ACMP_TypeDef * |
acmp,
|
const ACMP_Init_TypeDef * |
init
|
||
) |
Initialize ACMP.
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block. [in] init
A pointer to the initialization structure used to configure ACMP.
◆ ACMP_IntClear()
|
inline |
Clear one or more pending ACMP interrupts.
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block. [in] flags
Pending ACMP interrupt source to clear. Use a bitwise logic OR combination of valid interrupt flags for the ACMP module. The flags can be, for instance, ACMP_IFC_EDGE or ACMP_IFC_WARMUP.
◆ ACMP_IntDisable()
|
inline |
Disable one or more ACMP interrupts.
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block. [in] flags
ACMP interrupt sources to disable. Use a bitwise logic OR combination of valid interrupt flags for the ACMP module. The flags can be, for instance, ACMP_IEN_EDGE or ACMP_IEN_WARMUP.
◆ ACMP_IntEnable()
|
inline |
Enable one or more ACMP interrupts.
- Note
- Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. Consider using ACMP_IntClear() prior to enabling if a pending interrupt should be ignored.
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block. [in] flags
ACMP interrupt sources to enable. Use a bitwise logic OR combination of valid interrupt flags for the ACMP module. The flags can be, for instance, ACMP_IEN_EDGE or ACMP_IEN_WARMUP.
◆ ACMP_IntGet()
|
inline |
Get pending ACMP interrupt flags.
- Note
- This function does not clear event bits.
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block.
- Returns
- Pending ACMP interrupt sources. A bitwise logic OR combination of valid interrupt flags for the ACMP module. The pending interrupt sources can be, for instance, ACMP_IF_EDGE or ACMP_IF_WARMUP.
◆ ACMP_IntGetEnabled()
|
inline |
Get enabled and pending ACMP interrupt flags.
Useful for handling more interrupt sources in the same interrupt handler.
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block.
- Note
- This function does not clear interrupt flags.
- Returns
-
Pending and enabled ACMP interrupt sources. The return value is the bitwise AND combination of
- the OR combination of enabled interrupt sources in ACMPx_IEN_nnn register (ACMPx_IEN_nnn) and
- the OR combination of valid interrupt flags of the ACMP module (ACMPx_IF_nnn).
◆ ACMP_IntSet()
|
inline |
Set one or more pending ACMP interrupts from software.
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block. [in] flags
ACMP interrupt sources to set as pending. Use a bitwise logic OR combination of valid interrupt flags for the ACMP module. The flags can be, for instance, ACMP_IFS_EDGE or ACMP_IFS_WARMUP.
Macro Definition Documentation
◆ ACMP_CAPSENSE_INIT_DEFAULT
#define ACMP_CAPSENSE_INIT_DEFAULT |
A default configuration for capacitive sense mode initialization.
◆ ACMP_INIT_DEFAULT
#define ACMP_INIT_DEFAULT |
Default configuration for ACMP regular initialization.
Enumeration Type Documentation
◆ ACMP_CapsenseResistor_TypeDef
◆ ACMP_HysteresisLevel_TypeDef
Hysteresis level.
See data sheet for your device for details on each level.
◆ ACMP_WarmTime_TypeDef
ACMP warmup time.
The delay is measured in HFPERCLK / HFPERCCLK cycles and should be at least 10 us.
◆ ACMP_Channel_TypeDef
enum ACMP_Channel_TypeDef |
ACMP inputs.
Note that scaled VDD and bandgap references can only be used as negative inputs.