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...
 
struct  acmp_discrete_mode_config_t
 Configuration for discrete 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...
 
enum  acmp_dac_work_mode_t {
  kACMP_DACWorkLowSpeedMode = 0U,
  kACMP_DACWorkHighSpeedMode = 1U
}
 Internal DAC's work mode. More...
 
enum  acmp_discrete_clock_source_t {
  kACMP_DiscreteClockSlow = 0U,
  kACMP_DiscreteClockFast = 1U
}
 Discrete mode clock selection. More...
 
enum  acmp_discrete_sample_time_t {
  kACMP_DiscreteSampleTimeAs1T = 0U,
  kACMP_DiscreteSampleTimeAs2T = 1U,
  kACMP_DiscreteSampleTimeAs4T = 2U,
  kACMP_DiscreteSampleTimeAs8T = 3U,
  kACMP_DiscreteSampleTimeAs16T = 4U,
  kACMP_DiscreteSampleTimeAs32T = 5U,
  kACMP_DiscreteSampleTimeAs64T = 6U,
  kACMP_DiscreteSampleTimeAs256T = 7U
}
 ACMP discrete sample selection. More...
 
enum  acmp_discrete_phase_time_t {
  kACMP_DiscretePhaseTimeAlt0 = 0U,
  kACMP_DiscretePhaseTimeAlt1 = 1U,
  kACMP_DiscretePhaseTimeAlt2 = 2U,
  kACMP_DiscretePhaseTimeAlt3 = 3U,
  kACMP_DiscretePhaseTimeAlt4 = 4U,
  kACMP_DiscretePhaseTimeAlt5 = 5U,
  kACMP_DiscretePhaseTimeAlt6 = 6U,
  kACMP_DiscretePhaseTimeAlt7 = 7U
}
 ACMP discrete phase time selection. More...
 

Driver version

#define FSL_ACMP_DRIVER_VERSION   (MAKE_VERSION(2U, 0U, 6U))
 ACMP driver version 2.0.6. 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_EnableLinkToDAC (CMP_Type *base, bool enable)
 Enables the link from CMP to DAC enable. 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...
 

Discrete mode

void ACMP_SetDiscreteModeConfig (CMP_Type *base, const acmp_discrete_mode_config_t *config)
 Configure the discrete mode. More...
 
void ACMP_GetDefaultDiscreteModeConfig (acmp_discrete_mode_config_t *config)
 Get the default configuration for discrete mode setting. 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-255.

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
struct acmp_discrete_mode_config_t

Data Fields

bool enablePositiveChannelDiscreteMode
 Positive Channel Continuous Mode Enable. More...
 
bool enableNegativeChannelDiscreteMode
 Negative Channel Continuous Mode Enable. More...
 
bool enableResistorDivider
 Resistor Divider Enable is used to enable the resistor divider for the inputs when they come from 3v domain and their values are above 1.8v. More...
 
acmp_discrete_clock_source_t clockSource
 Select the clock source in order to generate the requiried timing for comparator to work in discrete mode. More...
 
acmp_discrete_sample_time_t sampleTime
 Select the ACMP total sampling time period. More...
 
acmp_discrete_phase_time_t phase1Time
 Select the ACMP phase 1 sampling time. More...
 
acmp_discrete_phase_time_t phase2Time
 Select the ACMP phase 2 sampling time. More...
 

Field Documentation

bool acmp_discrete_mode_config_t::enablePositiveChannelDiscreteMode

By default, the continuous mode is used.

bool acmp_discrete_mode_config_t::enableNegativeChannelDiscreteMode

By default, the continuous mode is used.

bool acmp_discrete_mode_config_t::enableResistorDivider
acmp_discrete_clock_source_t acmp_discrete_mode_config_t::clockSource
acmp_discrete_sample_time_t acmp_discrete_mode_config_t::sampleTime
acmp_discrete_phase_time_t acmp_discrete_mode_config_t::phase1Time
acmp_discrete_phase_time_t acmp_discrete_mode_config_t::phase2Time

Macro Definition Documentation

#define FSL_ACMP_DRIVER_VERSION   (MAKE_VERSION(2U, 0U, 6U))
#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.

Enumerator
kACMP_DACWorkLowSpeedMode 

DAC is selected to work in low speed and low power mode.

kACMP_DACWorkHighSpeedMode 

DAC is selected to work in high speed high power mode.

Enumerator
kACMP_DiscreteClockSlow 

Slow clock (32kHz) is used as the discrete mode clock.

kACMP_DiscreteClockFast 

Fast clock (16-20MHz) is used as the discrete mode clock.

These values configures the analog comparator sampling timing (speicified by the discrete mode clock period T which is selected by acmp_discrete_clock_source_t) in discrete mode.

Enumerator
kACMP_DiscreteSampleTimeAs1T 

The sampling time equals to 1xT.

kACMP_DiscreteSampleTimeAs2T 

The sampling time equals to 2xT.

kACMP_DiscreteSampleTimeAs4T 

The sampling time equals to 4xT.

kACMP_DiscreteSampleTimeAs8T 

The sampling time equals to 8xT.

kACMP_DiscreteSampleTimeAs16T 

The sampling time equals to 16xT.

kACMP_DiscreteSampleTimeAs32T 

The sampling time equals to 32xT.

kACMP_DiscreteSampleTimeAs64T 

The sampling time equals to 64xT.

kACMP_DiscreteSampleTimeAs256T 

The sampling time equals to 256xT.

There are two phases for sampling input signals, phase 1 and phase 2.

Enumerator
kACMP_DiscretePhaseTimeAlt0 

The phase x active in one sampling selection 0.

kACMP_DiscretePhaseTimeAlt1 

The phase x active in one sampling selection 1.

kACMP_DiscretePhaseTimeAlt2 

The phase x active in one sampling selection 2.

kACMP_DiscretePhaseTimeAlt3 

The phase x active in one sampling selection 3.

kACMP_DiscretePhaseTimeAlt4 

The phase x active in one sampling selection 4.

kACMP_DiscretePhaseTimeAlt5 

The phase x active in one sampling selection 5.

kACMP_DiscretePhaseTimeAlt6 

The phase x active in one sampling selection 6.

kACMP_DiscretePhaseTimeAlt7 

The phase x active in one sampling selection 7.

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_EnableLinkToDAC ( CMP_Type *  base,
bool  enable 
)

When this bit is set, the DAC enable/disable is controlled by the bit CMP_C0[EN] instead of CMP_C1[DACEN].

Parameters
baseACMP peripheral base address.
enableEnable the feature or not.
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".
void ACMP_SetDiscreteModeConfig ( CMP_Type *  base,
const acmp_discrete_mode_config_t config 
)

Configure the discrete mode when supporting 3V domain with 1.8V core.

Parameters
baseACMP peripheral base address.
configPointer to configuration structure. See "acmp_discrete_mode_config_t".
void ACMP_GetDefaultDiscreteModeConfig ( acmp_discrete_mode_config_t config)
Parameters
configPointer to configuration structure to be restored with the setting values.