MCUXpresso SDK API Reference Manual  Rev 2.15.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
 Configure the filter. More...
 
struct  _lpcmp_dac_config
 configure the internal DAC. More...
 
struct  _lpcmp_config
 Configures the comparator. More...
 

Typedefs

typedef enum _lpcmp_hysteresis_mode lpcmp_hysteresis_mode_t
 LPCMP hysteresis mode. More...
 
typedef enum _lpcmp_power_mode lpcmp_power_mode_t
 LPCMP nano mode.
 
typedef enum
_lpcmp_dac_reference_voltage_source 
lpcmp_dac_reference_voltage_source_t
 Internal DAC reference voltage source.
 
typedef struct _lpcmp_filter_config lpcmp_filter_config_t
 Configure the filter.
 
typedef struct _lpcmp_dac_config lpcmp_dac_config_t
 configure the internal DAC.
 
typedef struct _lpcmp_config lpcmp_config_t
 Configures the comparator.
 

Enumerations

enum  _lpcmp_status_flags {
  kLPCMP_OutputRisingEventFlag = LPCMP_CSR_CFR_MASK,
  kLPCMP_OutputFallingEventFlag = LPCMP_CSR_CFF_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
}
 LPCMP interrupt enable/disable mask. More...
 
enum  _lpcmp_hysteresis_mode {
  kLPCMP_HysteresisLevel0 = 0U,
  kLPCMP_HysteresisLevel1 = 1U,
  kLPCMP_HysteresisLevel2 = 2U,
  kLPCMP_HysteresisLevel3 = 3U
}
 LPCMP hysteresis mode. More...
 
enum  _lpcmp_power_mode {
  kLPCMP_LowSpeedPowerMode = 0U,
  kLPCMP_HighSpeedPowerMode = 1U,
  kLPCMP_NanoPowerMode = 2U
}
 LPCMP nano mode. More...
 
enum  _lpcmp_dac_reference_voltage_source {
  kLPCMP_VrefSourceVin1 = 0U,
  kLPCMP_VrefSourceVin2 = 1U
}
 Internal DAC reference voltage source. More...
 

Driver version

#define FSL_LPCMP_DRIVER_VERSION   (MAKE_VERSION(2, 1, 1))
 LPCMP driver version 2.1.1. 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...
 

Data Structure Documentation

struct _lpcmp_filter_config

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::enableSample
uint8_t _lpcmp_filter_config::filterSampleCount

Available range is 1-7; 0 disables the filter.

uint8_t _lpcmp_filter_config::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

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::enableLowPowerMode
lpcmp_dac_reference_voltage_source_t _lpcmp_dac_config::referenceVoltageSource
uint8_t _lpcmp_dac_config::DACValue

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

struct _lpcmp_config

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

Field Documentation

bool _lpcmp_config::enableStopMode
bool _lpcmp_config::enableOutputPin
bool _lpcmp_config::useUnfilteredOutput
bool _lpcmp_config::enableInvertOutput
lpcmp_hysteresis_mode_t _lpcmp_config::hysteresisMode
lpcmp_power_mode_t _lpcmp_config::powerMode

Macro Definition Documentation

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

Typedef Documentation

See chip data sheet to get the actual hystersis value with each level

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

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.