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
|
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...
|
|
|
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...
|
|
|
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...
|
|
bool cadc_config_t::enableSimultaneousMode |
uint16_t cadc_config_t::powerUpDelay |
struct cadc_converter_config_t |
uint16_t cadc_converter_config_t::clockDivisor |
Available setting range is 0-63.
uint16_t cadc_converter_config_t::sampleWindowCount |
Available setting range is 0-7.
struct cadc_sample_config_t |
uint16_t cadc_sample_config_t::channelNumber |
The available range is 0-15.
bool cadc_sample_config_t::enableDifferentialPair |
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 |
#define FSL_CADC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) |
#define CADC_SAMPLE_MASK |
( |
|
index | ) |
(1U << (index)) |
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.
|
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
-
base | CADC peripheral base address. |
config | Pointer to configuration structure. See "cadc_config_t". |
This function initializes the module's configuration structure with an available settings. The default value are:
* config->enableSimultaneousMode = true;
* config->powerUpDelay = 26U;
*
- Parameters
-
config | Pointer 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
-
base | CADC peripheral base address. |
- Parameters
-
base | CADC peripheral base address. |
converterMask | Mask for converters to be configured. See "_cadc_converter_id". |
config | Pointer to configuration structure. See "cadc_converter_config_t". |
This function initializes each converter's configuration structure with an available settings. The default value are:
* config->clockDivisor = 4U;
* config->sampleWindowCount = 0U;
*
- Parameters
-
config | Pointer 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
-
base | CADC peripheral base address. |
converterMask | Mask for converters to be operated. See "_cadc_converter_id". |
enable | Enable 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
-
base | CADC peripheral base address. |
converterMask | Mask for converters to be operated. See "_cadc_converter_id". |
enable | Enable 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
-
base | CADC peripheral base address. |
converterMask | Mask for converters to be operated. See "_cadc_converter_id". |
enable | Enable 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
-
base | CADC peripheral base address. |
converterMask | Mask for converters to be operated. See "_cadc_converter_id". |
void CADC_EnableConverterDMA |
( |
ADC_Type * |
base, |
|
|
uint16_t |
converterMask, |
|
|
bool |
enable |
|
) |
| |
- Parameters
-
base | CADC peripheral base address. |
converterMask | Mask for converters to be operated. See "_cadc_converter_id". |
enable | Enable the feature or not. |
void CADC_EnableInterrupts |
( |
ADC_Type * |
base, |
|
|
uint16_t |
mask |
|
) |
| |
- Parameters
-
base | CADC peripheral base address. |
mask | Mask value for interrupt events. See "_cadc_interrupt_enable". |
void CADC_DisableInterrupts |
( |
ADC_Type * |
base, |
|
|
uint16_t |
mask |
|
) |
| |
- Parameters
-
base | CADC peripheral base address. |
mask | Mask value for interrupt events. See "_cadc_interrupt_enable". |
uint16_t CADC_GetStatusFlags |
( |
ADC_Type * |
base | ) |
|
- Parameters
-
base | CADC peripheral base address. |
- Returns
- Mask value for the event flags. See "_cadc_status_flags".
void CADC_ClearStatusFlags |
( |
ADC_Type * |
base, |
|
|
uint16_t |
flags |
|
) |
| |
- Parameters
-
base | CADC peripheral base address. |
flags | Mask 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
-
base | CADC peripheral base address. |
sampleIndex | Index of sample slot in conversion sequence. Available range is 0-15. |
config | Pointer 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
-
base | CADC peripheral base address. |
sampleMask | Mask value of sample slots in conversion sequence. Each bit is responding to a sample slot. |
enable | Enable the feature or not. |
static void CADC_EnableSampleResultReadyInterrupts |
( |
ADC_Type * |
base, |
|
|
uint16_t |
sampleMask, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | CADC peripheral base address. |
sampleMask | Mask value of sample slots in conversion sequence. Each bit is responding to a sample slot. |
enable | Enable the feature or not. |
static uint16_t CADC_GetSampleReadyStatusFlags |
( |
ADC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | CADC 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
-
base | CADC 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
-
base | CADC peripheral base address. |
sampleMask | Mask value for the sample slots' flags to be cleared. |
static uint16_t CADC_GetSampleHighLimitStatusFlags |
( |
ADC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | CADC 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
-
base | CADC peripheral base address. |
sampleMask | Mask value for the sample slots to be cleared flags. |
static uint16_t CADC_GetSampleZeroCrossingStatusFlags |
( |
ADC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | CADC 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
-
base | CADC peripheral base address. |
sampleMask | Mask 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
-
base | CADC peripheral base address. |
sampleIndex | Index of sample slot. |
- Returns
- Sample's conversion value.