The MCUXpresso SDK provides a peripheral driver for the Low Power Analog Comparator (LPCMP) module of Kinetis devices.
The LPCMP driver is a basic comparator with advanced features. The APIs for the basic comparator enable the LPCMP to compare the two voltages of the two input channels and create the output of the comparator result. The APIs for advanced features can be used as the plug-in functions based on the basic comparator. They can process the comparator's output with hardware support.
Typical use case
Polling Configuration
Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/lpcmp
Interrupt Configuration
Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/lpcmp
|
void | LPCMP_Init (LPCMP_Type *base, const lpcmp_config_t *config) |
| Initialize the LPCMP. More...
|
|
void | LPCMP_Deinit (LPCMP_Type *base) |
| De-initializes the LPCMP module. More...
|
|
void | LPCMP_GetDefaultConfig (lpcmp_config_t *config) |
| Gets an available pre-defined settings for the comparator's configuration. More...
|
|
static void | LPCMP_Enable (LPCMP_Type *base, bool enable) |
| Enable/Disable LPCMP module. More...
|
|
void | LPCMP_SetInputChannels (LPCMP_Type *base, uint32_t positiveChannel, uint32_t negativeChannel) |
| Select the input channels for LPCMP. More...
|
|
static void | LPCMP_EnableDMA (LPCMP_Type *base, bool enable) |
| Enables/disables the DMA request for rising/falling events. More...
|
|
static void | LPCMP_EnableWindowMode (LPCMP_Type *base, bool enable) |
| Enable/Disable window mode.When any windowed mode is active, COUTA is clocked by the bus clock whenever WINDOW = 1. More...
|
|
void | LPCMP_SetFilterConfig (LPCMP_Type *base, const lpcmp_filter_config_t *config) |
| Configures the filter. More...
|
|
void | LPCMP_SetDACConfig (LPCMP_Type *base, const lpcmp_dac_config_t *config) |
| Configure the internal DAC module. More...
|
|
static void | LPCMP_EnableInterrupts (LPCMP_Type *base, uint32_t mask) |
| Enable the interrupts. More...
|
|
static void | LPCMP_DisableInterrupts (LPCMP_Type *base, uint32_t mask) |
| Disable the interrupts. More...
|
|
static uint32_t | LPCMP_GetStatusFlags (LPCMP_Type *base) |
| Get the LPCMP status flags. More...
|
|
static void | LPCMP_ClearStatusFlags (LPCMP_Type *base, uint32_t mask) |
| Clear the LPCMP status flags. More...
|
|
struct lpcmp_filter_config_t |
bool lpcmp_filter_config_t::enableSample |
uint8_t lpcmp_filter_config_t::filterSampleCount |
Available range is 1-7; 0 disables the filter.
uint8_t lpcmp_filter_config_t::filterSamplePeriod |
The divider to the bus clock. Available range is 0-255. The sampling clock must be at least 4 times slower than the system clock to the comparator. So if enableSample is "false", filterSamplePeriod should be set greater than 4.
struct lpcmp_dac_config_t |
bool lpcmp_dac_config_t::enableLowPowerMode |
uint8_t lpcmp_dac_config_t::DACValue |
bool lpcmp_config_t::enableStopMode |
bool lpcmp_config_t::enableOutputPin |
bool lpcmp_config_t::useUnfilteredOutput |
bool lpcmp_config_t::enableInvertOutput |
Enumerator |
---|
kLPCMP_OutputRisingEventFlag |
Rising-edge on the comparison output has occurred.
|
kLPCMP_OutputFallingEventFlag |
Falling-edge on the comparison output has occurred.
|
kLPCMP_OutputAssertEventFlag |
Return the current value of the analog comparator output.
The flag does not support W1C.
|
Enumerator |
---|
kLPCMP_OutputRisingInterruptEnable |
Comparator interrupt enable rising.
|
kLPCMP_OutputFallingInterruptEnable |
Comparator interrupt enable falling.
|
See chip data sheet to get the actual hystersis value with each level
Enumerator |
---|
kLPCMP_HysteresisLevel0 |
The hard block output has level 0 hysteresis internally.
|
kLPCMP_HysteresisLevel1 |
The hard block output has level 1 hysteresis internally.
|
kLPCMP_HysteresisLevel2 |
The hard block output has level 2 hysteresis internally.
|
kLPCMP_HysteresisLevel3 |
The hard block output has level 3 hysteresis internally.
|
Enumerator |
---|
kLPCMP_LowSpeedPowerMode |
Low speed comparison mode is selected.
|
kLPCMP_HighSpeedPowerMode |
High speed comparison mode is selected.
|
kLPCMP_NanoPowerMode |
Nano power comparator is enabled.
|
Enumerator |
---|
kLPCMP_VrefSourceVin1 |
vrefh_int is selected as resistor ladder network supply reference Vin.
|
kLPCMP_VrefSourceVin2 |
vrefh_ext is selected as resistor ladder network supply reference Vin.
|
This function initializes the LPCMP module. The operations included are:
- Enabling the clock for LPCMP module.
- Configuring the comparator.
- Enabling the LPCMP module. Note: For some devices, multiple LPCMP instance share the same clock gate. In this case, to enable the clock for any instance enables all the LPCMPs. Check the chip reference manual for the clock assignment of the LPCMP.
- Parameters
-
base | LPCMP peripheral base address. |
config | Pointer to "lpcmp_config_t" structure. |
void LPCMP_Deinit |
( |
LPCMP_Type * |
base | ) |
|
This function de-initializes the LPCMP module. The operations included are:
- Disabling the LPCMP module.
- Disabling the clock for LPCMP module.
This function disables the clock for the LPCMP. Note: For some devices, multiple LPCMP instance shares the same clock gate. In this case, before disabling the clock for the LPCMP, ensure that all the LPCMP instances are not used.
- Parameters
-
base | LPCMP peripheral base address. |
This function initializes the comparator configuration structure to these default values:
* config->enableStopMode = false;
* config->enableOutputPin = false;
* config->useUnfilteredOutput = false;
* config->enableInvertOutput = false;
*
- Parameters
-
config | Pointer to "lpcmp_config_t" structure. |
static void LPCMP_Enable |
( |
LPCMP_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | LPCMP peripheral base address. |
enable | "true" means enable the module, and "false" means disable the module. |
void LPCMP_SetInputChannels |
( |
LPCMP_Type * |
base, |
|
|
uint32_t |
positiveChannel, |
|
|
uint32_t |
negativeChannel |
|
) |
| |
This function determines which input is selected for the negative and positive mux.
- Parameters
-
base | LPCMP peripheral base address. |
positiveChannel | Positive side input channel number. Available range is 0-7. |
negativeChannel | Negative side input channel number. Available range is 0-7. |
static void LPCMP_EnableDMA |
( |
LPCMP_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
Normally, the LPCMP generates a CPU interrupt if there is a rising/falling event. When
DMA support is enabled and the rising/falling interrupt is enabled , the rising/falling
event forces a DMA transfer request rather than a CPU interrupt instead.
- Parameters
-
base | LPCMP peripheral base address. |
enable | "true" means enable DMA support, and "false" means disable DMA support. |
static void LPCMP_EnableWindowMode |
( |
LPCMP_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
The last latched value is held when WINDOW = 0. The optionally inverted comparator output COUT_RAW is sampled on every bus clock when WINDOW=1 to generate COUTA.
- Parameters
-
base | LPCMP peripheral base address. |
enable | "true" means enable window mode, and "false" means disable window mode. |
- Parameters
-
base | LPCMP peripheral base address. |
config | Pointer to "lpcmp_filter_config_t" structure. |
- Parameters
-
base | LPCMP peripheral base address. |
config | Pointer to "lpcmp_dac_config_t" structure. If config is "NULL", disable internal DAC. |
static void LPCMP_EnableInterrupts |
( |
LPCMP_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | LPCMP peripheral base address. |
mask | Mask value for interrupts. See "_lpcmp_interrupt_enable". |
static void LPCMP_DisableInterrupts |
( |
LPCMP_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | LPCMP peripheral base address. |
mask | Mask value for interrupts. See "_lpcmp_interrupt_enable". |
static uint32_t LPCMP_GetStatusFlags |
( |
LPCMP_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | LPCMP peripheral base address. |
- Returns
- Mask value for the asserted flags. See "_lpcmp_status_flags".
static void LPCMP_ClearStatusFlags |
( |
LPCMP_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | LPCMP peripheral base address. |
mask | Mask value for the flags. See "_lpcmp_status_flags". |