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

Overview

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

Typical use case

Interrupt Configuration

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

Polling Configuration

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

Data Structures

struct  adc_config_t
 ADC converter configuration. More...
 
struct  adc_hardware_compare_config_t
 ADC hardware comparison configuration. More...
 
struct  adc_fifo_config_t
 ADC FIFO configuration. More...
 
struct  adc_channel_config_t
 ADC channel conversion configuration. More...
 

Macros

#define FSL_ADC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 2))
 ADC driver version. More...
 

Enumerations

enum  adc_reference_voltage_source_t {
  kADC_ReferenceVoltageSourceAlt0 = 0U,
  kADC_ReferenceVoltageSourceAlt1 = 1U
}
 Reference voltage source. More...
 
enum  adc_clock_divider_t {
  kADC_ClockDivider1 = 0U,
  kADC_ClockDivider2 = 1U,
  kADC_ClockDivider4 = 2U,
  kADC_ClockDivider8 = 3U
}
 Clock divider for the converter. More...
 
enum  adc_resolution_mode_t {
  kADC_Resolution8BitMode = 0U,
  kADC_Resolution10BitMode = 1U,
  kADC_Resolution12BitMode = 2U
}
 ADC converter resolution mode. More...
 
enum  adc_clock_source_t {
  kADC_ClockSourceAlt0 = 0U,
  kADC_ClockSourceAlt1 = 1U,
  kADC_ClockSourceAlt2 = 2U,
  kADC_ClockSourceAlt3 = 3U
}
 ADC input Clock source. More...
 
enum  adc_compare_mode_t {
  kADC_CompareDisableMode = 0U,
  kADC_CompareLessMode = 2U,
  kADC_CompareGreaterOrEqualMode = 3U
}
 Compare function mode. More...
 
enum  _adc_status_flags {
  kADC_ActiveFlag = ADC_SC2_ADACT_MASK,
  kADC_FifoEmptyFlag = ADC_SC2_FEMPTY_MASK,
  kADC_FifoFullFlag = ADC_SC2_FFULL_MASK
}
 ADC status flags mask. More...
 
enum  adc_hardware_trigger_mask_mode_t {
  kADC_HWTriggerMaskDisableMode,
  kADC_HWTriggerMaskAutoMode = 1U,
  kADC_HWTriggerMaskEnableMode
}
 Hardware tigger mask mode. More...
 

Initialization

void ADC_Init (ADC_Type *base, const adc_config_t *config)
 Initializes the ADC module. More...
 
void ADC_Deinit (ADC_Type *base)
 De-initialize the ADC module. More...
 
void ADC_GetDefaultConfig (adc_config_t *config)
 Gets an available pre-defined settings for the converter's configuration. More...
 
static void ADC_EnableHardwareTrigger (ADC_Type *base, bool enable)
 Enable the hardware trigger mode. More...
 
void ADC_SetHardwareCompare (ADC_Type *base, const adc_hardware_compare_config_t *config)
 Configure the hardware compare mode. More...
 
void ADC_SetFifoConfig (ADC_Type *base, const adc_fifo_config_t *config)
 Configure the Fifo mode. More...
 
void ADC_SetChannelConfig (ADC_Type *base, const adc_channel_config_t *config)
 Configures the conversion channel. More...
 
bool ADC_GetChannelStatusFlags (ADC_Type *base)
 Get the status flags of channel. More...
 
uint32_t ADC_GetStatusFlags (ADC_Type *base)
 Get the ADC status flags. More...
 
static void ADC_EnableAnalogInput (ADC_Type *base, uint32_t mask, bool enable)
 Disables the I/O port control of the pins used as analog inputs. More...
 
static uint32_t ADC_GetChannelConversionValue (ADC_Type *base)
 Gets the conversion value. More...
 
static void ADC_SetHardwareTriggerMaskMode (ADC_Type *base, adc_hardware_trigger_mask_mode_t mode)
 

Data Structure Documentation

struct adc_config_t

Data Fields

adc_reference_voltage_source_t referenceVoltageSource
 Selects the voltage reference source used for conversions. More...
 
bool enableLowPower
 Enable low power mode. More...
 
bool enableLongSampleTime
 Enable long sample time mode. More...
 
adc_clock_divider_t clockDivider
 Select the divider of input clock source. More...
 
adc_resolution_mode_t ResolutionMode
 Select the sample resolution mode. More...
 
adc_clock_source_t clockSource
 Select the input Clock source. More...
 

Field Documentation

adc_reference_voltage_source_t adc_config_t::referenceVoltageSource

>

bool adc_config_t::enableLowPower

The power is reduced at the expense of maximum clock speed. >

bool adc_config_t::enableLongSampleTime

>

adc_clock_divider_t adc_config_t::clockDivider

>

adc_resolution_mode_t adc_config_t::ResolutionMode

>

adc_clock_source_t adc_config_t::clockSource

>

struct adc_hardware_compare_config_t

Data Fields

uint32_t compareValue
 Setting the compare value. More...
 
adc_compare_mode_t compareMode
 Setting the compare mode. More...
 

Field Documentation

uint32_t adc_hardware_compare_config_t::compareValue

The value are compared to the conversion result. >

adc_compare_mode_t adc_hardware_compare_config_t::compareMode

Refer to "adc_compare_mode_t". >

struct adc_fifo_config_t

Data Fields

bool enableHWTriggerMultConv
 The field is valid when FIFO is enabled.Enable hardware trigger multiple conversion. More...
 
bool enableFifoScanMode
 The field is valid when FIFO is enabled. More...
 
bool enableCompareAndMode
 The field is valid when FIFO is enabled. More...
 
uint32_t FifoDepth
 Setting the depth of FIFO. More...
 

Field Documentation

bool adc_fifo_config_t::enableHWTriggerMultConv

One hardware trigger pulse triggers multiple conversions in fifo mode. >

bool adc_fifo_config_t::enableFifoScanMode

Enable the FIFO scan mode. If enable, ADC will repeat using the first FIFO channel as the conversion channel until the result FIFO is fulfilled. >

bool adc_fifo_config_t::enableCompareAndMode

If enable, ADC will AND all of compare triggers and set COCO after all of compare triggers occur. If disable, ADC will OR all of compare triggers and set COCO after at least one of compare trigger occurs. >

uint32_t adc_fifo_config_t::FifoDepth

Depth of fifo is FifoDepth + 1. When FifoDepth = 0U, the FIFO is DISABLED. When FifoDepth is set to nonzero, the FIFO function is ENABLED and the depth is indicated by the FifoDepth field. >

struct adc_channel_config_t

Data Fields

uint32_t channelNumber
 Setting the conversion channel number. More...
 
bool enableContinuousConversion
 enables continuous conversions. More...
 
bool enableInterruptOnConversionCompleted
 Generate an interrupt request once the conversion is completed. More...
 

Field Documentation

uint32_t adc_channel_config_t::channelNumber

The available range is 0-31. See channel connection information for each chip in Reference Manual document.

bool adc_channel_config_t::enableContinuousConversion

>

bool adc_channel_config_t::enableInterruptOnConversionCompleted

Macro Definition Documentation

#define FSL_ADC_DRIVER_VERSION   (MAKE_VERSION(2, 0, 2))

Version 2.0.2.

Enumeration Type Documentation

Enumerator
kADC_ReferenceVoltageSourceAlt0 

Default voltage reference pin pair (VREFH/VREFL).

>

kADC_ReferenceVoltageSourceAlt1 

Analog supply pin pair (VDDA/VSSA).

>

Enumerator
kADC_ClockDivider1 

Divide ration = 1, and clock rate = Input clock.

>

kADC_ClockDivider2 

Divide ration = 2, and clock rate = Input clock / 2.

>

kADC_ClockDivider4 

Divide ration = 3, and clock rate = Input clock / 4.

>

kADC_ClockDivider8 

Divide ration = 4, and clock rate = Input clock / 8.

>

Enumerator
kADC_Resolution8BitMode 

8-bit conversion (N = 8).

>

kADC_Resolution10BitMode 

10-bit conversion (N = 10) >

kADC_Resolution12BitMode 

12-bit conversion (N = 12) >

Enumerator
kADC_ClockSourceAlt0 

Bus clock.

>

kADC_ClockSourceAlt1 

Bus clock divided by 2.

>

kADC_ClockSourceAlt2 

Alternate clock (ALTCLK).

>

kADC_ClockSourceAlt3 

Asynchronous clock (ADACK).

>

Enumerator
kADC_CompareDisableMode 

Compare function disabled.

>

kADC_CompareLessMode 

Compare triggers when input is less than compare level.

>

kADC_CompareGreaterOrEqualMode 

Compare triggers when input is greater than or equal to compare level.

>

Enumerator
kADC_ActiveFlag 

Indicates that a conversion is in progress.

>

kADC_FifoEmptyFlag 

Indicates that ADC result FIFO have no valid new data.

>

kADC_FifoFullFlag 

Indicates that ADC result FIFO is full.

>

Enumerator
kADC_HWTriggerMaskDisableMode 

Hardware trigger mask disable and hardware trigger can trigger ADC conversion.

>

kADC_HWTriggerMaskAutoMode 

Hardware trigger mask automatically when data fifo is not empty.

>

kADC_HWTriggerMaskEnableMode 

Hardware trigger mask enable and hardware trigger cannot trigger ADC conversion.

>

Function Documentation

void ADC_Init ( ADC_Type *  base,
const adc_config_t config 
)
Parameters
baseADC peripheral base address.
configPointer to configuration structure. See "adc_config_t".
void ADC_Deinit ( ADC_Type *  base)
Parameters
baseADC peripheral base address.
void ADC_GetDefaultConfig ( adc_config_t config)

This function initializes the converter configuration structure with available settings. The default values are as follows.

* config->referenceVoltageSource = kADC_ReferenceVoltageSourceAlt0;
* config->enableLowPower = false;
* config->enableLongSampleTime = false;
* config->clockDivider = kADC_ClockDivider1;
* config->ResolutionMode = kADC_Resolution8BitMode;
* config->clockSource = kADC_ClockSourceAlt0;
*
Parameters
configPointer to the configuration structure.
static void ADC_EnableHardwareTrigger ( ADC_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseADC peripheral base address.
enableSwitcher of the hardware trigger feature. "true" means enabled, "false" means not enabled.
void ADC_SetHardwareCompare ( ADC_Type *  base,
const adc_hardware_compare_config_t config 
)

The compare function can be configured to check for an upper or lower limit. After the input is sampled and converted, the result is added to the complement of the compare value (ADC_CV).

Parameters
baseADC peripheral base address.
configPointer to "adc_hardware_compare_config_t" structure.
void ADC_SetFifoConfig ( ADC_Type *  base,
const adc_fifo_config_t config 
)

The ADC module supports FIFO operation to minimize the interrupts to CPU in order to reduce CPU loading in ADC interrupt service routines. This module contains two FIFOs to buffer analog input channels and analog results respectively.

Parameters
baseADC peripheral base address.
configPointer to "adc_fifo_config_t" structure.
void ADC_SetChannelConfig ( ADC_Type *  base,
const adc_channel_config_t config 
)

This operation triggers the conversion when in software trigger mode. When in hardware trigger mode, this API configures the channel while the external trigger source helps to trigger the conversion.

Parameters
baseADC peripheral base address.
configPointer to "adc_channel_config_t" structure.
bool ADC_GetChannelStatusFlags ( ADC_Type *  base)
Parameters
baseADC peripheral base address.
Returns
"True" means conversion has completed and "false" means conversion has not completed.
uint32_t ADC_GetStatusFlags ( ADC_Type *  base)
Parameters
baseADC peripheral base address.
Returns
Flags' mask if indicated flags are asserted. See "_adc_status_flags".
static void ADC_EnableAnalogInput ( ADC_Type *  base,
uint32_t  mask,
bool  enable 
)
inlinestatic

When a pin control register bit is set, the following conditions are forced for the associated MCU pin: -The output buffer is forced to its high impedance state. -The input buffer is disabled. A read of the I/O port returns a zero for any pin with its input buffer disabled. -The pullup is disabled.

Parameters
baseADC peripheral base address.
maskThe mask of the pin associated with channel ADx. Valid range is AD0:0x1U ~ AD15:0x8000U. For example: If enable AD0, AD1 and AD2 pins, mask should be set to 0x7U.
enableThe "true" means enabled, "false" means not enabled.
static uint32_t ADC_GetChannelConversionValue ( ADC_Type *  base)
inlinestatic
Parameters
baseADC peripheral base address.
Returns
Conversion value.