The MCUXpresso SDK provides a peripheral driver for the Analog Comparator (CMP) module of MCUXpresso SDK devices.
The CMP driver is a basic comparator with advanced features. The APIs for the basic comparator enable the CMP 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
int main(void)
{
CMP_Configure(DEMO_CMP_INSTANCE, &mCmpConfigStruct);
while (1)
{
{
}
else
{
}
}
}
Interrupt Configuration
volatile uint32_t g_CmpFlags = 0U;
void DEMO_CMP_IRQ_HANDLER_FUNC(void)
{
{
}
{
}
}
int main(void)
{
EnableIRQ(DEMO_CMP_IRQ_ID);
CMP_Configure(DEMO_CMP_INSTANCE, &mCmpConfigStruct);
while (1)
{
}
}
bool cmp_config_t::enableCmp |
bool cmp_config_t::enableHighSpeed |
bool cmp_config_t::enableInvertOutput |
bool cmp_config_t::useUnfilteredOutput |
bool cmp_config_t::enablePinOut |
bool cmp_config_t::enableTriggerMode |
struct cmp_filter_config_t |
uint8_t cmp_filter_config_t::filterCount |
Available range is 1-7; 0 disables the filter.
uint8_t cmp_filter_config_t::filterPeriod |
The divider to the bus clock. Available range is 0-255.
uint8_t cmp_dac_config_t::DACValue |
Enumerator |
---|
kCMP_OutputRisingInterruptEnable |
Comparator interrupt enable rising.
|
kCMP_OutputFallingInterruptEnable |
Comparator interrupt enable falling.
|
Enumerator |
---|
kCMP_OutputRisingEventFlag |
Rising-edge on the comparison output has occurred.
|
kCMP_OutputFallingEventFlag |
Falling-edge on the comparison output has occurred.
|
kCMP_OutputAssertEventFlag |
Return the current value of the analog comparator output.
|
Enumerator |
---|
kCMP_HysteresisLevel0 |
Hysteresis level 0.
|
kCMP_HysteresisLevel1 |
Hysteresis level 1.
|
kCMP_HysteresisLevel2 |
Hysteresis level 2.
|
kCMP_HysteresisLevel3 |
Hysteresis level 3.
|
Enumerator |
---|
kCMP_VrefSourceVin1 |
Vin1 is selected as a resistor ladder network supply reference Vin.
|
kCMP_VrefSourceVin2 |
Vin2 is selected as a resistor ladder network supply reference Vin.
|
void CMP_Init |
( |
CMP_Type * |
base, |
|
|
const cmp_config_t * |
config |
|
) |
| |
This function initializes the CMP module. The operations included are as follows.
- Enabling the clock for CMP module.
- Configuring the comparator.
- Enabling the CMP module. Note that for some devices, multiple CMP instances share the same clock gate. In this case, to enable the clock for any instance enables all CMPs. See the appropriate MCU reference manual for the clock assignment of the CMP.
- Parameters
-
base | CMP peripheral base address. |
config | Pointer to the configuration structure. |
void CMP_Deinit |
( |
CMP_Type * |
base | ) |
|
This function de-initializes the CMP module. The operations included are as follows.
- Disabling the CMP module.
- Disabling the clock for CMP module.
This function disables the clock for the CMP. Note that for some devices, multiple CMP instances share the same clock gate. In this case, before disabling the clock for the CMP, ensure that all the CMP instances are not used.
- Parameters
-
base | CMP peripheral base address. |
static void CMP_Enable |
( |
CMP_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | CMP peripheral base address. |
enable | Enables or disables the module. |
This function initializes the user configuration structure to these default values.
* config->enableCmp = true;
* config->enableHighSpeed = false;
* config->enableInvertOutput = false;
* config->useUnfilteredOutput = false;
* config->enablePinOut = false;
* config->enableTriggerMode = false;
*
- Parameters
-
config | Pointer to the configuration structure. |
void CMP_SetInputChannels |
( |
CMP_Type * |
base, |
|
|
uint8_t |
positiveChannel, |
|
|
uint8_t |
negativeChannel |
|
) |
| |
This function sets the input channels for the comparator. Note that two input channels cannot be set the same way in the application. When the user selects the same input from the analog mux to the positive and negative port, the comparator is disabled automatically.
- Parameters
-
base | CMP 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. |
- Parameters
-
base | CMP peripheral base address. |
config | Pointer to the configuration structure. |
- Parameters
-
base | CMP peripheral base address. |
config | Pointer to the configuration structure. "NULL" disables the feature. |
void CMP_EnableInterrupts |
( |
CMP_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
- Parameters
-
base | CMP peripheral base address. |
mask | Mask value for interrupts. See "_cmp_interrupt_enable". |
void CMP_DisableInterrupts |
( |
CMP_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
- Parameters
-
base | CMP peripheral base address. |
mask | Mask value for interrupts. See "_cmp_interrupt_enable". |
uint32_t CMP_GetStatusFlags |
( |
CMP_Type * |
base | ) |
|
- Parameters
-
base | CMP peripheral base address. |
- Returns
- Mask value for the asserted flags. See "_cmp_status_flags".
void CMP_ClearStatusFlags |
( |
CMP_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
- Parameters
-
base | CMP peripheral base address. |
mask | Mask value for the flags. See "_cmp_status_flags". |