MCUXpresso SDK API Reference Manual  Rev 2.16.000
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
 Configuration for ACMP. More...
 
struct  _acmp_channel_config
 Configuration for channel. More...
 
struct  _acmp_filter_config
 Configuration for filter. More...
 
struct  _acmp_dac_config
 Configuration for DAC. More...
 
struct  _acmp_round_robin_config
 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...
 

Typedefs

typedef enum _acmp_offset_mode acmp_offset_mode_t
 Comparator hard block offset control. More...
 
typedef enum _acmp_hysteresis_mode acmp_hysteresis_mode_t
 Comparator hard block hysteresis control. More...
 
typedef enum
_acmp_reference_voltage_source 
acmp_reference_voltage_source_t
 CMP Voltage Reference source. More...
 
typedef enum _acmp_port_input acmp_port_input_t
 Port input source. More...
 
typedef enum _acmp_fixed_port acmp_fixed_port_t
 Fixed mux port. More...
 
typedef struct _acmp_config acmp_config_t
 Configuration for ACMP. More...
 
typedef struct _acmp_channel_config acmp_channel_config_t
 Configuration for channel. More...
 
typedef struct _acmp_filter_config acmp_filter_config_t
 Configuration for filter. More...
 
typedef struct _acmp_dac_config acmp_dac_config_t
 Configuration for DAC. More...
 
typedef struct
_acmp_round_robin_config 
acmp_round_robin_config_t
 Configuration for round robin mode. 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_offset_mode {
  kACMP_OffsetLevel0 = 0U,
  kACMP_OffsetLevel1 = 1U
}
 Comparator hard block offset control. More...
 
enum  _acmp_hysteresis_mode {
  kACMP_HysteresisLevel0 = 0U,
  kACMP_HysteresisLevel1 = 1U,
  kACMP_HysteresisLevel2 = 2U,
  kACMP_HysteresisLevel3 = 3U
}
 Comparator hard block hysteresis control. More...
 
enum  _acmp_reference_voltage_source {
  kACMP_VrefSourceVin1 = 0U,
  kACMP_VrefSourceVin2 = 1U
}
 CMP Voltage Reference source. More...
 
enum  _acmp_port_input {
  kACMP_PortInputFromDAC = 0U,
  kACMP_PortInputFromMux = 1U
}
 Port input source. More...
 
enum  _acmp_fixed_port {
  kACMP_FixedPlusPort = 0U,
  kACMP_FixedMinusPort = 1U
}
 Fixed mux port. More...
 

Driver version

#define FSL_ACMP_DRIVER_VERSION   (MAKE_VERSION(2, 3, 0))
 ACMP driver version 2.3.0. 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

Data Fields

acmp_offset_mode_t offsetMode
 Offset mode. More...
 
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_offset_mode_t _acmp_config::offsetMode
acmp_hysteresis_mode_t _acmp_config::hysteresisMode
bool _acmp_config::enableHighSpeed
bool _acmp_config::enableInvertOutput
bool _acmp_config::useUnfilteredOutput
bool _acmp_config::enablePinOut
struct _acmp_channel_config

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

acmp_port_input_t positivePortInput
 Input source of the comparator's positive port. More...
 
uint32_t plusMuxInput
 Plus mux input channel(0~7). More...
 
acmp_port_input_t negativePortInput
 Input source of the comparator's negative port. More...
 
uint32_t minusMuxInput
 Minus mux input channel(0~7). More...
 

Field Documentation

acmp_port_input_t _acmp_channel_config::positivePortInput
uint32_t _acmp_channel_config::plusMuxInput
acmp_port_input_t _acmp_channel_config::negativePortInput
uint32_t _acmp_channel_config::minusMuxInput
struct _acmp_filter_config

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::enableSample
uint32_t _acmp_filter_config::filterCount

Available range is 1-7, 0 would cause the filter disabled.

uint32_t _acmp_filter_config::filterPeriod

The divider to bus clock. Available range is 0-255.

struct _acmp_dac_config

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::referenceVoltageSource
uint32_t _acmp_dac_config::DACValue

Available range is 0-255.

struct _acmp_round_robin_config

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::fixedPort
uint32_t _acmp_round_robin_config::fixedChannelNumber
uint32_t _acmp_round_robin_config::checkerChannelMask

Available range is channel0:0x01 to channel7:0x80 for round-robin checker.

uint32_t _acmp_round_robin_config::sampleClockCount
uint32_t _acmp_round_robin_config::delayModulus

Macro Definition Documentation

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

Typedef Documentation

If OFFSET level is 1, then there is no hysteresis in the case of positive port input crossing negative port input in the positive direction (or negative port input crossing positive port input in the negative direction). Hysteresis still exists for positive port input crossing negative port input in the falling direction. If OFFSET level is 0, then the hysteresis selected by acmp_hysteresis_mode_t is valid for both directions.

See chip data sheet to get the actual hysteresis value with each level.

typedef struct _acmp_config acmp_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.

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.

If OFFSET level is 1, then there is no hysteresis in the case of positive port input crossing negative port input in the positive direction (or negative port input crossing positive port input in the negative direction). Hysteresis still exists for positive port input crossing negative port input in the falling direction. If OFFSET level is 0, then the hysteresis selected by acmp_hysteresis_mode_t is valid for both directions.

Enumerator
kACMP_OffsetLevel0 

The comparator hard block output has level 0 offset internally.

kACMP_OffsetLevel1 

The comparator hard block output has level 1 offset internally.

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_PortInputFromDAC 

Port input from the 8-bit DAC output.

kACMP_PortInputFromMux 

Port input from the analog 8-1 mux.

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.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".