EFM32 Happy Gecko Software Documentation
efm32hg-doc-5.1.2
|
Analog comparator (ACMP) Peripheral API.
The Analog Comparator is used to compare the 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 thereby also the current consumption can be configured by altering the current supply to the comparator.
The ACMP is available down to EM3 and is able to wakeup the system when input signals pass a certain threshold. Use ACMP_IntEnable to enable an edge interrupt to use this functionality.
Here is an example of how to use the em_acmp.h API for comparing an input pin to an internal 2.5V reference voltage.
The ACMP also contains specialized hardware for capacitive sensing. This module contains the function ACMP_CapsenseInit for initializing the ACMP for capacitive sensing and the function ACMP_CapsenseChannelSet for selecting the current capsense channel.
For applications that require capacitive sensing it is recommended to use a library like 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_CapsenseResistor_TypeDef { acmpResistor0 = _ACMP_INPUTSEL_CSRESSEL_RES0, acmpResistor1 = _ACMP_INPUTSEL_CSRESSEL_RES1, acmpResistor2 = _ACMP_INPUTSEL_CSRESSEL_RES2, acmpResistor3 = _ACMP_INPUTSEL_CSRESSEL_RES3 } |
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, acmpChannelCapSense = _ACMP_INPUTSEL_NEGSEL_CAPSENSE } |
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 } |
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 } |
Functions | |
void | ACMP_CapsenseChannelSet (ACMP_TypeDef *acmp, ACMP_Channel_TypeDef channel) |
Sets the ACMP channel used for capacative sensing. More... | |
void | ACMP_CapsenseInit (ACMP_TypeDef *acmp, const ACMP_CapsenseInit_TypeDef *init) |
Sets up the ACMP for use in capacative sense applications. More... | |
void | ACMP_ChannelSet (ACMP_TypeDef *acmp, ACMP_Channel_TypeDef negSel, ACMP_Channel_TypeDef posSel) |
Sets which channels should be used in ACMP comparisons. More... | |
void | ACMP_Disable (ACMP_TypeDef *acmp) |
Disables the ACMP. More... | |
void | ACMP_Enable (ACMP_TypeDef *acmp) |
Enables the ACMP. More... | |
void | ACMP_GPIOSetup (ACMP_TypeDef *acmp, uint32_t location, bool enable, bool invert) |
Sets up GPIO output from the ACMP. More... | |
void | ACMP_Init (ACMP_TypeDef *acmp, const ACMP_Init_TypeDef *init) |
Initialize ACMP. More... | |
__STATIC_INLINE void | ACMP_IntClear (ACMP_TypeDef *acmp, uint32_t flags) |
Clear one or more pending ACMP interrupts. More... | |
__STATIC_INLINE void | ACMP_IntDisable (ACMP_TypeDef *acmp, uint32_t flags) |
Disable one or more ACMP interrupts. More... | |
__STATIC_INLINE void | ACMP_IntEnable (ACMP_TypeDef *acmp, uint32_t flags) |
Enable one or more ACMP interrupts. More... | |
__STATIC_INLINE uint32_t | ACMP_IntGet (ACMP_TypeDef *acmp) |
Get pending ACMP interrupt flags. More... | |
__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. More... | |
__STATIC_INLINE void | ACMP_IntSet (ACMP_TypeDef *acmp, uint32_t flags) |
Set one or more pending ACMP interrupts from SW. More... | |
void | ACMP_Reset (ACMP_TypeDef *acmp) |
Reset ACMP to same state as after a HW reset. More... | |
#define ACMP_CAPSENSE_INIT_DEFAULT |
Default config for capacitive sense mode initialization.
Definition at line 622 of file em_acmp.h.
Referenced by CAPSENSE_Init().
#define ACMP_INIT_DEFAULT |
Default config for ACMP regular initialization.
enum ACMP_Channel_TypeDef |
ACMP inputs. Note that scaled VDD and bandgap references can only be used as negative inputs.
Hysteresis level. See datasheet for your device for details on each level.
ACMP warmup time. The delay is measured in HFPERCLK cycles and should be at least 10 us.
void ACMP_CapsenseChannelSet | ( | ACMP_TypeDef * | acmp, |
ACMP_Channel_TypeDef | channel | ||
) |
Sets the ACMP channel used for capacative sensing.
[in] | acmp | Pointer to ACMP peripheral register block. |
[in] | channel | The ACMP channel to use for capacative sensing (Possel). |
Definition at line 185 of file em_acmp.c.
References _ACMP_INPUTSEL_POSSEL_CH7, _ACMP_INPUTSEL_POSSEL_MASK, _ACMP_INPUTSEL_POSSEL_SHIFT, BUS_RegMaskedWrite(), and ACMP_TypeDef::INPUTSEL.
Referenced by CAPSENSE_Measure().
void ACMP_CapsenseInit | ( | ACMP_TypeDef * | acmp, |
const ACMP_CapsenseInit_TypeDef * | init | ||
) |
Sets up the ACMP for use in capacative sense applications.
This function sets up the ACMP for use in capacacitve sense applications. To use the capacative sense functionality in the ACMP you need to use the PRS output of the ACMP module to count the number of oscillations in the capacative sense circuit (possibly using a TIMER).
[in] | acmp | Pointer to ACMP peripheral register block. |
[in] | init | Pointer to initialization structure used to configure ACMP for capacative sensing operation. |
Definition at line 109 of file em_acmp.c.
References _ACMP_CTRL_BIASPROG_MASK, _ACMP_CTRL_BIASPROG_SHIFT, _ACMP_CTRL_EN_SHIFT, _ACMP_CTRL_FULLBIAS_SHIFT, _ACMP_CTRL_HALFBIAS_MASK, _ACMP_CTRL_HALFBIAS_SHIFT, _ACMP_CTRL_HYSTSEL_MASK, _ACMP_CTRL_HYSTSEL_SHIFT, _ACMP_CTRL_WARMTIME_SHIFT, _ACMP_INPUTSEL_CSRESSEL_SHIFT, _ACMP_INPUTSEL_LPREF_MASK, _ACMP_INPUTSEL_LPREF_SHIFT, _ACMP_INPUTSEL_VDDLEVEL_MASK, _ACMP_INPUTSEL_VDDLEVEL_SHIFT, ACMP_INPUTSEL_CSRESEN, ACMP_INPUTSEL_NEGSEL_CAPSENSE, ACMP_CapsenseInit_TypeDef::biasProg, BUS_RegBitWrite(), ACMP_TypeDef::CTRL, ACMP_CapsenseInit_TypeDef::enable, ACMP_CapsenseInit_TypeDef::fullBias, ACMP_CapsenseInit_TypeDef::halfBias, ACMP_CapsenseInit_TypeDef::hysteresisLevel, ACMP_TypeDef::INPUTSEL, ACMP_CapsenseInit_TypeDef::lowPowerReferenceEnabled, ACMP_CapsenseInit_TypeDef::resistor, ACMP_CapsenseInit_TypeDef::vddLevel, and ACMP_CapsenseInit_TypeDef::warmTime.
Referenced by CAPLESENSE_setupACMP(), and CAPSENSE_Init().
void ACMP_ChannelSet | ( | ACMP_TypeDef * | acmp, |
ACMP_Channel_TypeDef | negSel, | ||
ACMP_Channel_TypeDef | posSel | ||
) |
Sets which channels should be used in ACMP comparisons.
[in] | acmp | Pointer to the ACMP peripheral register block. |
negSel | Channel to use on the negative input to the ACMP. | |
posSel | Channel to use on the positive input to the ACMP. |
Definition at line 340 of file em_acmp.c.
References _ACMP_INPUTSEL_NEGSEL_CAPSENSE, _ACMP_INPUTSEL_NEGSEL_MASK, _ACMP_INPUTSEL_NEGSEL_SHIFT, _ACMP_INPUTSEL_POSSEL_CH7, _ACMP_INPUTSEL_POSSEL_MASK, _ACMP_INPUTSEL_POSSEL_SHIFT, and ACMP_TypeDef::INPUTSEL.
void ACMP_Disable | ( | ACMP_TypeDef * | acmp | ) |
Disables the ACMP.
[in] | acmp | Pointer to ACMP peripheral register block. |
Definition at line 210 of file em_acmp.c.
References ACMP_CTRL_EN, and ACMP_TypeDef::CTRL.
Referenced by CAPSENSE_Sense().
void ACMP_Enable | ( | ACMP_TypeDef * | acmp | ) |
Enables the ACMP.
[in] | acmp | Pointer to ACMP peripheral register block. |
Definition at line 225 of file em_acmp.c.
References ACMP_CTRL_EN, and ACMP_TypeDef::CTRL.
Referenced by CAPSENSE_Sense().
void ACMP_GPIOSetup | ( | ACMP_TypeDef * | acmp, |
uint32_t | location, | ||
bool | enable, | ||
bool | invert | ||
) |
Sets up GPIO output from the ACMP.
CMU_ClockEnable(cmuClock_GPIO, true);
[in] | acmp | Pointer to the ACMP peripheral register block. |
location | The pin location to use. See the datasheet for location to pin mappings. | |
enable | Enable or disable pin output. | |
invert | Invert output. |
Definition at line 305 of file em_acmp.c.
References _ACMP_CTRL_GPIOINV_MASK, _ACMP_CTRL_GPIOINV_SHIFT, _ACMP_ROUTE_ACMPPEN_SHIFT, _ACMP_ROUTE_LOCATION_SHIFT, BUS_RegMaskedWrite(), ACMP_TypeDef::CTRL, and ACMP_TypeDef::ROUTE.
Referenced by CAPLESENSE_setupACMP().
void ACMP_Init | ( | ACMP_TypeDef * | acmp, |
const ACMP_Init_TypeDef * | init | ||
) |
Initialize ACMP.
[in] | acmp | Pointer to the ACMP peripheral register block. |
[in] | init | Pointer to initialization structure used to configure ACMP for capacative sensing operation. |
Definition at line 374 of file em_acmp.c.
References _ACMP_CTRL_BIASPROG_MASK, _ACMP_CTRL_BIASPROG_SHIFT, _ACMP_CTRL_EN_SHIFT, _ACMP_CTRL_FULLBIAS_SHIFT, _ACMP_CTRL_HALFBIAS_MASK, _ACMP_CTRL_HALFBIAS_SHIFT, _ACMP_CTRL_HYSTSEL_MASK, _ACMP_CTRL_HYSTSEL_SHIFT, _ACMP_CTRL_IFALL_SHIFT, _ACMP_CTRL_INACTVAL_SHIFT, _ACMP_CTRL_IRISE_SHIFT, _ACMP_CTRL_WARMTIME_MASK, _ACMP_CTRL_WARMTIME_SHIFT, _ACMP_INPUTSEL_LPREF_MASK, _ACMP_INPUTSEL_LPREF_SHIFT, _ACMP_INPUTSEL_VDDLEVEL_MASK, _ACMP_INPUTSEL_VDDLEVEL_SHIFT, ACMP_Init_TypeDef::biasProg, BUS_RegBitWrite(), ACMP_TypeDef::CTRL, ACMP_Init_TypeDef::enable, ACMP_Init_TypeDef::fullBias, ACMP_Init_TypeDef::halfBias, ACMP_Init_TypeDef::hysteresisLevel, ACMP_Init_TypeDef::inactiveValue, ACMP_TypeDef::INPUTSEL, ACMP_Init_TypeDef::interruptOnFallingEdge, ACMP_Init_TypeDef::interruptOnRisingEdge, ACMP_Init_TypeDef::lowPowerReferenceEnabled, ACMP_Init_TypeDef::vddLevel, and ACMP_Init_TypeDef::warmTime.
__STATIC_INLINE void ACMP_IntClear | ( | ACMP_TypeDef * | acmp, |
uint32_t | flags | ||
) |
Clear one or more pending ACMP interrupts.
[in] | acmp | Pointer to 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 881 of file em_acmp.h.
References ACMP_TypeDef::IFC.
__STATIC_INLINE void ACMP_IntDisable | ( | ACMP_TypeDef * | acmp, |
uint32_t | flags | ||
) |
Disable one or more ACMP interrupts.
[in] | acmp | Pointer to 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 899 of file em_acmp.h.
References ACMP_TypeDef::IEN.
__STATIC_INLINE void ACMP_IntEnable | ( | ACMP_TypeDef * | acmp, |
uint32_t | flags | ||
) |
Enable one or more ACMP interrupts.
[in] | acmp | Pointer to 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 922 of file em_acmp.h.
References ACMP_TypeDef::IEN.
__STATIC_INLINE uint32_t ACMP_IntGet | ( | ACMP_TypeDef * | acmp | ) |
Get pending ACMP interrupt flags.
[in] | acmp | Pointer to ACMP peripheral register block. |
Definition at line 943 of file em_acmp.h.
References ACMP_TypeDef::IF.
__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.
[in] | acmp | Pointer to ACMP peripheral register block. |
Definition at line 968 of file em_acmp.h.
References ACMP_TypeDef::IEN, and ACMP_TypeDef::IF.
__STATIC_INLINE void ACMP_IntSet | ( | ACMP_TypeDef * | acmp, |
uint32_t | flags | ||
) |
Set one or more pending ACMP interrupts from SW.
[in] | acmp | Pointer to ACMP peripheral register block. |
[in] | flags | ACMP interrupt sources to set to 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 993 of file em_acmp.h.
References ACMP_TypeDef::IFS.
void ACMP_Reset | ( | ACMP_TypeDef * | acmp | ) |
Reset ACMP to same state as after a HW reset.
[in] | acmp | Pointer to the ACMP peripheral register block. |
Definition at line 270 of file em_acmp.c.
References _ACMP_CTRL_RESETVALUE, _ACMP_IEN_RESETVALUE, _ACMP_IF_MASK, _ACMP_INPUTSEL_RESETVALUE, ACMP_TypeDef::CTRL, ACMP_TypeDef::IEN, ACMP_TypeDef::IFC, and ACMP_TypeDef::INPUTSEL.