The KSDK provides a peripheral driver for the Analog Comparator (CMP) module of Kinetis devices.
Overview
The CMP driver is a basic comparator with advanced features. The APIs for the basic comparator enable the CMP as a general comparator, which compares the two voltage of the two input channels and creates the output of the comparator result. The APIs for advanced features can be used as the plug-in function 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 |
struct cmp_filter_config_t |
uint8_t cmp_filter_config_t::filterCount |
Available range is 1-7, 0 would cause the filter disabled.
uint8_t cmp_filter_config_t::filterPeriod |
The divider to 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 compare output has occurred.
|
kCMP_OutputFallingEventFlag |
Falling-edge on compare 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 resistor ladder network supply reference Vin.
|
kCMP_VrefSourceVin2 |
Vin2 is selected as 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:
- Enabling the clock for CMP module.
- Configuring the comparator.
- Enabling the CMP module. Note: For some devices, multiple CMP instance share the same clock gate. In this case, to enable the clock for any instance enables all the CMPs. Check the chip reference manual for the clock assignment of the CMP.
- Parameters
-
base | CMP peripheral base address. |
config | Pointer to configuration structure. |
void CMP_Deinit |
( |
CMP_Type * |
base | ) |
|
This function de-initializes the CMP module. The operations included are:
- Disabling the CMP module.
- Disabling the clock for CMP module.
This function disables the clock for the CMP. Note: For some devices, multiple CMP instance shares 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 | Enable the module or not. |
This function initializes the user configure 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 as same 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 configuration structure. |
- Parameters
-
base | CMP peripheral base address. |
config | Pointer to configuration structure. "NULL" is for disabling 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". |