ACMP - Analog Comparator#
Analog Comparator peripheral API.
Introduction#
This module contains functions to control the Analog Comparator (ACMP) peripheral of Silicon Labs' 32-bit MCUs and SoCs.
The Analog Comparator compares the voltage of two analog inputs and outputs a digital signal indicating which input voltage is higher. Inputs can either be from internal references or from external pins. Response time, and thereby the current consumption, can be configured by altering the current supply to the comparator.
Example#
This example shows how to use the em_acmp.h API for comparing an input pin to an internal 2.5 V reference voltage.
ACMP Base example:
{
#define GPIO_ACMPOUT PD1 // Pin location for ACMP OUT varies depending on the device.
// Enable bus clocks.
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_ACMP0);
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_GPIO);
// Initialize with default settings.
sl_hal_acmp_init_t init = SL_HAL_ACMP_INIT_DEFAULT;
sl_hal_acmp_init(ACMP0, &init);
sl_hal_acmp_enable(ACMP0);
// Now we select the two inputs to compare. Here we compare the SL_HAL_ACMP_INPUT_PD2
// input to the internal 2.5V reference. When SL_HAL_ACMP_INPUT_PD2 is lower than
// 2.5 V then the ACMP output is 0 and when SL_HAL_ACMP_INPUT_PD2 is higher than
// 2.5 V then the ACMP output is 1.
sl_hal_acmp_set_input(ACMP0, SL_HAL_ACMP_INPUT_VREFDIV2V5, SL_HAL_ACMP_INPUT_PD2);
// Allocate CDEVEN0 to ACMP0 to be able to use the input.
GPIO->CDBUSALLOC = GPIO_CDBUSALLOC_CDEVEN0_ACMP0;
// To be able to probe the output we can send the ACMP output to a pin.
sl_hal_acmp_setup_gpio_inversion(ACMP0, false);
GPIO->ACMPROUTE[ACMP_NUM(ACMP0)].ACMPOUTROUTE = (GPIO_ACMPOUT->port << _GPIO_ACMP_ACMPOUTROUTE_PORT_SHIFT)
| (GPIO_ACMPOUT->pin << _GPIO_ACMP_ACMPOUTROUTE_PIN_SHIFT);
GPIO->ACMPROUTE[ACMP_NUM(ACMP0)].ROUTEEN = GPIO_ACMP_ROUTEEN_ACMPOUTPEN;
}
Modules#
Enumerations#
Hysteresis level.
vcm/input range.
Accuracy mode.
Input Selection.
Functions#
Initialize ACMP.
Reset ACMP to the state it is after a hardware reset.
Set up GPIO output inversion from the ACMP.
Set which channels are used in ACMP comparisons.
Enable ACMP.
Disable ACMP.
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.
Get enabled ACMP interrupts.
Set one or more pending ACMP interrupts from software.
Convert GPIO port/pin to ACMP input selection.
Wait for ongoing sync of register(s) to the low-frequency domain to complete.
Wait for disabling to finish.
Return the content of the status register.
Macros#
Validation of ACMP register block pointer reference for assert statements.
Analog comparator CFG with initial bias value.
Analog comparator reset value.
Default configuration for ACMP regular initialization.
Enumeration Documentation#
sl_hal_acmp_hysteresis_t#
sl_hal_acmp_hysteresis_t
Hysteresis level.
Enumerator | |
---|---|
SL_HAL_ACMP_HYSTERESIS_DISABLED | Mode DISABLED for ACMP_CFG. |
SL_HAL_ACMP_HYSTERESIS_SYM_10MV | Mode HYST10SYM for ACMP_CFG. |
SL_HAL_ACMP_HYSTERESIS_SYM_20MV | Mode HYST20SYM for ACMP_CFG. |
SL_HAL_ACMP_HYSTERESIS_SYM_30MV | Mode HYST30SYM for ACMP_CFG. |
SL_HAL_ACMP_HYSTERESIS_POS_10MV | Mode HYST10POS for ACMP_CFG. |
SL_HAL_ACMP_HYSTERESIS_POS_20MV | Mode HYST20POS for ACMP_CFG. |
SL_HAL_ACMP_HYSTERESIS_POS_30MV | Mode HYST30POS for ACMP_CFG. |
SL_HAL_ACMP_HYSTERESIS_NEG_10MV | Mode HYST10NEG for ACMP_CFG. |
SL_HAL_ACMP_HYSTERESIS_NEG_20MV | Mode HYST20NEG for ACMP_CFG. |
SL_HAL_ACMP_HYSTERESIS_NEG_30MV | Mode HYST30NEG for ACMP_CFG. |
sl_hal_acmp_input_range_t#
sl_hal_acmp_input_range_t
vcm/input range.
Enumerator | |
---|---|
SL_HAL_ACMP_INPUT_RANGE_FULL | Input can be from 0 to VDD. |
SL_HAL_ACMP_INPUT_RANGE_REDUCED | Input can be from 0 to VDD-0.7 V. |
sl_hal_acmp_accuracy_t#
sl_hal_acmp_accuracy_t
Accuracy mode.
Enumerator | |
---|---|
SL_HAL_ACMP_ACCURACY_LOW | Low-accuracy mode which consumes less current. |
SL_HAL_ACMP_ACCURACY_HIGH | High-accuracy mode which consumes more current. |
sl_hal_acmp_input_t#
sl_hal_acmp_input_t
Input Selection.
Enumerator | |
---|---|
SL_HAL_ACMP_INPUT_VSS | Select VSS. |
SL_HAL_ACMP_INPUT_VREFDIVAVDD | Select Divided AVDD. |
SL_HAL_ACMP_INPUT_VREFDIVAVDDLP | Select Low-Power Divided AVDD. |
SL_HAL_ACMP_INPUT_VREFDIV1V25 | Select Divided 1V25 reference. |
SL_HAL_ACMP_INPUT_VREFDIV1V25LP | Select Low-power Divided 1V25 reference. |
SL_HAL_ACMP_INPUT_VREFDIV2V5 | Select Divided 2V5 reference. |
SL_HAL_ACMP_INPUT_VREFDIV2V5LP | Select Low-power Divided 2V5 reference. |
SL_HAL_ACMP_INPUT_VSENSE01DIV4 | Select VSENSE0 divided by 4. |
SL_HAL_ACMP_INPUT_VSENSE01DIV4LP | Select Low-power VSENSE0 divided by 4. |
SL_HAL_ACMP_INPUT_VSENSE11DIV4 | Select VSENSE1 divided by 4. |
SL_HAL_ACMP_INPUT_VSENSE11DIV4LP | Select Low-power VSENSE1 divided by 4. |
SL_HAL_ACMP_INPUT_VDACOUT0 | Select VDAC0 channel 0 output. |
SL_HAL_ACMP_INPUT_VDACOUT1 | Select VDAC0 channel 1 output. |
SL_HAL_ACMP_INPUT_EXTPA | Select external interface, base is PA0. |
SL_HAL_ACMP_INPUT_EXTPB | Select external interface, base is PB0. |
SL_HAL_ACMP_INPUT_EXTPC | Select external interface, base is PC0. |
SL_HAL_ACMP_INPUT_EXTPD | Select external interface, base is PD0. |
SL_HAL_ACMP_INPUT_PA0 | Select Port A Pin0. |
SL_HAL_ACMP_INPUT_PA1 | Select Port A Pin1. |
SL_HAL_ACMP_INPUT_PA2 | Select Port A Pin2. |
SL_HAL_ACMP_INPUT_PA3 | Select Port A Pin3. |
SL_HAL_ACMP_INPUT_PA4 | Select Port A Pin4. |
SL_HAL_ACMP_INPUT_PA5 | Select Port A Pin5. |
SL_HAL_ACMP_INPUT_PA6 | Select Port A Pin6. |
SL_HAL_ACMP_INPUT_PA7 | Select Port A Pin7. |
SL_HAL_ACMP_INPUT_PA8 | Select Port A Pin8. |
SL_HAL_ACMP_INPUT_PA9 | Select Port A Pin9. |
SL_HAL_ACMP_INPUT_PA10 | Select Port A Pin10. |
SL_HAL_ACMP_INPUT_PA11 | Select Port A Pin11. |
SL_HAL_ACMP_INPUT_PA12 | Select Port A Pin12. |
SL_HAL_ACMP_INPUT_PA13 | Select Port A Pin13. |
SL_HAL_ACMP_INPUT_PA14 | Select Port A Pin14. |
SL_HAL_ACMP_INPUT_PA15 | Select Port A Pin15. |
SL_HAL_ACMP_INPUT_PB0 | Select Port B Pin0. |
SL_HAL_ACMP_INPUT_PB1 | Select Port B Pin1. |
SL_HAL_ACMP_INPUT_PB2 | Select Port B Pin2. |
SL_HAL_ACMP_INPUT_PB3 | Select Port B Pin3. |
SL_HAL_ACMP_INPUT_PB4 | Select Port B Pin4. |
SL_HAL_ACMP_INPUT_PB5 | Select Port B Pin5. |
SL_HAL_ACMP_INPUT_PB6 | Select Port B Pin6. |
SL_HAL_ACMP_INPUT_PB7 | Select Port B Pin7. |
SL_HAL_ACMP_INPUT_PB8 | Select Port B Pin8. |
SL_HAL_ACMP_INPUT_PB9 | Select Port B Pin9. |
SL_HAL_ACMP_INPUT_PB10 | Select Port B Pin10. |
SL_HAL_ACMP_INPUT_PB11 | Select Port B Pin11. |
SL_HAL_ACMP_INPUT_PB12 | Select Port B Pin12. |
SL_HAL_ACMP_INPUT_PB13 | Select Port B Pin13. |
SL_HAL_ACMP_INPUT_PB14 | Select Port B Pin14. |
SL_HAL_ACMP_INPUT_PB15 | Select Port B Pin15. |
SL_HAL_ACMP_INPUT_PC0 | Select Port C Pin0. |
SL_HAL_ACMP_INPUT_PC1 | Select Port C Pin1. |
SL_HAL_ACMP_INPUT_PC2 | Select Port C Pin2. |
SL_HAL_ACMP_INPUT_PC3 | Select Port C Pin3. |
SL_HAL_ACMP_INPUT_PC4 | Select Port C Pin4. |
SL_HAL_ACMP_INPUT_PC5 | Select Port C Pin5. |
SL_HAL_ACMP_INPUT_PC6 | Select Port C Pin6. |
SL_HAL_ACMP_INPUT_PC7 | Select Port C Pin7. |
SL_HAL_ACMP_INPUT_PC8 | Select Port C Pin8. |
SL_HAL_ACMP_INPUT_PC9 | Select Port C Pin9. |
SL_HAL_ACMP_INPUT_PC10 | Select Port C Pin10. |
SL_HAL_ACMP_INPUT_PC11 | Select Port C Pin11. |
SL_HAL_ACMP_INPUT_PC12 | Select Port C Pin12. |
SL_HAL_ACMP_INPUT_PC13 | Select Port C Pin13. |
SL_HAL_ACMP_INPUT_PC14 | Select Port C Pin14. |
SL_HAL_ACMP_INPUT_PC15 | Select Port C Pin15. |
SL_HAL_ACMP_INPUT_PD0 | Select Port D Pin0. |
SL_HAL_ACMP_INPUT_PD1 | Select Port D Pin1. |
SL_HAL_ACMP_INPUT_PD2 | Select Port D Pin2. |
SL_HAL_ACMP_INPUT_PD3 | Select Port D Pin3. |
SL_HAL_ACMP_INPUT_PD4 | Select Port D Pin4. |
SL_HAL_ACMP_INPUT_PD5 | Select Port D Pin5. |
SL_HAL_ACMP_INPUT_PD6 | Select Port D Pin6. |
SL_HAL_ACMP_INPUT_PD7 | Select Port D Pin7. |
SL_HAL_ACMP_INPUT_PD8 | Select Port D Pin8. |
SL_HAL_ACMP_INPUT_PD9 | Select Port D Pin9. |
SL_HAL_ACMP_INPUT_PD10 | Select Port D Pin10. |
SL_HAL_ACMP_INPUT_PD11 | Select Port D Pin11. |
SL_HAL_ACMP_INPUT_PD12 | Select Port D Pin12. |
SL_HAL_ACMP_INPUT_PD13 | Select Port D Pin13. |
SL_HAL_ACMP_INPUT_PD14 | Select Port D Pin14. |
SL_HAL_ACMP_INPUT_PD15 | Select Port D Pin15. |
Function Documentation#
sl_hal_acmp_init#
void sl_hal_acmp_init (ACMP_TypeDef * acmp, const sl_hal_acmp_init_t * init)
Initialize ACMP.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [in] | acmp | A pointer to the ACMP peripheral register block. |
const sl_hal_acmp_init_t * | [in] | init | A pointer to the initialization structure used to configure ACMP. |
Note
A call to ACMP_Init can cause side effects since it can enable/disable the peripheral.
sl_hal_acmp_reset#
void sl_hal_acmp_reset (ACMP_TypeDef * acmp)
Reset ACMP to the state it is after a hardware reset.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [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.
sl_hal_acmp_setup_gpio_inversion#
void sl_hal_acmp_setup_gpio_inversion (ACMP_TypeDef * acmp, bool invert)
Set up GPIO output inversion from the ACMP.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [in] | acmp | Pointer to the ACMP peripheral register block. |
bool | [in] | invert | true = GPIO output is inverted. false = GPIO output is not inverted. |
sl_hal_acmp_set_input#
void sl_hal_acmp_set_input (ACMP_TypeDef * acmp, sl_hal_acmp_input_t negative_input, sl_hal_acmp_input_t positive_input)
Set which channels are used in ACMP comparisons.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [in] | acmp | A pointer to the ACMP peripheral register block. |
sl_hal_acmp_input_t | [in] | negative_input | ACMP channel for the negative input. |
sl_hal_acmp_input_t | [in] | positive_input | ACMP channel for the positive input. |
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.
sl_hal_acmp_enable#
void sl_hal_acmp_enable (ACMP_TypeDef * acmp)
Enable ACMP.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [in] | acmp | A pointer to the ACMP peripheral register block. |
sl_hal_acmp_disable#
void sl_hal_acmp_disable (ACMP_TypeDef * acmp)
Disable ACMP.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [in] | acmp | A pointer to the ACMP peripheral register block. |
sl_hal_acmp_clear_interrupts#
void sl_hal_acmp_clear_interrupts (ACMP_TypeDef * acmp, uint32_t flags)
Clear one or more pending ACMP interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [in] | acmp | A pointer to the ACMP peripheral register block. |
uint32_t | [in] | flags | Pending ACMP interrupt source to clear. Use one or more valid interrupt flags for the ACMP module (ACMP_IF_nnn) OR'ed together. |
sl_hal_acmp_disable_interrupts#
void sl_hal_acmp_disable_interrupts (ACMP_TypeDef * acmp, uint32_t flags)
Disable one or more ACMP interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [in] | acmp | A pointer to the ACMP peripheral register block. |
uint32_t | [in] | flags | ACMP interrupt sources to disable. Use one or more valid interrupt flags for the ACMP module (ACMP_IF_nnn) OR'ed together. |
sl_hal_acmp_enable_interrupts#
void sl_hal_acmp_enable_interrupts (ACMP_TypeDef * acmp, uint32_t flags)
Enable one or more ACMP interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [in] | acmp | A pointer to the ACMP peripheral register block. |
uint32_t | [in] | flags | ACMP interrupt sources to enable. Use one or more valid interrupt flags for the ACMP module (ACMP_IF_nnn) OR'ed together. |
Note
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. Use ACMP_IntClear() prior to enabling if a pending interrupt should be ignored.
sl_hal_acmp_get_pending_interrupts#
uint32_t sl_hal_acmp_get_pending_interrupts (ACMP_TypeDef * acmp)
Get pending ACMP interrupt flags.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [in] | acmp | A pointer to the ACMP peripheral register block. |
Note
This function does not clear event bits.
Returns
Pending ACMP interrupt sources. Use one or more valid interrupt flags for the ACMP module (ACMP_IF_nnn) OR'ed together.
sl_hal_acmp_get_enabled_pending_interrupts#
uint32_t sl_hal_acmp_get_enabled_pending_interrupts (ACMP_TypeDef * acmp)
Get enabled and pending ACMP interrupt flags.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [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).
sl_hal_acmp_get_enabled_interrupts#
uint32_t sl_hal_acmp_get_enabled_interrupts (ACMP_TypeDef * acmp)
Get enabled ACMP interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [in] | acmp | A pointer to the ACMP peripheral register block. |
Useful for handling more interrupt sources in the same interrupt handler.
Returns
Enabled ACMP interrupt sources.
sl_hal_acmp_set_interrupts#
void sl_hal_acmp_set_interrupts (ACMP_TypeDef * acmp, uint32_t flags)
Set one or more pending ACMP interrupts from software.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [in] | acmp | A pointer to the ACMP peripheral register block. |
uint32_t | [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. |
sl_hal_acmp_gpio_to_input#
sl_hal_acmp_input_t sl_hal_acmp_gpio_to_input (uint32_t port, uint32_t pin)
Convert GPIO port/pin to ACMP input selection.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | port | GPIO port to convert. |
uint32_t | [in] | pin | GPIO pin to convert. |
Returns
ACMP input selection of the selected GPIO port and pin.
sl_hal_acmp_wait_sync#
void sl_hal_acmp_wait_sync (ACMP_TypeDef * acmp)
Wait for ongoing sync of register(s) to the low-frequency domain to complete.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [in] | acmp | A pointer to the ACMP peripheral register block. |
sl_hal_acmp_wait_ready#
void sl_hal_acmp_wait_ready (ACMP_TypeDef * acmp)
Wait for disabling to finish.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [in] | acmp | A pointer to the ACMP peripheral register block. |
sl_hal_acmp_get_status#
uint32_t sl_hal_acmp_get_status (ACMP_TypeDef * acmp)
Return the content of the status register.
Type | Direction | Argument Name | Description |
---|---|---|---|
ACMP_TypeDef * | [in] | acmp | A pointer to the ACMP peripheral register block. |
Returns
Status register.