The MCUXpresso SDK provides a peripheral driver for the Analog Comparator (CMP) module of MCUXpresso SDK devices.
Function groups
The driver provides a set of functions to set two input sources of the on-chip comparator and compare the voltage of them.
Initialization and deinitialization
The function CMP_Init() initializes the CMP with specified configurations. The function CMP_GetDefaultConfig() gets the default configurations.
The function CMP_Deinit() disables the module clock.
Compare
The function CMP_SetInputChannels() configures the P-side and N-side input sources.
The function CMP_SetVREF() sets the reference voltage which can be dedicated to input 0 of both P and N sides.
The function CMP_GetOutput() gets the compare result of the two sides.
Interrupt
Provides functions to enable/disable/clear CMP interrupts.
The function CMP_EnableFilteredInterruptSource() allows users to select which analog comparator output (filtered or un-filtered) is used for interrupt detection.
Status
Provides functions to get the CMP status.
Typical use case
Polling Configuration
Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/cmp_1
Interrupt Configuration
Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/cmp_1
|
enum | _cmp_input_mux {
kCMP_InputVREF = 0U,
kCMP_Input1 = 1U,
kCMP_Input2 = 2U,
kCMP_Input3 = 3U,
kCMP_Input4 = 4U,
kCMP_Input5 = 5U
} |
| CMP input mux for positive and negative sides. More...
|
|
enum | _cmp_interrupt_type {
kCMP_EdgeDisable = 0U,
kCMP_EdgeRising = 2U,
kCMP_EdgeFalling = 4U,
kCMP_EdgeRisingFalling = 6U,
kCMP_LevelDisable = 1U,
kCMP_LevelHigh = 3U,
kCMP_LevelLow = 5U
} |
| CMP interrupt type. More...
|
|
enum | cmp_vref_source_t {
KCMP_VREFSourceVDDA = 1U,
KCMP_VREFSourceInternalVREF = 0U
} |
| CMP Voltage Reference source. More...
|
|
enum | cmp_filtercgf_samplemode_t {
kCMP_FilterSampleMode0 = 0U,
kCMP_FilterSampleMode1 = 1U,
kCMP_FilterSampleMode2 = 2U,
kCMP_FilterSampleMode3 = 3U
} |
| CMP Filter sample mode. More...
|
|
enum | cmp_filtercgf_clkdiv_t {
kCMP_FilterClockDivide1 = 0U,
kCMP_FilterClockDivide2 = 1U,
kCMP_FilterClockDivide4 = 2U,
kCMP_FilterClockDivide8 = 3U,
kCMP_FilterClockDivide16 = 4U,
kCMP_FilterClockDivide32 = 5U,
kCMP_FilterClockDivide64 = 6U
} |
| CMP Filter clock divider. More...
|
|
|
static void | CMP_SetInputChannels (uint8_t positiveChannel, uint8_t negativeChannel) |
|
void | CMP_SetVREF (const cmp_vref_config_t *config) |
| Configures the VREFINPUT. More...
|
|
static bool | CMP_GetOutput (void) |
| Get CMP compare output. More...
|
|
bool cmp_config_t::enableHysteresis |
bool cmp_config_t::enableLowPower |
Enumerator |
---|
kCMP_InputVREF |
Cmp input from VREF.
|
kCMP_Input1 |
Cmp input source 1.
|
kCMP_Input2 |
Cmp input source 2.
|
kCMP_Input3 |
Cmp input source 3.
|
kCMP_Input4 |
Cmp input source 4.
|
kCMP_Input5 |
Cmp input source 5.
|
Enumerator |
---|
kCMP_EdgeDisable |
Disable edge interupt.
|
kCMP_EdgeRising |
Interrupt on falling edge.
|
kCMP_EdgeFalling |
Interrupt on rising edge.
|
kCMP_EdgeRisingFalling |
Interrupt on both rising and falling edges.
|
kCMP_LevelDisable |
Disable level interupt.
|
kCMP_LevelHigh |
Interrupt on high level.
|
kCMP_LevelLow |
Interrupt on low level.
|
Enumerator |
---|
KCMP_VREFSourceVDDA |
Select VDDA as VREF.
|
KCMP_VREFSourceInternalVREF |
Select internal VREF as VREF.
|
Enumerator |
---|
kCMP_FilterSampleMode0 |
Bypass mode.
Filtering is disabled.
|
kCMP_FilterSampleMode1 |
Filter 1 clock period.
|
kCMP_FilterSampleMode2 |
Filter 2 clock period.
|
kCMP_FilterSampleMode3 |
Filter 3 clock period.
|
Enumerator |
---|
kCMP_FilterClockDivide1 |
Filter clock period duration equals 1 analog comparator clock period.
|
kCMP_FilterClockDivide2 |
Filter clock period duration equals 2 analog comparator clock period.
|
kCMP_FilterClockDivide4 |
Filter clock period duration equals 4 analog comparator clock period.
|
kCMP_FilterClockDivide8 |
Filter clock period duration equals 8 analog comparator clock period.
|
kCMP_FilterClockDivide16 |
Filter clock period duration equals 16 analog comparator clock period.
|
kCMP_FilterClockDivide32 |
Filter clock period duration equals 32 analog comparator clock period.
|
kCMP_FilterClockDivide64 |
Filter clock period duration equals 64 analog comparator clock period.
|
This function enables the CMP module and do necessary settings.
- Parameters
-
config | Pointer to the configuration structure. |
This function gates the clock for CMP module.
This function initializes the user configuration structure to these default values.
* config->enableHysteresis = true;
* config->enableLowPower = true;
*
- Parameters
-
config | Pointer to the configuration structure. |
void CMP_SetVREF |
( |
const cmp_vref_config_t * |
config | ) |
|
- Parameters
-
config | Pointer to the configuration structure. |
static bool CMP_GetOutput |
( |
void |
| ) |
|
|
inlinestatic |
- Returns
- The output result. true: voltage on positive side is greater than negative side. false: voltage on positive side is lower than negative side.
static void CMP_EnableInterrupt |
( |
uint32_t |
type | ) |
|
|
inlinestatic |
- Parameters
-
type | CMP interrupt type. See "_cmp_interrupt_type". |
static void CMP_EnableFilteredInterruptSource |
( |
bool |
enable | ) |
|
|
inlinestatic |
- Parameters
-
enable | false: Select Analog Comparator raw output (unfiltered) as input for interrupt detection. true: Select Analog Comparator filtered output as input for interrupt detection. |
- Note
- : When CMP is configured as the wakeup source in power down mode, this function must use the raw output as the interupt source, that is, call this function and set parameter enable to false.
static bool CMP_GetPreviousInterruptStatus |
( |
void |
| ) |
|
|
inlinestatic |
- Returns
- Interrupt status. true: interrupt pending, false: no interrupt pending.
static bool CMP_GetInterruptStatus |
( |
void |
| ) |
|
|
inlinestatic |
- Returns
- Interrupt status. true: interrupt pending, false: no interrupt pending.
This function allows the users to configure the sampling mode and clock divider of the CMP Filter.
- Parameters
-
filterSampleMode | CMP Select filter sample mode |
filterClockDivider | CMP Set fileter clock divider |