ACMP - Analog Comparator#
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.
/* The ACMP is a high-frequency peripheral so we need to enable
* both the HFPER clock and the ACMP0 clock. */
CMU_ClockEnable(cmuClock_HFPER, true);
CMU_ClockEnable(cmuClock_ACMP0, true);
/* Initialize with default settings. */
ACMP_Init_TypeDef init = ACMP_INIT_DEFAULT;
init.enable = false;
ACMP_Init(ACMP0, &init);
/* Setup the two channels to compare. The first argument is the negative
* channel and the second argument is the positive channel.
*
* Here we compare channel 0 with the 2.5 V internal reference. When
* channel 0 is lower than 2.5 V then the ACMP output is 0 and when
* channel 0 voltage is higher than 2.5 V then the ACMP output is 1. */
ACMP_ChannelSet(ACMP0, acmpChannel2V5, acmpChannel0);
/* To be able to probe the output we can send the ACMP output to a pin.
* The second argument to this function is the pin location which is
* device dependent. */
ACMP_GPIOSetup(ACMP0, 0, true, false);
/* Finally we enable the ACMP. */
ACMP_Enable(ACMP0);
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.
Modules#
Enumerations#
Resistor values used for the internal capacitive sense resistor.
Hysteresis level.
ACMP warmup time.
ACMP inputs.
Functions#
Set up ACMP for use in capacitive sense applications.
Set the ACMP channel used for capacitive sensing.
Set which channels should be used in ACMP comparisons.
Disable ACMP.
Enable ACMP.
Set up GPIO output from ACMP.
Initialize ACMP.
Reset ACMP to the same state that it was in after a hardware reset.
Clear one or more pending ACMP interrupts.
Disable one or more ACMP interrupts.
Enable one or more ACMP interrupts.
Get pending ACMP interrupt flags.
Get enabled and pending ACMP interrupt flags.
Set one or more pending ACMP interrupts from software.
Macros#
A default configuration for capacitive sense mode initialization.
Default configuration for ACMP regular initialization.
Enumeration Documentation#
ACMP_CapsenseResistor_TypeDef#
ACMP_CapsenseResistor_TypeDef
Resistor values used for the internal capacitive sense resistor.
See data sheet for your device for details on each resistor value.
Enumerator | |
---|---|
acmpResistor0 | Resistor value 0. |
acmpResistor1 | Resistor value 1. |
acmpResistor2 | Resistor value 2. |
acmpResistor3 | Resistor value 3. |
57
of file platform/emlib/inc/em_acmp.h
ACMP_HysteresisLevel_TypeDef#
ACMP_HysteresisLevel_TypeDef
Hysteresis level.
See data sheet for your device for details on each level.
Enumerator | |
---|---|
acmpHysteresisLevel0 | Hysteresis level 0. |
acmpHysteresisLevel1 | Hysteresis level 1. |
acmpHysteresisLevel2 | Hysteresis level 2. |
acmpHysteresisLevel3 | Hysteresis level 3. |
acmpHysteresisLevel4 | Hysteresis level 4. |
acmpHysteresisLevel5 | Hysteresis level 5. |
acmpHysteresisLevel6 | Hysteresis level 6. |
acmpHysteresisLevel7 | Hysteresis level 7. |
82
of file platform/emlib/inc/em_acmp.h
ACMP_WarmTime_TypeDef#
ACMP_WarmTime_TypeDef
ACMP warmup time.
The delay is measured in HFPERCLK / HFPERCCLK cycles and should be at least 10 us.
Enumerator | |
---|---|
acmpWarmTime4 | 4 cycles warmup |
acmpWarmTime8 | 8 cycles warmup |
acmpWarmTime16 | 16 cycles warmup |
acmpWarmTime32 | 32 cycles warmup |
acmpWarmTime64 | 64 cycles warmup |
acmpWarmTime128 | 128 cycles warmup |
acmpWarmTime256 | 256 cycles warmup |
acmpWarmTime512 | 512 cycles warmup |
128
of file platform/emlib/inc/em_acmp.h
ACMP_Channel_TypeDef#
ACMP_Channel_TypeDef
ACMP inputs.
Note that scaled VDD and bandgap references can only be used as negative inputs.
Enumerator | |
---|---|
acmpChannel0 | Channel 0. |
acmpChannel1 | Channel 1. |
acmpChannel2 | Channel 2. |
acmpChannel3 | Channel 3. |
acmpChannel4 | Channel 4. |
acmpChannel5 | Channel 5. |
acmpChannel6 | Channel 6. |
acmpChannel7 | Channel 7. |
acmpChannel1V25 | 1.25 V internal reference |
acmpChannel2V5 | 2.5 V internal reference |
acmpChannelVDD | Scaled VDD reference. |
acmpChannelCapSense | Capacitive sense mode. |
540
of file platform/emlib/inc/em_acmp.h
Function Documentation#
ACMP_CapsenseInit#
void ACMP_CapsenseInit (ACMP_TypeDef * acmp, const ACMP_CapsenseInit_TypeDef * init)
Set up ACMP for use in capacitive sense applications.
[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. |
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).
166
of file platform/emlib/src/em_acmp.c
ACMP_CapsenseChannelSet#
void ACMP_CapsenseChannelSet (ACMP_TypeDef * acmp, ACMP_Channel_TypeDef channel)
Set the ACMP channel used for capacitive sensing.
[in] | acmp | A pointer to the ACMP peripheral register block. |
[in] | channel | The ACMP channel to use for capacitive sensing (Possel). |
Note
A basic example of capacitive sensing can be found in the STK BSP (capsense demo).
248
of file platform/emlib/src/em_acmp.c
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.
[in] | acmp | A pointer to the ACMP peripheral register block. |
N/A | negSel | A channel to use on the negative input to the ACMP. |
N/A | posSel | A channel to use on the positive input to the ACMP. |
507
of file platform/emlib/src/em_acmp.c
ACMP_Disable#
void ACMP_Disable (ACMP_TypeDef * acmp)
Disable ACMP.
[in] | acmp | A pointer to the ACMP peripheral register block. |
286
of file platform/emlib/src/em_acmp.c
ACMP_Enable#
void ACMP_Enable (ACMP_TypeDef * acmp)
Enable ACMP.
[in] | acmp | A pointer to the ACMP peripheral register block. |
315
of file platform/emlib/src/em_acmp.c
ACMP_GPIOSetup#
void ACMP_GPIOSetup (ACMP_TypeDef * acmp, uint32_t location, bool enable, bool invert)
Set up GPIO output from ACMP.
[in] | acmp | A pointer to the ACMP peripheral register block. |
N/A | location | The pin location to use. See the data sheet for location to pin mappings. |
N/A | enable | Enable or disable pin output. |
N/A | invert | Invert output. |
Note
GPIO must be enabled in the CMU before this function call, i.e.,
CMU_ClockEnable(cmuClock_GPIO, true);
462
of file platform/emlib/src/em_acmp.c
ACMP_Init#
void ACMP_Init (ACMP_TypeDef * acmp, const ACMP_Init_TypeDef * init)
Initialize ACMP.
[in] | acmp | A pointer to the ACMP peripheral register block. |
[in] | init | A pointer to the initialization structure used to configure ACMP. |
580
of file platform/emlib/src/em_acmp.c
ACMP_Reset#
void ACMP_Reset (ACMP_TypeDef * acmp)
Reset ACMP to the same state that it was in after a hardware reset.
[in] | acmp | A pointer to the ACMP peripheral register block. |
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.
367
of file platform/emlib/src/em_acmp.c
ACMP_IntClear#
void ACMP_IntClear (ACMP_TypeDef * acmp, uint32_t flags)
Clear one or more pending ACMP interrupts.
[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. |
989
of file platform/emlib/inc/em_acmp.h
ACMP_IntDisable#
void ACMP_IntDisable (ACMP_TypeDef * acmp, uint32_t flags)
Disable one or more ACMP interrupts.
[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. |
1010
of file platform/emlib/inc/em_acmp.h
ACMP_IntEnable#
void ACMP_IntEnable (ACMP_TypeDef * acmp, uint32_t flags)
Enable one or more ACMP interrupts.
[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. |
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.
1032
of file platform/emlib/inc/em_acmp.h
ACMP_IntGet#
uint32_t ACMP_IntGet (ACMP_TypeDef * acmp)
Get pending ACMP interrupt flags.
[in] | acmp | A pointer to the ACMP peripheral register block. |
Note
This function does not clear event bits.
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.
1056
of file platform/emlib/inc/em_acmp.h
ACMP_IntGetEnabled#
uint32_t ACMP_IntGetEnabled (ACMP_TypeDef * acmp)
Get enabled and pending ACMP interrupt flags.
[in] | acmp | A pointer to the ACMP 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 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).
1080
of file platform/emlib/inc/em_acmp.h
ACMP_IntSet#
void ACMP_IntSet (ACMP_TypeDef * acmp, uint32_t flags)
Set one or more pending ACMP interrupts from software.
[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. |
1104
of file platform/emlib/inc/em_acmp.h
Macro Definition Documentation#
ACMP_CAPSENSE_INIT_DEFAULT#
#define ACMP_CAPSENSE_INIT_DEFAULTValue:
A default configuration for capacitive sense mode initialization.
718
of file platform/emlib/inc/em_acmp.h
ACMP_INIT_DEFAULT#
#define ACMP_INIT_DEFAULTValue:
Default configuration for ACMP regular initialization.
867
of file platform/emlib/inc/em_acmp.h