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
Initialization and configuration
Functions in this group are used to initialize and configure LPCMP module, LPCMP internal DAC, channel and filter block, etc.
Window mode
Functions in this group are used to enable/disable window and configure window control, etc.
RoundRobin mode
Functions in this group are used to configure roundrobin mode, set internal timer rate and preset value, etc.
|
enum | _lpcmp_status_flags {
kLPCMP_OutputRisingEventFlag = LPCMP_CSR_CFR_MASK,
kLPCMP_OutputFallingEventFlag = LPCMP_CSR_CFF_MASK,
kLPCMP_OutputRoundRobinEventFlag = LPCMP_CSR_RRF_MASK,
kLPCMP_OutputAssertEventFlag = LPCMP_CSR_COUT_MASK
} |
| LPCMP status falgs mask. More...
|
|
enum | _lpcmp_interrupt_enable {
kLPCMP_OutputRisingInterruptEnable = LPCMP_IER_CFR_IE_MASK,
kLPCMP_OutputFallingInterruptEnable = LPCMP_IER_CFF_IE_MASK,
kLPCMP_RoundRobinInterruptEnable = LPCMP_IER_RRF_IE_MASK
} |
| LPCMP interrupt enable/disable mask. More...
|
|
enum | lpcmp_hysteresis_mode_t {
kLPCMP_HysteresisLevel0 = 0U,
kLPCMP_HysteresisLevel1 = 1U,
kLPCMP_HysteresisLevel2 = 2U,
kLPCMP_HysteresisLevel3 = 3U
} |
| LPCMP hysteresis mode. More...
|
|
enum | lpcmp_power_mode_t {
kLPCMP_LowSpeedPowerMode = 0U,
kLPCMP_HighSpeedPowerMode = 1U,
kLPCMP_NanoPowerMode = 2U
} |
| LPCMP nano mode. More...
|
|
enum | lpcmp_dac_reference_voltage_source_t {
kLPCMP_VrefSourceVin1 = 0U,
kLPCMP_VrefSourceVin2 = 1U
} |
| Internal DAC reference voltage source. More...
|
|
enum | lpcmp_functional_source_clock_t {
kLPCMP_FunctionalClockSource0 = 0U,
kLPCMP_FunctionalClockSource1 = 1U,
kLPCMP_FunctionalClockSource2 = 2U,
kLPCMP_FunctionalClockSource3 = 3U
} |
| LPCMP functional mode clock source selection. More...
|
|
enum | lpcmp_couta_signal_t {
kLPCMP_COUTASignalNoSet = 0U,
kLPCMP_COUTASignalLow = 1U,
kLPCMP_COUTASignalHigh = 3U
} |
| Set the COUTA signal value when the window is closed. More...
|
|
enum | lpcmp_close_window_event_t {
kLPCMP_CLoseWindowEventNoSet = 0U,
kLPCMP_CloseWindowEventRisingEdge = 1U,
kLPCMP_CloseWindowEventFallingEdge = 3U,
kLPCMP_CLoseWindowEventBothEdge = 5U
} |
| Set COUT event, which can close the active window in window mode. More...
|
|
enum | lpcmp_roundrobin_fixedmuxport_t {
kLPCMP_FixedPlusMuxPort = 0U,
kLPCMP_FixedMinusMuxPort = 1U
} |
| LPCMP round robin mode fixed mux port. More...
|
|
enum | lpcmp_roundrobin_clock_source_t {
kLPCMP_RoundRobinClockSource0 = 0U,
kLPCMP_RoundRobinClockSource1 = 1U,
kLPCMP_RoundRobinClockSource2 = 2U,
kLPCMP_RoundRobinClockSource3 = 3U
} |
| LPCMP round robin mode clock source selection. More...
|
|
enum | lpcmp_roundrobin_trigger_source_t {
kLPCMP_TriggerSourceExternally = 0U,
kLPCMP_TriggerSourceInternally = 1U
} |
| LPCMP round robin mode trigger source. More...
|
|
|
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...
|
|
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...
|
|
|
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_SetWindowControl (LPCMP_Type *base, const lpcmp_window_control_config_t *config) |
| Configure the window control, users can use this API to implement operations on the window, such as inverting the window signal, setting the window closing event(only valid in windowing mode), and setting the COUTA signal after the window is closed(only valid in windowing mode). More...
|
|
|
void | LPCMP_SetRoundRobinConfig (LPCMP_Type *base, const lpcmp_roundrobin_config_t *config) |
| Configure the roundrobin mode. More...
|
|
void | LPCMP_SetRoundRobinInternalTimer (LPCMP_Type *base, uint32_t value) |
| brief Configure the roundrobin internal timer reload value. More...
|
|
static void | LPCMP_EnableRoundRobinMode (LPCMP_Type *base, bool enable) |
| Enable/Disable roundrobin mode. More...
|
|
static void | LPCMP_EnableRoundRobinInternalTimer (LPCMP_Type *base, bool enable) |
| Enable/Disable roundrobin internal timer, note that this function is only valid when using the internal trigger source. More...
|
|
static void | LPCMP_SetPreSetValue (LPCMP_Type *base, uint8_t mask) |
| Set preset value for all channels, users can set all channels' preset vaule through this API, for example, if the mask set to 0x03U means channel0 and channel2's preset value set to 1U and other channels' preset value set to 0U. More...
|
|
static uint8_t | LPCMP_GetComparisonResult (LPCMP_Type *base) |
| Get comparison results for all channels, users can get all channels' comparison results through this API. More...
|
|
static void | LPCMP_ClearInputChangedFlags (LPCMP_Type *base, uint8_t mask) |
| Clear input changed flags for single channel or multiple channels, users can clear input changed flag of a single channel or multiple channels through this API, for example, if the mask set to 0x03U means clear channel0 and channel2's input changed flags. More...
|
|
static uint8_t | LPCMP_GetInputChangedFlags (LPCMP_Type *base) |
| Get input changed flags for all channels, Users can get all channels' input changed flags through this API. 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 |
Different devices has different available range, for specific values, please refer to the reference manual.
bool lpcmp_config_t::enableStopMode |
bool lpcmp_config_t::enableOutputPin |
bool lpcmp_config_t::useUnfilteredOutput |
bool lpcmp_config_t::enableInvertOutput |
struct lpcmp_window_control_config_t |
bool lpcmp_window_control_config_t::enableInvertWindowSignal |
struct lpcmp_roundrobin_config_t |
uint8_t lpcmp_roundrobin_config_t::initDelayModules |
uint8_t lpcmp_roundrobin_config_t::sampleClockNumbers |
uint8_t lpcmp_roundrobin_config_t::channelSampleNumbers |
uint8_t lpcmp_roundrobin_config_t::sampleTimeThreshhold |
uint8_t lpcmp_roundrobin_config_t::fixedChannel |
uint8_t lpcmp_roundrobin_config_t::checkerChannelMask |
Enumerator |
---|
kLPCMP_OutputRisingEventFlag |
Rising-edge on the comparison output has occurred.
|
kLPCMP_OutputFallingEventFlag |
Falling-edge on the comparison output has occurred.
|
kLPCMP_OutputRoundRobinEventFlag |
Detects when any channel's last comparison result is different from the pre-set value in trigger mode.
|
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.
|
kLPCMP_RoundRobinInterruptEnable |
Comparator round robin mode interrupt occurred when the comparison result changes for a given channel.
|
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.
|
Note: In different devices, the functional mode clock source selection is different, please refer to specific device Reference Manual for details.
Enumerator |
---|
kLPCMP_FunctionalClockSource0 |
Select functional mode clock source0.
|
kLPCMP_FunctionalClockSource1 |
Select functional mode clock source1.
|
kLPCMP_FunctionalClockSource2 |
Select functional mode clock source2.
|
kLPCMP_FunctionalClockSource3 |
Select functional mode clock source3.
|
Enumerator |
---|
kLPCMP_COUTASignalNoSet |
NO set the COUTA signal value when the window is closed.
|
kLPCMP_COUTASignalLow |
Set COUTA signal low(0) when the window is closed.
|
kLPCMP_COUTASignalHigh |
Set COUTA signal high(1) when the window is closed.
|
Enumerator |
---|
kLPCMP_CLoseWindowEventNoSet |
No Set COUT event, which can close the active window in window mode.
|
kLPCMP_CloseWindowEventRisingEdge |
Set rising edge COUT signal as COUT event.
|
kLPCMP_CloseWindowEventFallingEdge |
Set falling edge COUT signal as COUT event.
|
kLPCMP_CLoseWindowEventBothEdge |
Set both rising and falling edge COUT signal as COUT event.
|
Enumerator |
---|
kLPCMP_FixedPlusMuxPort |
Fixed plus mux port.
|
kLPCMP_FixedMinusMuxPort |
Fixed minus mux port.
|
Note: In different devices,the round robin mode clock source selection is different, please refer to the specific device Reference Manual for details.
Enumerator |
---|
kLPCMP_RoundRobinClockSource0 |
Select roundrobin mode clock source0.
|
kLPCMP_RoundRobinClockSource1 |
Select roundrobin mode clock source1.
|
kLPCMP_RoundRobinClockSource2 |
Select roundrobin mode clock source2.
|
kLPCMP_RoundRobinClockSource3 |
Select roundrobin mode clock source3.
|
Enumerator |
---|
kLPCMP_TriggerSourceExternally |
Select external trigger source.
|
kLPCMP_TriggerSourceInternally |
Select internal trigger source.
|
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. |
- 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". |
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 "lpcmp_window_control_config_t" structure. |
- Parameters
-
base | LPCMP peripheral base address. |
config | Pointer "lpcmp_roundrobin_config_t" structure. |
void LPCMP_SetRoundRobinInternalTimer |
( |
LPCMP_Type * |
base, |
|
|
uint32_t |
value |
|
) |
| |
param base LPCMP peripheral base address. param value RoundRobin internal timer reload value, allowed range:0x0UL-0xFFFFFFFUL.
static void LPCMP_EnableRoundRobinMode |
( |
LPCMP_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | LPCMP peripheral base address. |
enable | "true" means enable roundrobin mode, and "false" means disable roundrobin mode. |
static void LPCMP_EnableRoundRobinInternalTimer |
( |
LPCMP_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | LPCMP peripheral base address. |
enable | "true" means enable roundrobin internal timer, and "false" means disable roundrobin internal timer. |
static void LPCMP_SetPreSetValue |
( |
LPCMP_Type * |
base, |
|
|
uint8_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | LPCMP peripheral base address. |
mask | Mask of channel index. |
static uint8_t LPCMP_GetComparisonResult |
( |
LPCMP_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | LPCMP peripheral base address. |
- Returns
- return All channels' comparison result.
static void LPCMP_ClearInputChangedFlags |
( |
LPCMP_Type * |
base, |
|
|
uint8_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | LPCMP peripheral base address. |
mask | Mask of channel index. |
static uint8_t LPCMP_GetInputChangedFlags |
( |
LPCMP_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | LPCMP peripheral base address. |
- Returns
- return All channels' changed flag.