ACMP
Detailed 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 |
struct | ACMP_Init_TypeDef |
Macros |
|
#define | ACMP_CAPSENSE_INIT_DEFAULT |
#define | ACMP_INIT_DEFAULT |
Enumerations |
|
enum |
ACMP_Accuracy_TypeDef
{
acmpAccuracyLow = _ACMP_CFG_ACCURACY_LOW, acmpAccuracyHigh = _ACMP_CFG_ACCURACY_HIGH } |
enum |
ACMP_CapsenseResistor_TypeDef
{
acmpResistor0 = _ACMP_INPUTCTRL_CSRESSEL_RES0, acmpResistor1 = _ACMP_INPUTCTRL_CSRESSEL_RES1, acmpResistor2 = _ACMP_INPUTCTRL_CSRESSEL_RES2, acmpResistor3 = _ACMP_INPUTCTRL_CSRESSEL_RES3, acmpResistor4 = _ACMP_INPUTCTRL_CSRESSEL_RES4, acmpResistor5 = _ACMP_INPUTCTRL_CSRESSEL_RES5, acmpResistor6 = _ACMP_INPUTCTRL_CSRESSEL_RES6 } |
enum |
ACMP_Channel_TypeDef
{
acmpInputVSS = _ACMP_INPUTCTRL_POSSEL_VSS, acmpInputVREFDIVAVDD = _ACMP_INPUTCTRL_POSSEL_VREFDIVAVDD, acmpInputVREFDIVAVDDLP = _ACMP_INPUTCTRL_POSSEL_VREFDIVAVDDLP, acmpInputVREFDIV1V25 = _ACMP_INPUTCTRL_POSSEL_VREFDIV1V25, acmpInputVREFDIV1V25LP = _ACMP_INPUTCTRL_POSSEL_VREFDIV1V25LP, acmpInputVREFDIV2V5 = _ACMP_INPUTCTRL_POSSEL_VREFDIV2V5, acmpInputVREFDIV2V5LP = _ACMP_INPUTCTRL_POSSEL_VREFDIV2V5LP, acmpInputVSENSE01DIV4 = _ACMP_INPUTCTRL_POSSEL_VSENSE01DIV4, acmpInputVSENSE01DIV4LP = _ACMP_INPUTCTRL_POSSEL_VSENSE01DIV4LP, acmpInputVSENSE11DIV4 = _ACMP_INPUTCTRL_POSSEL_VSENSE11DIV4, acmpInputVSENSE11DIV4LP = _ACMP_INPUTCTRL_POSSEL_VSENSE11DIV4LP, acmpInputCAPSENSE = _ACMP_INPUTCTRL_NEGSEL_CAPSENSE, acmpInputPA0 = _ACMP_INPUTCTRL_POSSEL_PA0, acmpInputPA1 = _ACMP_INPUTCTRL_POSSEL_PA1, acmpInputPA2 = _ACMP_INPUTCTRL_POSSEL_PA2, acmpInputPA3 = _ACMP_INPUTCTRL_POSSEL_PA3, acmpInputPA4 = _ACMP_INPUTCTRL_POSSEL_PA4, acmpInputPA5 = _ACMP_INPUTCTRL_POSSEL_PA5, acmpInputPA6 = _ACMP_INPUTCTRL_POSSEL_PA6, acmpInputPA7 = _ACMP_INPUTCTRL_POSSEL_PA7, acmpInputPA8 = _ACMP_INPUTCTRL_POSSEL_PA8, acmpInputPA9 = _ACMP_INPUTCTRL_POSSEL_PA9, acmpInputPA10 = _ACMP_INPUTCTRL_POSSEL_PA10, acmpInputPA11 = _ACMP_INPUTCTRL_POSSEL_PA11, acmpInputPA12 = _ACMP_INPUTCTRL_POSSEL_PA12, acmpInputPA13 = _ACMP_INPUTCTRL_POSSEL_PA13, acmpInputPA14 = _ACMP_INPUTCTRL_POSSEL_PA14, acmpInputPA15 = _ACMP_INPUTCTRL_POSSEL_PA15, acmpInputPB0 = _ACMP_INPUTCTRL_POSSEL_PB0, acmpInputPB1 = _ACMP_INPUTCTRL_POSSEL_PB1, acmpInputPB2 = _ACMP_INPUTCTRL_POSSEL_PB2, acmpInputPB3 = _ACMP_INPUTCTRL_POSSEL_PB3, acmpInputPB4 = _ACMP_INPUTCTRL_POSSEL_PB4, acmpInputPB5 = _ACMP_INPUTCTRL_POSSEL_PB5, acmpInputPB6 = _ACMP_INPUTCTRL_POSSEL_PB6, acmpInputPB7 = _ACMP_INPUTCTRL_POSSEL_PB7, acmpInputPB8 = _ACMP_INPUTCTRL_POSSEL_PB8, acmpInputPB9 = _ACMP_INPUTCTRL_POSSEL_PB9, acmpInputPB10 = _ACMP_INPUTCTRL_POSSEL_PB10, acmpInputPB11 = _ACMP_INPUTCTRL_POSSEL_PB11, acmpInputPB12 = _ACMP_INPUTCTRL_POSSEL_PB12, acmpInputPB13 = _ACMP_INPUTCTRL_POSSEL_PB13, acmpInputPB14 = _ACMP_INPUTCTRL_POSSEL_PB14, acmpInputPB15 = _ACMP_INPUTCTRL_POSSEL_PB15, acmpInputPC0 = _ACMP_INPUTCTRL_POSSEL_PC0, acmpInputPC1 = _ACMP_INPUTCTRL_POSSEL_PC1, acmpInputPC2 = _ACMP_INPUTCTRL_POSSEL_PC2, acmpInputPC3 = _ACMP_INPUTCTRL_POSSEL_PC3, acmpInputPC4 = _ACMP_INPUTCTRL_POSSEL_PC4, acmpInputPC5 = _ACMP_INPUTCTRL_POSSEL_PC5, acmpInputPC6 = _ACMP_INPUTCTRL_POSSEL_PC6, acmpInputPC7 = _ACMP_INPUTCTRL_POSSEL_PC7, acmpInputPC8 = _ACMP_INPUTCTRL_POSSEL_PC8, acmpInputPC9 = _ACMP_INPUTCTRL_POSSEL_PC9, acmpInputPC10 = _ACMP_INPUTCTRL_POSSEL_PC10, acmpInputPC11 = _ACMP_INPUTCTRL_POSSEL_PC11, acmpInputPC12 = _ACMP_INPUTCTRL_POSSEL_PC12, acmpInputPC13 = _ACMP_INPUTCTRL_POSSEL_PC13, acmpInputPC14 = _ACMP_INPUTCTRL_POSSEL_PC14, acmpInputPC15 = _ACMP_INPUTCTRL_POSSEL_PC15, acmpInputPD0 = _ACMP_INPUTCTRL_POSSEL_PD0, acmpInputPD1 = _ACMP_INPUTCTRL_POSSEL_PD1, acmpInputPD2 = _ACMP_INPUTCTRL_POSSEL_PD2, acmpInputPD3 = _ACMP_INPUTCTRL_POSSEL_PD3, acmpInputPD4 = _ACMP_INPUTCTRL_POSSEL_PD4, acmpInputPD5 = _ACMP_INPUTCTRL_POSSEL_PD5, acmpInputPD6 = _ACMP_INPUTCTRL_POSSEL_PD6, acmpInputPD7 = _ACMP_INPUTCTRL_POSSEL_PD7, acmpInputPD8 = _ACMP_INPUTCTRL_POSSEL_PD8, acmpInputPD9 = _ACMP_INPUTCTRL_POSSEL_PD9, acmpInputPD10 = _ACMP_INPUTCTRL_POSSEL_PD10, acmpInputPD11 = _ACMP_INPUTCTRL_POSSEL_PD11, acmpInputPD12 = _ACMP_INPUTCTRL_POSSEL_PD12, acmpInputPD13 = _ACMP_INPUTCTRL_POSSEL_PD13, acmpInputPD14 = _ACMP_INPUTCTRL_POSSEL_PD14, acmpInputPD15 = _ACMP_INPUTCTRL_POSSEL_PD15 } |
enum |
ACMP_HysteresisLevel_TypeDef
{
acmpHysteresisDisabled = _ACMP_CFG_HYST_DISABLED, acmpHysteresis10Sym = _ACMP_CFG_HYST_SYM10MV, acmpHysteresis20Sym = _ACMP_CFG_HYST_SYM20MV, acmpHysteresis30Sym = _ACMP_CFG_HYST_SYM30MV, acmpHysteresis10Pos = _ACMP_CFG_HYST_POS10MV, acmpHysteresis20Pos = _ACMP_CFG_HYST_POS20MV, acmpHysteresis30Pos = _ACMP_CFG_HYST_POS30MV, acmpHysteresis10Neg = _ACMP_CFG_HYST_NEG10MV, acmpHysteresis20Neg = _ACMP_CFG_HYST_NEG20MV, acmpHysteresis30Neg = _ACMP_CFG_HYST_NEG30MV } |
enum |
ACMP_InputRange_TypeDef
{
acmpInputRangeFull = _ACMP_CFG_INPUTRANGE_FULL, acmpInputRangeReduced = _ACMP_CFG_INPUTRANGE_REDUCED } |
Functions |
|
void | ACMP_CapsenseChannelSet (ACMP_TypeDef *acmp, ACMP_Channel_TypeDef channel) |
Set the ACMP channel used for capacitive sensing.
|
|
void | ACMP_CapsenseInit (ACMP_TypeDef *acmp, const ACMP_CapsenseInit_TypeDef *init) |
Set up ACMP for use in capacitive sense applications.
|
|
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_Disable (ACMP_TypeDef *acmp) |
Disable ACMP.
|
|
void | ACMP_Enable (ACMP_TypeDef *acmp) |
Enable ACMP.
|
|
void | ACMP_GPIOSetup (ACMP_TypeDef *acmp, GPIO_Port_TypeDef port, unsigned int pin, bool enable, bool invert) |
Sets up GPIO output from the ACMP.
|
|
void | ACMP_Init (ACMP_TypeDef *acmp, const ACMP_Init_TypeDef *init) |
Initialize ACMP.
|
|
__STATIC_INLINE void | ACMP_IntClear (ACMP_TypeDef *acmp, uint32_t flags) |
Clear one or more pending ACMP interrupts.
|
|
__STATIC_INLINE void | ACMP_IntDisable (ACMP_TypeDef *acmp, uint32_t flags) |
Disable one or more ACMP interrupts.
|
|
__STATIC_INLINE void | ACMP_IntEnable (ACMP_TypeDef *acmp, uint32_t flags) |
Enable one or more ACMP interrupts.
|
|
__STATIC_INLINE uint32_t | ACMP_IntGet (ACMP_TypeDef *acmp) |
Get pending ACMP interrupt flags.
|
|
__STATIC_INLINE uint32_t | ACMP_IntGetEnabled (ACMP_TypeDef *acmp) |
Get enabled and pending ACMP interrupt flags. Useful for handling more interrupt sources in the same interrupt handler.
|
|
__STATIC_INLINE void | ACMP_IntSet (ACMP_TypeDef *acmp, uint32_t flags) |
Set one or more pending ACMP interrupts from software.
|
|
__STATIC_INLINE ACMP_Channel_TypeDef | ACMP_PortPinToInput ( GPIO_Port_TypeDef port, uint8_t pin) |
Convert GPIO port/pin to ACMP input selection.
|
|
void | ACMP_Reset (ACMP_TypeDef *acmp) |
Reset ACMP to the same state that it was in after a hardware reset.
|
|
Macro Definition Documentation
#define ACMP_CAPSENSE_INIT_DEFAULT |
A default configuration for capacitive sense mode initialization.
Definition at line
684
of file
em_acmp.h
.
Referenced by CAPSENSE_Init() .
#define ACMP_INIT_DEFAULT |
Default configuration for ACMP regular initialization.
Definition at line
827
of file
em_acmp.h
.
Enumeration Type Documentation
Resistor values used for the internal capacative sense resistor. See data sheet for your device for details on each resistor value.
Definition at line
62
of file
em_acmp.h
.
enum ACMP_Channel_TypeDef |
ACMP Input Selection.
Definition at line
279
of file
em_acmp.h
.
Hysteresis level. See data sheet for your device for details on each level.
Definition at line
87
of file
em_acmp.h
.
Function Documentation
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).
- Can only be called when the peripheral is enabled.
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block. [in] channel
The ACMP channel to use for capacitive sensing (Possel).
Definition at line
247
of file
em_acmp.c
.
References BUS_RegMaskedWrite() .
Referenced by CAPSENSE_Measure() .
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).
- A call to ACMP_CapsenseInit will enable and disable the ACMP peripheral, which can cause side effects if it was previously set up.
- 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.
Definition at line
165
of file
em_acmp.c
.
References ACMP_Disable() , ACMP_Enable() , ACMP_CapsenseInit_TypeDef::biasProg , BUS_RegBitWrite() , ACMP_CapsenseInit_TypeDef::enable , ACMP_CapsenseInit_TypeDef::hysteresisLevel , ACMP_CapsenseInit_TypeDef::resistor , and ACMP_CapsenseInit_TypeDef::vrefDiv .
Referenced by CAPLESENSE_setupACMP() , and CAPSENSE_Init() .
void ACMP_ChannelSet | ( | ACMP_TypeDef * |
acmp,
|
ACMP_Channel_TypeDef |
negSel,
|
||
ACMP_Channel_TypeDef |
posSel
|
||
) |
Set which channels should be used in ACMP comparisons.
- Note
- Can only be called when the peripheral is enabled.
- If GPIO is used for both posSel and negSel, they cannot both use even or odd pins.
- 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.
Definition at line
496
of file
em_acmp.c
.
void ACMP_Disable | ( | ACMP_TypeDef * |
acmp
|
) |
Disable ACMP.
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block.
Definition at line
288
of file
em_acmp.c
.
Referenced by ACMP_CapsenseInit() , ACMP_Init() , ACMP_Reset() , and CAPSENSE_Sense() .
void ACMP_Enable | ( | ACMP_TypeDef * |
acmp
|
) |
Enable ACMP.
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block.
Definition at line
310
of file
em_acmp.c
.
Referenced by ACMP_CapsenseInit() , ACMP_Init() , ACMP_Reset() , and CAPSENSE_Sense() .
void ACMP_GPIOSetup | ( | ACMP_TypeDef * |
acmp,
|
GPIO_Port_TypeDef |
port,
|
||
unsigned int |
pin,
|
||
bool |
enable,
|
||
bool |
invert
|
||
) |
Sets up GPIO output from the ACMP.
- Note
-
GPIO must be enabled in the CMU before this function call, i.e.
CMU_ClockEnable(cmuClock_GPIO, true);
- Parameters
-
[in] acmp
Pointer to the ACMP peripheral register block. port
The GPIO port to use. pin
The GPIO pin to use. enable
Enable or disable pin output. invert
Invert output.
Definition at line
411
of file
em_acmp.c
.
Referenced by CAPLESENSE_setupACMP() .
void ACMP_Init | ( | ACMP_TypeDef * |
acmp,
|
const ACMP_Init_TypeDef * |
init
|
||
) |
Initialize ACMP.
- Note
- A call to ACMP_Init can cause side effects since it can enable/disable the peripheral.
- Parameters
-
[in] acmp
A pointer to the ACMP peripheral register block. [in] init
A pointer to the initialization structure used to configure ACMP.
Definition at line
560
of file
em_acmp.c
.
References ACMP_Init_TypeDef::accuracy , ACMP_Disable() , ACMP_Enable() , ACMP_Init_TypeDef::biasProg , BUS_RegMaskedWrite() , ACMP_Init_TypeDef::enable , ACMP_Init_TypeDef::hysteresisLevel , ACMP_Init_TypeDef::inactiveValue , ACMP_Init_TypeDef::inputRange , and ACMP_Init_TypeDef::vrefDiv .
__STATIC_INLINE void ACMP_IntClear | ( | ACMP_TypeDef * |
acmp,
|
uint32_t |
flags
|
||
) |
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.
Definition at line
974
of file
em_acmp.h
.
__STATIC_INLINE void ACMP_IntDisable | ( | ACMP_TypeDef * |
acmp,
|
uint32_t |
flags
|
||
) |
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.
Definition at line
995
of file
em_acmp.h
.
References BUS_RegMaskedClear() .
__STATIC_INLINE void ACMP_IntEnable | ( | ACMP_TypeDef * |
acmp,
|
uint32_t |
flags
|
||
) |
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.
Definition at line
1017
of file
em_acmp.h
.
__STATIC_INLINE uint32_t ACMP_IntGet | ( | ACMP_TypeDef * |
acmp
|
) |
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.
Definition at line
1041
of file
em_acmp.h
.
__STATIC_INLINE uint32_t ACMP_IntGetEnabled | ( | ACMP_TypeDef * |
acmp
|
) |
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).
Definition at line
1065
of file
em_acmp.h
.
__STATIC_INLINE void ACMP_IntSet | ( | ACMP_TypeDef * |
acmp,
|
uint32_t |
flags
|
||
) |
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.
Definition at line
1089
of file
em_acmp.h
.
__STATIC_INLINE ACMP_Channel_TypeDef ACMP_PortPinToInput | ( | GPIO_Port_TypeDef |
port,
|
uint8_t |
pin
|
||
) |
Convert GPIO port/pin to ACMP input selection.
- Parameters
-
[in] port
GPIO port [in] pin
GPIO pin
- Returns
- ACMP input selection
Definition at line
1112
of file
em_acmp.h
.
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.
Definition at line
362
of file
em_acmp.c
.
References ACMP_Disable() , and ACMP_Enable() .