MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
ACMP: Analog Comparator Driver

Overview

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

Data Structures

struct  acmp_config_t
 Configuration for ACMP. More...
 
struct  acmp_channel_config_t
 Configuration for channel. More...
 
struct  acmp_filter_config_t
 Configuration for filter. More...
 
struct  acmp_dac_config_t
 Configuration for DAC. More...
 
struct  acmp_round_robin_config_t
 Configuration for round robin mode. More...
 

Macros

#define CMP_C0_CFx_MASK   (CMP_C0_CFR_MASK | CMP_C0_CFF_MASK)
 The mask of status flags cleared by writing 1. More...
 

Enumerations

enum  _acmp_interrupt_enable {
  kACMP_OutputRisingInterruptEnable = (1U << 0U),
  kACMP_OutputFallingInterruptEnable = (1U << 1U),
  kACMP_RoundRobinInterruptEnable = (1U << 2U)
}
 Interrupt enable/disable mask. More...
 
enum  _acmp_status_flags {
  kACMP_OutputRisingEventFlag = CMP_C0_CFR_MASK,
  kACMP_OutputFallingEventFlag = CMP_C0_CFF_MASK,
  kACMP_OutputAssertEventFlag = CMP_C0_COUT_MASK
}
 Status flag mask. More...
 
enum  acmp_hysteresis_mode_t {
  kACMP_HysteresisLevel0 = 0U,
  kACMP_HysteresisLevel1 = 1U,
  kACMP_HysteresisLevel2 = 2U,
  kACMP_HysteresisLevel3 = 3U
}
 Comparator hard block hysteresis control. More...
 
enum  acmp_reference_voltage_source_t {
  kACMP_VrefSourceVin1 = 0U,
  kACMP_VrefSourceVin2 = 1U
}
 CMP Voltage Reference source. More...
 
enum  acmp_fixed_port_t {
  kACMP_FixedPlusPort = 0U,
  kACMP_FixedMinusPort = 1U
}
 Fixed mux port. More...
 

Driver version

#define FSL_ACMP_DRIVER_VERSION   (MAKE_VERSION(2U, 0U, 4U))
 ACMP driver version 2.0.4. More...
 

Initialization and deinitialization

void ACMP_Init (CMP_Type *base, const acmp_config_t *config)
 Initializes the ACMP. More...
 
void ACMP_Deinit (CMP_Type *base)
 Deinitializes the ACMP. More...
 
void ACMP_GetDefaultConfig (acmp_config_t *config)
 Gets the default configuration for ACMP. More...
 

Basic Operations

void ACMP_Enable (CMP_Type *base, bool enable)
 Enables or disables the ACMP. More...
 
void ACMP_SetChannelConfig (CMP_Type *base, const acmp_channel_config_t *config)
 Sets the channel configuration. More...
 

Advanced Operations

void ACMP_EnableDMA (CMP_Type *base, bool enable)
 Enables or disables DMA. More...
 
void ACMP_EnableWindowMode (CMP_Type *base, bool enable)
 Enables or disables window mode. More...
 
void ACMP_SetFilterConfig (CMP_Type *base, const acmp_filter_config_t *config)
 Configures the filter. More...
 
void ACMP_SetDACConfig (CMP_Type *base, const acmp_dac_config_t *config)
 Configures the internal DAC. More...
 
void ACMP_SetRoundRobinConfig (CMP_Type *base, const acmp_round_robin_config_t *config)
 Configures the round robin mode. More...
 
void ACMP_SetRoundRobinPreState (CMP_Type *base, uint32_t mask)
 Defines the pre-set state of channels in round robin mode. More...
 
static uint32_t ACMP_GetRoundRobinStatusFlags (CMP_Type *base)
 Gets the channel input changed flags in round robin mode. More...
 
void ACMP_ClearRoundRobinStatusFlags (CMP_Type *base, uint32_t mask)
 Clears the channel input changed flags in round robin mode. More...
 
static uint32_t ACMP_GetRoundRobinResult (CMP_Type *base)
 Gets the round robin result. More...
 

Interrupts

void ACMP_EnableInterrupts (CMP_Type *base, uint32_t mask)
 Enables interrupts. More...
 
void ACMP_DisableInterrupts (CMP_Type *base, uint32_t mask)
 Disables interrupts. More...
 

Status

uint32_t ACMP_GetStatusFlags (CMP_Type *base)
 Gets status flags. More...
 
void ACMP_ClearStatusFlags (CMP_Type *base, uint32_t mask)
 Clears status flags. More...
 

Data Structure Documentation

struct acmp_config_t

Data Fields

acmp_hysteresis_mode_t hysteresisMode
 Hysteresis mode. More...
 
bool enableHighSpeed
 Enable High Speed (HS) comparison mode. More...
 
bool enableInvertOutput
 Enable inverted comparator output. More...
 
bool useUnfilteredOutput
 Set compare output(COUT) to equal COUTA(true) or COUT(false). More...
 
bool enablePinOut
 The comparator output is available on the associated pin. More...
 

Field Documentation

acmp_hysteresis_mode_t acmp_config_t::hysteresisMode
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.

Data Fields

uint32_t plusMuxInput
 Plus mux input channel(0~7). More...
 
uint32_t minusMuxInput
 Minus mux input channel(0~7). More...
 

Field Documentation

uint32_t acmp_channel_config_t::plusMuxInput
uint32_t acmp_channel_config_t::minusMuxInput
struct acmp_filter_config_t

Data Fields

bool enableSample
 Using external SAMPLE as sampling clock input, or using divided bus clock. More...
 
uint32_t filterCount
 Filter Sample Count. More...
 
uint32_t filterPeriod
 Filter Sample Period. More...
 

Field Documentation

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.

struct acmp_dac_config_t

Data Fields

acmp_reference_voltage_source_t referenceVoltageSource
 Supply voltage reference source. More...
 
uint32_t DACValue
 Value for DAC Output Voltage. More...
 

Field Documentation

acmp_reference_voltage_source_t acmp_dac_config_t::referenceVoltageSource
uint32_t acmp_dac_config_t::DACValue

Available range is 0-63.

struct acmp_round_robin_config_t

Data Fields

acmp_fixed_port_t fixedPort
 Fixed mux port. More...
 
uint32_t fixedChannelNumber
 Indicates which channel is fixed in the fixed mux port. More...
 
uint32_t checkerChannelMask
 Mask of checker channel index. More...
 
uint32_t sampleClockCount
 Specifies how many round-robin clock cycles(0~3) later the sample takes place. More...
 
uint32_t delayModulus
 Comparator and DAC initialization delay modulus. More...
 

Field Documentation

acmp_fixed_port_t acmp_round_robin_config_t::fixedPort
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

Macro Definition Documentation

#define FSL_ACMP_DRIVER_VERSION   (MAKE_VERSION(2U, 0U, 4U))
#define CMP_C0_CFx_MASK   (CMP_C0_CFR_MASK | CMP_C0_CFF_MASK)

Enumeration Type Documentation

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.

Function Documentation

void ACMP_Init ( CMP_Type *  base,
const acmp_config_t config 
)

The default configuration can be got by calling ACMP_GetDefaultConfig().

Parameters
baseACMP peripheral base address.
configPointer to ACMP configuration structure.
void ACMP_Deinit ( CMP_Type *  base)
Parameters
baseACMP peripheral base address.
void ACMP_GetDefaultConfig ( acmp_config_t config)

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
configPointer to ACMP configuration structure.
void ACMP_Enable ( CMP_Type *  base,
bool  enable 
)
Parameters
baseACMP peripheral base address.
enableTrue to enable the ACMP.
void ACMP_SetChannelConfig ( CMP_Type *  base,
const acmp_channel_config_t config 
)

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:

acmp_channel_config_t configStruct = {0};
configStruct.positivePortInput = kACMP_PortInputFromDAC;
configStruct.negativePortInput = kACMP_PortInputFromMux;
configStruct.minusMuxInput = 1U;
ACMP_SetChannelConfig(CMP0, &configStruct);
Parameters
baseACMP peripheral base address.
configPointer to channel configuration structure.
void ACMP_EnableDMA ( CMP_Type *  base,
bool  enable 
)
Parameters
baseACMP peripheral base address.
enableTrue to enable DMA.
void ACMP_EnableWindowMode ( CMP_Type *  base,
bool  enable 
)
Parameters
baseACMP peripheral base address.
enableTrue to enable window mode.
void ACMP_SetFilterConfig ( CMP_Type *  base,
const acmp_filter_config_t config 
)

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:

acmp_filter_config_t configStruct = {0};
configStruct.filterCount = 5U;
configStruct.filterPeriod = 200U;
configStruct.enableSample = false;
ACMP_SetFilterConfig(CMP0, &configStruct);
Parameters
baseACMP peripheral base address.
configPointer to filter configuration structure.
void ACMP_SetDACConfig ( CMP_Type *  base,
const acmp_dac_config_t config 
)

Example:

acmp_dac_config_t configStruct = {0};
configStruct.DACValue = 20U;
configStruct.enableOutput = false;
configStruct.workMode = kACMP_DACWorkLowSpeedMode;
ACMP_SetDACConfig(CMP0, &configStruct);
Parameters
baseACMP peripheral base address.
configPointer to DAC configuration structure. "NULL" is for disabling the feature.
void ACMP_SetRoundRobinConfig ( CMP_Type *  base,
const acmp_round_robin_config_t config 
)

Example:

acmp_round_robin_config_t configStruct = {0};
configStruct.fixedChannelNumber = 3U;
configStruct.checkerChannelMask = 0xF7U;
configStruct.sampleClockCount = 0U;
configStruct.delayModulus = 0U;
ACMP_SetRoundRobinConfig(CMP0, &configStruct);
Parameters
baseACMP peripheral base address.
configPointer 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
baseACMP peripheral base address.
maskMask of round robin channel index. Available range is channel0:0x01 to channel7:0x80.
static uint32_t ACMP_GetRoundRobinStatusFlags ( CMP_Type *  base)
inlinestatic
Parameters
baseACMP 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
baseACMP peripheral base address.
maskMask 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
baseACMP 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
baseACMP peripheral base address.
maskInterrupts mask. See "_acmp_interrupt_enable".
void ACMP_DisableInterrupts ( CMP_Type *  base,
uint32_t  mask 
)
Parameters
baseACMP peripheral base address.
maskInterrupts mask. See "_acmp_interrupt_enable".
uint32_t ACMP_GetStatusFlags ( CMP_Type *  base)
Parameters
baseACMP peripheral base address.
Returns
Status flags asserted mask. See "_acmp_status_flags".
void ACMP_ClearStatusFlags ( CMP_Type *  base,
uint32_t  mask 
)
Parameters
baseACMP peripheral base address.
maskStatus flags mask. See "_acmp_status_flags".