MCUXpresso SDK API Reference Manual  Rev 2.16.000
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
LPCMP: Low Power Analog Comparator Driver

Overview

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.

Data Structures

struct  lpcmp_filter_config_t
 Configure the filter. More...
 
struct  lpcmp_dac_config_t
 configure the internal DAC. More...
 
struct  lpcmp_config_t
 Configures the comparator. More...
 
struct  lpcmp_window_control_config_t
 Configure the window mode control. More...
 
struct  lpcmp_roundrobin_config_t
 Configure the round robin mode. More...
 

Enumerations

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...
 

Driver version

#define FSL_LPCMP_DRIVER_VERSION   (MAKE_VERSION(2, 1, 3))
 LPCMP driver version 2.1.3. More...
 

Initialization and configuration

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...
 

Window mode

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...
 

RoundRobin mode

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...
 

Data Structure Documentation

struct lpcmp_filter_config_t

Data Fields

bool enableSample
 Decide whether to use the external SAMPLE as a sampling clock input. More...
 
uint8_t filterSampleCount
 Filter Sample Count. More...
 
uint8_t filterSamplePeriod
 Filter Sample Period. More...
 

Field Documentation

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

Data Fields

bool enableLowPowerMode
 Decide whether to enable DAC low power mode. More...
 
lpcmp_dac_reference_voltage_source_t referenceVoltageSource
 Internal DAC supply voltage reference source. More...
 
uint8_t DACValue
 Value for the DAC Output Voltage. More...
 

Field Documentation

bool lpcmp_dac_config_t::enableLowPowerMode
lpcmp_dac_reference_voltage_source_t lpcmp_dac_config_t::referenceVoltageSource
uint8_t lpcmp_dac_config_t::DACValue

Different devices has different available range, for specific values, please refer to the reference manual.

struct lpcmp_config_t

Data Fields

bool enableStopMode
 Decide whether to enable the comparator when in STOP modes. More...
 
bool enableOutputPin
 Decide whether to enable the comparator is available in selected pin. More...
 
bool useUnfilteredOutput
 Decide whether to use unfiltered output. More...
 
bool enableInvertOutput
 Decide whether to inverts the comparator output. More...
 
lpcmp_hysteresis_mode_t hysteresisMode
 LPCMP hysteresis mode. More...
 
lpcmp_power_mode_t powerMode
 LPCMP power mode. More...
 
lpcmp_functional_source_clock_t functionalSourceClock
 Select LPCMP functional mode clock source. More...
 

Field Documentation

bool lpcmp_config_t::enableStopMode
bool lpcmp_config_t::enableOutputPin
bool lpcmp_config_t::useUnfilteredOutput
bool lpcmp_config_t::enableInvertOutput
lpcmp_hysteresis_mode_t lpcmp_config_t::hysteresisMode
lpcmp_power_mode_t lpcmp_config_t::powerMode
lpcmp_functional_source_clock_t lpcmp_config_t::functionalSourceClock
struct lpcmp_window_control_config_t

Data Fields

bool enableInvertWindowSignal
 True: enable invert window signal, False: disable invert window signal. More...
 
lpcmp_couta_signal_t COUTASignal
 Decide whether to define the COUTA signal value when the window is closed. More...
 
lpcmp_close_window_event_t closeWindowEvent
 Decide whether to select COUT event signal edge defines a COUT event to close window. More...
 

Field Documentation

bool lpcmp_window_control_config_t::enableInvertWindowSignal
lpcmp_couta_signal_t lpcmp_window_control_config_t::COUTASignal
lpcmp_close_window_event_t lpcmp_window_control_config_t::closeWindowEvent
struct lpcmp_roundrobin_config_t

Data Fields

uint8_t initDelayModules
 Comparator and DAC initialization delay modulus, See Reference Manual and DataSheet for specific value. More...
 
uint8_t sampleClockNumbers
 Specify the number of the round robin clock cycles(0~3) to wait after scanning the active channel before sampling the channel's comparison result. More...
 
uint8_t channelSampleNumbers
 Specify the number of samples for one channel, note that channelSampleNumbers must not smaller than sampleTimeThreshhold. More...
 
uint8_t sampleTimeThreshhold
 Specify that for one channel, when (sampleTimeThreshhold + 1) sample results are "1",the final result is "1", otherwise the final result is "0", note that the sampleTimeThreshhold must not be larger than channelSampleNumbers. More...
 
lpcmp_roundrobin_clock_source_t roundrobinClockSource
 
        Decide which clock source to

choose in round robin mode. More...

 
lpcmp_roundrobin_trigger_source_t roundrobinTriggerSource
 
        Decide which trigger source to

choose in round robin mode. More...

 
lpcmp_roundrobin_fixedmuxport_t fixedMuxPort
 
        Decide which mux port to choose as

fixed channel in round robin mode. More...

 
uint8_t fixedChannel
 Indicate which channel of the fixed mux port is used in round robin mode. More...
 
uint8_t checkerChannelMask
 Indicate which channel of the non-fixed mux port to check its voltage value in round robin mode, for example, if checkerChannelMask set to 0x11U means select channel 0 and channel 4 as checker channel. More...
 

Field Documentation

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
lpcmp_roundrobin_clock_source_t lpcmp_roundrobin_config_t::roundrobinClockSource
lpcmp_roundrobin_trigger_source_t lpcmp_roundrobin_config_t::roundrobinTriggerSource
lpcmp_roundrobin_fixedmuxport_t lpcmp_roundrobin_config_t::fixedMuxPort
uint8_t lpcmp_roundrobin_config_t::fixedChannel
uint8_t lpcmp_roundrobin_config_t::checkerChannelMask

Macro Definition Documentation

#define FSL_LPCMP_DRIVER_VERSION   (MAKE_VERSION(2, 1, 3))

Enumeration Type Documentation

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.

Function Documentation

void LPCMP_Init ( LPCMP_Type *  base,
const lpcmp_config_t config 
)

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
baseLPCMP peripheral base address.
configPointer 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
baseLPCMP peripheral base address.
void LPCMP_GetDefaultConfig ( lpcmp_config_t config)

This function initializes the comparator configuration structure to these default values:

* config->enableStopMode = false;
* config->enableOutputPin = false;
* config->useUnfilteredOutput = false;
* config->enableInvertOutput = false;
* config->hysteresisMode = kLPCMP_HysteresisLevel0;
* config->powerMode = kLPCMP_LowSpeedPowerMode;
* config->functionalSourceClock = kLPCMP_FunctionalClockSource0;
*
Parameters
configPointer to "lpcmp_config_t" structure.
static void LPCMP_Enable ( LPCMP_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseLPCMP 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
baseLPCMP peripheral base address.
positiveChannelPositive side input channel number. Available range is 0-7.
negativeChannelNegative 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
baseLPCMP peripheral base address.
enable"true" means enable DMA support, and "false" means disable DMA support.
void LPCMP_SetFilterConfig ( LPCMP_Type *  base,
const lpcmp_filter_config_t config 
)
Parameters
baseLPCMP peripheral base address.
configPointer to "lpcmp_filter_config_t" structure.
void LPCMP_SetDACConfig ( LPCMP_Type *  base,
const lpcmp_dac_config_t config 
)
Parameters
baseLPCMP peripheral base address.
configPointer 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
baseLPCMP peripheral base address.
maskMask value for interrupts. See "_lpcmp_interrupt_enable".
static void LPCMP_DisableInterrupts ( LPCMP_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseLPCMP peripheral base address.
maskMask value for interrupts. See "_lpcmp_interrupt_enable".
static uint32_t LPCMP_GetStatusFlags ( LPCMP_Type *  base)
inlinestatic
Parameters
baseLPCMP 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
baseLPCMP peripheral base address.
maskMask 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
baseLPCMP peripheral base address.
enable"true" means enable window mode, and "false" means disable window mode.
void LPCMP_SetWindowControl ( LPCMP_Type *  base,
const lpcmp_window_control_config_t config 
)
Parameters
baseLPCMP peripheral base address.
configPointer "lpcmp_window_control_config_t" structure.
void LPCMP_SetRoundRobinConfig ( LPCMP_Type *  base,
const lpcmp_roundrobin_config_t config 
)
Parameters
baseLPCMP peripheral base address.
configPointer "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
baseLPCMP 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
baseLPCMP 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
baseLPCMP peripheral base address.
maskMask of channel index.
static uint8_t LPCMP_GetComparisonResult ( LPCMP_Type *  base)
inlinestatic
Parameters
baseLPCMP peripheral base address.
Returns
return All channels' comparison result.
static void LPCMP_ClearInputChangedFlags ( LPCMP_Type *  base,
uint8_t  mask 
)
inlinestatic
Parameters
baseLPCMP peripheral base address.
maskMask of channel index.
static uint8_t LPCMP_GetInputChangedFlags ( LPCMP_Type *  base)
inlinestatic
Parameters
baseLPCMP peripheral base address.
Returns
return All channels' changed flag.