The MCUXpresso SDK provides a peripheral driver for the Comparator (ACMP) module of MCUXpresso SDK devices.
The ACMP driver is created to help the user operate the ACMP module better. This driver can be considered as a basic comparator with advanced features. The APIs for basic comparator can make the CMP work as a general comparator, which compares the two input channel's voltage and creates the output of the comparator result immediately. The APIs for advanced feature can be used as the plug-in function based on the basic comparator, and can provide more ways to process the comparator's output.
Typical use case
Normal Configuration
Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/acmp
Interrupt Configuration
Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/acmp
Round robin Configuration
Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/acmp
|
#define | CMP_C0_CFx_MASK (CMP_C0_CFR_MASK | CMP_C0_CFF_MASK) |
| The mask of status flags cleared by writing 1. More...
|
|
bool acmp_config_t::enableHighSpeed |
bool acmp_config_t::enableInvertOutput |
bool acmp_config_t::useUnfilteredOutput |
bool acmp_config_t::enablePinOut |
struct acmp_channel_config_t |
The comparator's port can be input from channel mux or DAC. If port input is from channel mux, detailed channel number for the mux should be configured.
uint32_t acmp_channel_config_t::plusMuxInput |
uint32_t acmp_channel_config_t::minusMuxInput |
struct acmp_filter_config_t |
bool acmp_filter_config_t::enableSample |
uint32_t acmp_filter_config_t::filterCount |
Available range is 1-7, 0 would cause the filter disabled.
uint32_t acmp_filter_config_t::filterPeriod |
The divider to bus clock. Available range is 0-255.
uint32_t acmp_dac_config_t::DACValue |
struct acmp_round_robin_config_t |
uint32_t acmp_round_robin_config_t::fixedChannelNumber |
uint32_t acmp_round_robin_config_t::checkerChannelMask |
Available range is channel0:0x01 to channel7:0x80 for round-robin checker.
uint32_t acmp_round_robin_config_t::sampleClockCount |
uint32_t acmp_round_robin_config_t::delayModulus |
#define CMP_C0_CFx_MASK (CMP_C0_CFR_MASK | CMP_C0_CFF_MASK) |
Enumerator |
---|
kACMP_OutputRisingInterruptEnable |
Enable the interrupt when comparator outputs rising.
|
kACMP_OutputFallingInterruptEnable |
Enable the interrupt when comparator outputs falling.
|
kACMP_RoundRobinInterruptEnable |
Enable the Round-Robin interrupt.
|
Enumerator |
---|
kACMP_OutputRisingEventFlag |
Rising-edge on compare output has occurred.
|
kACMP_OutputFallingEventFlag |
Falling-edge on compare output has occurred.
|
kACMP_OutputAssertEventFlag |
Return the current value of the analog comparator output.
|
See chip data sheet to get the actual hysteresis value with each level.
Enumerator |
---|
kACMP_HysteresisLevel0 |
Offset is level 0 and Hysteresis is level 0.
|
kACMP_HysteresisLevel1 |
Offset is level 0 and Hysteresis is level 1.
|
kACMP_HysteresisLevel2 |
Offset is level 0 and Hysteresis is level 2.
|
kACMP_HysteresisLevel3 |
Offset is level 0 and Hysteresis is level 3.
|
Enumerator |
---|
kACMP_VrefSourceVin1 |
Vin1 is selected as resistor ladder network supply reference Vin.
|
kACMP_VrefSourceVin2 |
Vin2 is selected as resistor ladder network supply reference Vin.
|
Enumerator |
---|
kACMP_FixedPlusPort |
Only the inputs to the Minus port are swept in each round.
|
kACMP_FixedMinusPort |
Only the inputs to the Plus port are swept in each round.
|
The default configuration can be got by calling ACMP_GetDefaultConfig().
- Parameters
-
base | ACMP peripheral base address. |
config | Pointer to ACMP configuration structure. |
void ACMP_Deinit |
( |
CMP_Type * |
base | ) |
|
- Parameters
-
base | ACMP peripheral base address. |
This function initializes the user configuration structure to default value. The default value are:
Example:
config->enableHighSpeed = false;
config->enableInvertOutput = false;
config->useUnfilteredOutput = false;
config->enablePinOut = false;
config->enableHysteresisBothDirections = false;
config->hysteresisMode = kACMP_hysteresisMode0;
- Parameters
-
config | Pointer to ACMP configuration structure. |
void ACMP_Enable |
( |
CMP_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
- Parameters
-
base | ACMP peripheral base address. |
enable | True to enable the ACMP. |
Note that the plus/minus mux's setting is only valid when the positive/negative port's input isn't from DAC but from channel mux.
Example:
configStruct.positivePortInput = kACMP_PortInputFromDAC;
configStruct.negativePortInput = kACMP_PortInputFromMux;
- Parameters
-
base | ACMP peripheral base address. |
config | Pointer to channel configuration structure. |
void ACMP_EnableDMA |
( |
CMP_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
- Parameters
-
base | ACMP peripheral base address. |
enable | True to enable DMA. |
void ACMP_EnableWindowMode |
( |
CMP_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
- Parameters
-
base | ACMP peripheral base address. |
enable | True to enable window mode. |
The filter can be enabled when the filter count is bigger than 1, the filter period is greater than 0 and the sample clock is from divided bus clock or the filter is bigger than 1 and the sample clock is from external clock. Detailed usage can be got from the reference manual.
Example:
- Parameters
-
base | ACMP peripheral base address. |
config | Pointer to filter configuration structure. |
Example:
configStruct.enableOutput = false;
configStruct.workMode = kACMP_DACWorkLowSpeedMode;
- Parameters
-
base | ACMP peripheral base address. |
config | Pointer to DAC configuration structure. "NULL" is for disabling the feature. |
Example:
- Parameters
-
base | ACMP peripheral base address. |
config | Pointer to round robin mode configuration structure. "NULL" is for disabling the feature. |
void ACMP_SetRoundRobinPreState |
( |
CMP_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
Note: The pre-state has different circuit with get-round-robin-result in the SOC even though they are same bits. So get-round-robin-result can't return the same value as the value are set by pre-state.
- Parameters
-
base | ACMP peripheral base address. |
mask | Mask of round robin channel index. Available range is channel0:0x01 to channel7:0x80. |
static uint32_t ACMP_GetRoundRobinStatusFlags |
( |
CMP_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | ACMP peripheral base address. |
- Returns
- Mask of channel input changed asserted flags. Available range is channel0:0x01 to channel7:0x80.
void ACMP_ClearRoundRobinStatusFlags |
( |
CMP_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
- Parameters
-
base | ACMP peripheral base address. |
mask | Mask of channel index. Available range is channel0:0x01 to channel7:0x80. |
static uint32_t ACMP_GetRoundRobinResult |
( |
CMP_Type * |
base | ) |
|
|
inlinestatic |
Note that the set-pre-state has different circuit with get-round-robin-result in the SOC even though they are same bits. So ACMP_GetRoundRobinResult() can't return the same value as the value are set by ACMP_SetRoundRobinPreState.
- Parameters
-
base | ACMP peripheral base address. |
- Returns
- Mask of round robin channel result. Available range is channel0:0x01 to channel7:0x80.
void ACMP_EnableInterrupts |
( |
CMP_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
- Parameters
-
base | ACMP peripheral base address. |
mask | Interrupts mask. See "_acmp_interrupt_enable". |
void ACMP_DisableInterrupts |
( |
CMP_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
- Parameters
-
base | ACMP peripheral base address. |
mask | Interrupts mask. See "_acmp_interrupt_enable". |
uint32_t ACMP_GetStatusFlags |
( |
CMP_Type * |
base | ) |
|
- Parameters
-
base | ACMP peripheral base address. |
- Returns
- Status flags asserted mask. See "_acmp_status_flags".
void ACMP_ClearStatusFlags |
( |
CMP_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
- Parameters
-
base | ACMP peripheral base address. |
mask | Status flags mask. See "_acmp_status_flags". |