MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
CADC: 12-bit Cyclic Analog-to-Digital Converter Driver

Overview

The MCUXpresso SDK provides a peripheral driver for the 12-bit Cyclic Analog-to-Digital Converter (CADC) module of MCUXpresso SDK devices.

The analog-to-digital (ADC) converter function consists of two separate analog-to-digital converters, each with eight analog inputs and its own sample and hold circuit. A common digital control module configures and controls the functioning of the converters.

To match the hardware feature, the CADC driver is designed with three parts: APIs for configuring common digital control module, APIs for configuring each converter and APIs for operating sample slots.

The common digital control configuration is set when initializing the CADC module in application, as it should be done firstly before any other operation, and decide how the two converters work together. The converter configure APIs would set each converter's attributes and operate them. Finally, the sample slot API would configure the sample slot with input channel and gather them to be a conversion sequence. Once the trigger (software trigger or external hardware trigger) starts, the sequence is started and the conversion are executed.

Function groups

Initialization and deinitialization

This function group initializes/de-initializes the CADC. The initialization should be done first, before any operation to the CADC module in application. It enables the clock and sets the configuration for the common digital control. An API to fill the configuration with an available default setting is also provided.

Each converter

This function group configures each of the two converters in the CADC module.

Each sample

This function group is for the operations to sample slot.

Typical use case

Triggered parallel

Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/cadc

Data Structures

struct  cadc_config_t
 Defines the structure for configuring the CyclicADC's common setting. More...
 
struct  cadc_converter_config_t
 Define the structure for configuring each converter. More...
 
struct  cadc_sample_config_t
 Defines the structure for configuring the sample slot. More...
 

Macros

#define CADC_SAMPLE_MASK(index)   (1U << (index))
 Convert index to mask for sample slot. More...
 

Enumerations

enum  _cadc_status_flags {
  kCADC_ZeroCrossingFlag = (1U << 0U),
  kCADC_HighLimitFlag = (1U << 2U),
  kCADC_LowLimitFlag = (1U << 1U),
  kCADC_ConverterAInProgressFlag = (1U << 3U),
  kCADC_ConverterBInProgressFlag = (1U << 4U),
  kCADC_ConverterAEndOfScanFlag = (1U << 5U),
  kCADC_ConverterBEndOfScanFlag = (1U << 6U),
  kCADC_ConverterAPowerDownFlag = (1U << 7U),
  kCADC_ConverterBPowerDownFlag = (1U << 8U)
}
 CADC status flags. More...
 
enum  _cadc_interrupt_enable {
  kCADC_ZeroCrossingInterruptEnable = (1U << 0U),
  kCADC_HighLimitInterruptEnable = (1U << 1U),
  kCADC_LowLimitInterruptEnable = (1U << 2U),
  kCADC_ConverterAEndOfScanInterruptEnable = (1U << 3U),
  kCADC_ConverterBEndOfScanInterruptEnable = (1U << 4U)
}
 CADC Interrupts. More...
 
enum  _cadc_converter_id {
  kCADC_ConverterA = (1U << 0U),
  kCADC_ConverterB = (1U << 1U)
}
 CADC Converter identifier. More...
 
enum  cadc_dual_converter_scan_mode_t {
  kCADC_DualConverterWorkAsOnceSequential = 0U,
  kCADC_DualConverterWorkAsOnceParallel = 1U,
  kCADC_DualConverterWorkAsLoopSequential = 2U,
  kCADC_DualConverterWorkAsLoopParallel = 3U,
  kCADC_DualConverterWorkAsTriggeredSequential = 4U,
  kCADC_DualConverterWorkAsTriggeredParallel = 5U
}
 Defines the enumeration for dual converter's scan mode. More...
 
enum  cadc_dma_trigger_source_t {
  kCADC_DMATriggerSourceAsEndOfScan = 0U,
  kCADC_DMATriggerSourceAsSampleReady = 1U
}
 Defines the enumeration for DMA trigger's source. More...
 
enum  cadc_reference_voltage_source_t {
  kCADC_ReferenceVoltageVrefPad = 0U,
  kCADC_ReferenceVoltageChannelPad = 1U
}
 Defines the enumeration for converter's reference voltage source. More...
 
enum  cadc_channel_gain_t {
  kCADC_ChannelGainx1 = 0U,
  kCADC_ChannelGainx2 = 1U,
  kCADC_ChannelGainx4 = 2U
}
 Defines the enumeration for channel's input gain. More...
 
enum  cadc_speed_mode_t {
  kCADC_SpeedMode0 = 0U,
  kCADC_SpeedMode1 = 1U,
  kCADC_SpeedMode2 = 2U,
  kCADC_SpeedMode3 = 3U
}
 Defines the enumeration for the converter's speed mode. More...
 
enum  cadc_zero_crossing_mode_t {
  kCADC_ZeroCorssingDisabled = 0U,
  kCADC_ZeroCorssingForPtoNSign = 1U,
  kCADC_ZeroCorssingForNtoPSign = 2U,
  kCADC_ZeroCorssingForAnySignChanged = 3U
}
 Defines the enumeration for the sample slot's zero crossing event. More...
 
enum  cadc_idle_work_mode_t {
  kCADC_IdleKeepNormal = 0U,
  kCADC_IdleAutoStandby,
  kCADC_IdleAutoPowerDown
}
 Defines the enumeration for converter's work mode in idle mode. More...
 

Driver version

#define FSL_CADC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
 CADC driver version 2.0.0. More...
 

Initialization and deinitialization

void CADC_Init (ADC_Type *base, const cadc_config_t *config)
 Initializes the CADC module. More...
 
void CADC_GetDefaultConfig (cadc_config_t *config)
 Gets an available pre-defined settings for module's configuration. More...
 
void CADC_Deinit (ADC_Type *base)
 Deinitializes the CADC module. More...
 

Each Converter

void CADC_SetConverterConfig (ADC_Type *base, uint16_t converterMask, const cadc_converter_config_t *config)
 Configures the converter. More...
 
void CADC_GetDefaultConverterConfig (cadc_converter_config_t *config)
 Gets an available pre-defined settings for each converter's configuration. More...
 
void CADC_EnableConverter (ADC_Type *base, uint16_t converterMask, bool enable)
 Enables the converter's conversion. More...
 
void CADC_EnableConverterSyncInput (ADC_Type *base, uint16_t converterMask, bool enable)
 Enables the input of external sync signal. More...
 
void CADC_EnableConverterPower (ADC_Type *base, uint16_t converterMask, bool enable)
 Enables power for the converter. More...
 
void CADC_DoSoftwareTriggerConverter (ADC_Type *base, uint16_t converterMask)
 Triggers the converter by software trigger. More...
 
void CADC_EnableConverterDMA (ADC_Type *base, uint16_t converterMask, bool enable)
 Enables the DMA feature. More...
 
void CADC_EnableInterrupts (ADC_Type *base, uint16_t mask)
 Enables the interrupts. More...
 
void CADC_DisableInterrupts (ADC_Type *base, uint16_t mask)
 Disables the interrupts. More...
 
uint16_t CADC_GetStatusFlags (ADC_Type *base)
 Gets the status flags. More...
 
void CADC_ClearStatusFlags (ADC_Type *base, uint16_t flags)
 Clears the status flags. More...
 

Each Sample

void CADC_SetSampleConfig (ADC_Type *base, uint16_t sampleIndex, const cadc_sample_config_t *config)
 Configures the sample slot. More...
 
static void CADC_EnableSample (ADC_Type *base, uint16_t sampleMask, bool enable)
 Enables the sample slot. More...
 
static void CADC_EnableSampleResultReadyInterrupts (ADC_Type *base, uint16_t sampleMask, bool enable)
 Enables the interrupt for each sample slot when its result is ready. More...
 
static uint16_t CADC_GetSampleReadyStatusFlags (ADC_Type *base)
 Returns the sample ready flags of sample slots. More...
 
static uint16_t CADC_GetSampleLowLimitStatusFlags (ADC_Type *base)
 Gets the low limit flags of sample slots. More...
 
static void CADC_ClearSampleLowLimitStatusFlags (ADC_Type *base, uint16_t sampleMask)
 Clears low limit flags of sample slots. More...
 
static uint16_t CADC_GetSampleHighLimitStatusFlags (ADC_Type *base)
 Gets the high limit flags of sample slots. More...
 
static void CADC_ClearSampleHighLimitStatusFlags (ADC_Type *base, uint16_t sampleMask)
 Clears the high limit flags of sample slots. More...
 
static uint16_t CADC_GetSampleZeroCrossingStatusFlags (ADC_Type *base)
 Gets the zero crossing flags of sample slots. More...
 
static void CADC_ClearSampleZeroCrossingStatusFlags (ADC_Type *base, uint16_t sampleMask)
 Clears zero crossing flags of sample slots. More...
 
static uint16_t CADC_GetSampleResultValue (ADC_Type *base, uint16_t sampleIndex)
 Gets the sample result value. More...
 

Data Structure Documentation

struct cadc_config_t

Data Fields

cadc_dual_converter_scan_mode_t dualConverterScanMode
 Dual converter's scan mode. More...
 
bool enableSimultaneousMode
 Using Simultaneous mode. More...
 
cadc_dma_trigger_source_t DMATriggerSoruce
 DMA trigger source. More...
 
cadc_idle_work_mode_t idleWorkMode
 Converter's work mode when in idle. More...
 
uint16_t powerUpDelay
 Delay clock count to wait for the clock is stable. More...
 

Field Documentation

cadc_dual_converter_scan_mode_t cadc_config_t::dualConverterScanMode
bool cadc_config_t::enableSimultaneousMode
cadc_dma_trigger_source_t cadc_config_t::DMATriggerSoruce
cadc_idle_work_mode_t cadc_config_t::idleWorkMode
uint16_t cadc_config_t::powerUpDelay

Available range is 0-63.

struct cadc_converter_config_t

Data Fields

uint16_t clockDivisor
 Converter's clock divisor for the clock source. More...
 
cadc_speed_mode_t speedMode
 Converter's speed mode. More...
 
cadc_reference_voltage_source_t highReferenceVoltageSource
 High voltage reference source. More...
 
cadc_reference_voltage_source_t lowReferenceVoltageSource
 Low reference voltage source. More...
 
uint16_t sampleWindowCount
 Sample Window Count. More...
 

Field Documentation

uint16_t cadc_converter_config_t::clockDivisor

Available setting range is 0-63.

cadc_speed_mode_t cadc_converter_config_t::speedMode
cadc_reference_voltage_source_t cadc_converter_config_t::highReferenceVoltageSource
cadc_reference_voltage_source_t cadc_converter_config_t::lowReferenceVoltageSource
uint16_t cadc_converter_config_t::sampleWindowCount

Available setting range is 0-7.

struct cadc_sample_config_t

Data Fields

uint16_t channelNumber
 Channel number. More...
 
bool enableDifferentialPair
 Use differential sample input or not. More...
 
cadc_channel_gain_t channelGain
 Input gain. More...
 
cadc_zero_crossing_mode_t zeroCrossingMode
 Zero crossing mode. More...
 
uint16_t highLimitValue
 High limit value. More...
 
uint16_t lowLimitValue
 Low limit value. More...
 
uint16_t offsetValue
 Offset value. More...
 
bool enableWaitSync
 Wait for sync input to launch this sample's conversion. More...
 

Field Documentation

uint16_t cadc_sample_config_t::channelNumber

The available range is 0-15.

bool cadc_sample_config_t::enableDifferentialPair
cadc_channel_gain_t cadc_sample_config_t::channelGain
cadc_zero_crossing_mode_t cadc_sample_config_t::zeroCrossingMode
uint16_t cadc_sample_config_t::highLimitValue

Original value formation as hardware register, with 3-bits left shifted.

uint16_t cadc_sample_config_t::lowLimitValue

Original value formation as hardware register, with 3-bits left shifted.

uint16_t cadc_sample_config_t::offsetValue

Original value formation as hardware register, with 3-bits left shifted.

bool cadc_sample_config_t::enableWaitSync

Macro Definition Documentation

#define FSL_CADC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
#define CADC_SAMPLE_MASK (   index)    (1U << (index))

Enumeration Type Documentation

Enumerator
kCADC_ZeroCrossingFlag 

Zero crossing.

kCADC_HighLimitFlag 

High limit.

kCADC_LowLimitFlag 

Low limit.

kCADC_ConverterAInProgressFlag 

Conversion in progress, converter A.

kCADC_ConverterBInProgressFlag 

Conversion in progress, converter B.

kCADC_ConverterAEndOfScanFlag 

End of scan, converter A.

kCADC_ConverterBEndOfScanFlag 

End of scan, converter B.

kCADC_ConverterAPowerDownFlag 

The converter is powered down, converter A.

kCADC_ConverterBPowerDownFlag 

The converter is powered down, converter B.

Enumerator
kCADC_ZeroCrossingInterruptEnable 

Zero crossing interrupt.

kCADC_HighLimitInterruptEnable 

High limit interrupt.

kCADC_LowLimitInterruptEnable 

Low limit interrupt.

kCADC_ConverterAEndOfScanInterruptEnable 

End of scan interrupt, converter A.

kCADC_ConverterBEndOfScanInterruptEnable 

End of scan interrupt, converter B.

Enumerator
kCADC_ConverterA 

Converter A.

kCADC_ConverterB 

Converter B.

Enumerator
kCADC_DualConverterWorkAsOnceSequential 

Once (single) sequential.

kCADC_DualConverterWorkAsOnceParallel 

Once parallel.

kCADC_DualConverterWorkAsLoopSequential 

Loop sequential.

kCADC_DualConverterWorkAsLoopParallel 

Loop parallel.

kCADC_DualConverterWorkAsTriggeredSequential 

Triggered sequential.

kCADC_DualConverterWorkAsTriggeredParallel 

Triggered parallel.

Enumerator
kCADC_DMATriggerSourceAsEndOfScan 

DMA trigger source is end of scan interrupt.

kCADC_DMATriggerSourceAsSampleReady 

DMA trigger source is RDY bits.

Enumerator
kCADC_ReferenceVoltageVrefPad 

VREF pin.

kCADC_ReferenceVoltageChannelPad 

ANx2 or ANx3 pin.

Enumerator
kCADC_ChannelGainx1 

Gain x1.

kCADC_ChannelGainx2 

Gain x2.

kCADC_ChannelGainx4 

Gain x4.

Enumerator
kCADC_SpeedMode0 

Conversion clock frequency <= 6.25 MHz; current consumption per converter = 6 mA.

kCADC_SpeedMode1 

Conversion clock frequency <= 12.25 MHz; current consumption per converter = 10.8 mA.

kCADC_SpeedMode2 

Conversion clock frequency <= 18.75 MHz; current consumption per converter = 18 mA.

kCADC_SpeedMode3 

Conversion clock frequency <= 25 MHz; current consumption per converter = 25.2 mA.

Enumerator
kCADC_ZeroCorssingDisabled 

Zero Crossing disabled.

kCADC_ZeroCorssingForPtoNSign 

Zero Crossing enabled for positive to negative sign change.

kCADC_ZeroCorssingForNtoPSign 

Zero Crossing enabled for negative to positive sign change.

kCADC_ZeroCorssingForAnySignChanged 

Zero Crossing enabled for any sign change.

Enumerator
kCADC_IdleKeepNormal 

Keep normal.

kCADC_IdleAutoStandby 

Fall into standby mode automatically.

kCADC_IdleAutoPowerDown 

Fall into power down mode automatically.

Function Documentation

void CADC_Init ( ADC_Type *  base,
const cadc_config_t config 
)

This function is to make the initialization for using CADC module. The operations are:

  • Enable the clock for CADC.
  • Set the global settings for CADC converter.
Parameters
baseCADC peripheral base address.
configPointer to configuration structure. See "cadc_config_t".
void CADC_GetDefaultConfig ( cadc_config_t config)

This function initializes the module's configuration structure with an available settings. The default value are:

* config->dualConverterScanMode = kCADC_DualConverterWorkAsTriggeredParallel;
* config->enableSimultaneousMode = true;
* config->DMATriggerSoruce = kCADC_DMATriggerSourceAsEndOfScan;
* config->idleWorkMode = kCADC_IdleKeepNormal;
* config->powerUpDelay = 26U;
*
Parameters
configPointer to configuration structure. See "cadc_config_t"
void CADC_Deinit ( ADC_Type *  base)

This function is to make the de-initialization for using CADC module. The operations are:

  • Power down both converter.
  • Disable the clock for CADC.
Parameters
baseCADC peripheral base address.
void CADC_SetConverterConfig ( ADC_Type *  base,
uint16_t  converterMask,
const cadc_converter_config_t config 
)
Parameters
baseCADC peripheral base address.
converterMaskMask for converters to be configured. See "_cadc_converter_id".
configPointer to configuration structure. See "cadc_converter_config_t".
void CADC_GetDefaultConverterConfig ( cadc_converter_config_t config)

This function initializes each converter's configuration structure with an available settings. The default value are:

* config->clockDivisor = 4U;
* config->speedMode = kCADC_SpeedMode0;
* config->highReferenceVoltageSource = kCADC_ReferenceVoltageVrefPad;
* config->lowReferenceVoltageSource = kCADC_ReferenceVoltageVrefPad;
* config->sampleWindowCount = 0U;
*
Parameters
configPointer to configuration structure. See "cadc_converter_config_t"
void CADC_EnableConverter ( ADC_Type *  base,
uint16_t  converterMask,
bool  enable 
)

This function is to enable the converter's conversion. The conversion should only be launched after the converter is enabled. When this feature is asserted to be "false", the current scan is stopped and no further scans can start. All the software trigger and hardware trigger are ignored.

Parameters
baseCADC peripheral base address.
converterMaskMask for converters to be operated. See "_cadc_converter_id".
enableEnable the power for converter.
void CADC_EnableConverterSyncInput ( ADC_Type *  base,
uint16_t  converterMask,
bool  enable 
)

This function is to enable the input of external sync signal. The external sync signal could be used to trigger the conversion if the hardware trigger related setting is used. Note: When in "Once" scan mode, this gate would be off automatically after an available sync is received. User needs to enable the input again manually if another sync signal is wanted.

Parameters
baseCADC peripheral base address.
converterMaskMask for converters to be operated. See "_cadc_converter_id".
enableEnable the feature or not.
void CADC_EnableConverterPower ( ADC_Type *  base,
uint16_t  converterMask,
bool  enable 
)

This function is to enable the power for the converter. The converter should be powered on before conversion. Once this API is called, the converter would be powered on after a few moment (so-called power up delay), so that the power would be stable.

Parameters
baseCADC peripheral base address.
converterMaskMask for converters to be operated. See "_cadc_converter_id".
enableEnable the feature or not.
void CADC_DoSoftwareTriggerConverter ( ADC_Type *  base,
uint16_t  converterMask 
)

This function is to do the software trigger to the converter. The software trigger can used to start a conversion sequence.

Parameters
baseCADC peripheral base address.
converterMaskMask for converters to be operated. See "_cadc_converter_id".
void CADC_EnableConverterDMA ( ADC_Type *  base,
uint16_t  converterMask,
bool  enable 
)
Parameters
baseCADC peripheral base address.
converterMaskMask for converters to be operated. See "_cadc_converter_id".
enableEnable the feature or not.
void CADC_EnableInterrupts ( ADC_Type *  base,
uint16_t  mask 
)
Parameters
baseCADC peripheral base address.
maskMask value for interrupt events. See "_cadc_interrupt_enable".
void CADC_DisableInterrupts ( ADC_Type *  base,
uint16_t  mask 
)
Parameters
baseCADC peripheral base address.
maskMask value for interrupt events. See "_cadc_interrupt_enable".
uint16_t CADC_GetStatusFlags ( ADC_Type *  base)
Parameters
baseCADC peripheral base address.
Returns
Mask value for the event flags. See "_cadc_status_flags".
void CADC_ClearStatusFlags ( ADC_Type *  base,
uint16_t  flags 
)
Parameters
baseCADC peripheral base address.
flagsMask value for the event flags to be cleared. See "_cadc_status_flags".
void CADC_SetSampleConfig ( ADC_Type *  base,
uint16_t  sampleIndex,
const cadc_sample_config_t config 
)
Parameters
baseCADC peripheral base address.
sampleIndexIndex of sample slot in conversion sequence. Available range is 0-15.
configPointer to configuration structure. See "cadc_sample_config_t"
static void CADC_EnableSample ( ADC_Type *  base,
uint16_t  sampleMask,
bool  enable 
)
inlinestatic

This function is to enable the sample slot. Only the enabled sample slot can join the conversion sequence.

Parameters
baseCADC peripheral base address.
sampleMaskMask value of sample slots in conversion sequence. Each bit is responding to a sample slot.
enableEnable the feature or not.
static void CADC_EnableSampleResultReadyInterrupts ( ADC_Type *  base,
uint16_t  sampleMask,
bool  enable 
)
inlinestatic
Parameters
baseCADC peripheral base address.
sampleMaskMask value of sample slots in conversion sequence. Each bit is responding to a sample slot.
enableEnable the feature or not.
static uint16_t CADC_GetSampleReadyStatusFlags ( ADC_Type *  base)
inlinestatic
Parameters
baseCADC peripheral base address.
Returns
Mask value for the sample slots if their result are ready.
static uint16_t CADC_GetSampleLowLimitStatusFlags ( ADC_Type *  base)
inlinestatic
Parameters
baseCADC peripheral base address.
Returns
Mask value for the sample slots if their results exceed the low limit.
static void CADC_ClearSampleLowLimitStatusFlags ( ADC_Type *  base,
uint16_t  sampleMask 
)
inlinestatic
Parameters
baseCADC peripheral base address.
sampleMaskMask value for the sample slots' flags to be cleared.
static uint16_t CADC_GetSampleHighLimitStatusFlags ( ADC_Type *  base)
inlinestatic
Parameters
baseCADC peripheral base address.
Returns
Mask value for the sample slots if their results exceed the high limit.
static void CADC_ClearSampleHighLimitStatusFlags ( ADC_Type *  base,
uint16_t  sampleMask 
)
inlinestatic
Parameters
baseCADC peripheral base address.
sampleMaskMask value for the sample slots to be cleared flags.
static uint16_t CADC_GetSampleZeroCrossingStatusFlags ( ADC_Type *  base)
inlinestatic
Parameters
baseCADC peripheral base address.
Returns
Mask value for the sample slots if their results cause the zero crossing event.
static void CADC_ClearSampleZeroCrossingStatusFlags ( ADC_Type *  base,
uint16_t  sampleMask 
)
inlinestatic
Parameters
baseCADC peripheral base address.
sampleMaskMask value for the sample slots to be cleared flags.
static uint16_t CADC_GetSampleResultValue ( ADC_Type *  base,
uint16_t  sampleIndex 
)
inlinestatic

This function is to get the sample result value. This returned value keeps it original formation just like in hardware result register. It includes the sign bit as the MSB and 3-bit left shifted value.

Parameters
baseCADC peripheral base address.
sampleIndexIndex of sample slot.
Returns
Sample's conversion value.