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

Overview

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

The ADC12 driver is created to help the user better operate the ADC12 module. This driver can be considered a basic analog-to-digital converter with advanced features. The APIs for basic operations can make the ADC12 work as a general converter, which can convert the analog input to be a digital value. The APIs for advanced operations can be used as the plug-in function based on the basic operations. They can provide more ways to process the converter's conversion results, such DMA trigger, hardware compare, hardware average, and so on.

Note that channel 26 of ADC12 is connected to a internal temperature sensor of the module. If you want to get the best conversion result of the temperature value, set the field "sampleClockCount" in the structure "adc12_config_t" to be maximum value when you call the API "ADC12_Init()". This field indicates the sample time of the analog input signal. A longer sample time makes the conversion result of the analog input signal more stable and accurate.

Function groups

Initialization and deinitialization

This function group implement ADC12 initialization and deinitialization API.

Basic Operations

This function group implement basic ADC12 operation API.

Advanced Operations

This function group implement advanced ADC12 operation API.

Typical use case

Normal Configuration

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

Interrupt Configuration

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

Data Structures

struct  adc12_config_t
 Converter configuration. More...
 
struct  adc12_hardware_compare_config_t
 Hardware compare configuration. More...
 
struct  adc12_channel_config_t
 Channel conversion configuration. More...
 

Macros

#define FSL_ADC12_DRIVER_VERSION   (MAKE_VERSION(2, 0, 2))
 ADC12 driver version. More...
 

Enumerations

enum  _adc12_channel_status_flags { kADC12_ChannelConversionCompletedFlag = ADC_SC1_COCO_MASK }
 Channel status flags' mask. More...
 
enum  _adc12_status_flags {
  kADC12_ActiveFlag = ADC_SC2_ADACT_MASK,
  kADC12_CalibrationFailedFlag = (ADC_SC2_ADACT_MASK << 1U)
}
 Converter status flags' mask. More...
 
enum  adc12_clock_divider_t {
  kADC12_ClockDivider1 = 0U,
  kADC12_ClockDivider2 = 1U,
  kADC12_ClockDivider4 = 2U,
  kADC12_ClockDivider8 = 3U
}
 Clock divider for the converter. More...
 
enum  adc12_resolution_t {
  kADC12_Resolution8Bit = 0U,
  kADC12_Resolution12Bit = 1U,
  kADC12_Resolution10Bit = 2U
}
 Converter's resolution. More...
 
enum  adc12_clock_source_t {
  kADC12_ClockSourceAlt0 = 0U,
  kADC12_ClockSourceAlt1 = 1U,
  kADC12_ClockSourceAlt2 = 2U,
  kADC12_ClockSourceAlt3 = 3U
}
 Conversion clock source. More...
 
enum  adc12_reference_voltage_source_t {
  kADC12_ReferenceVoltageSourceVref = 0U,
  kADC12_ReferenceVoltageSourceValt = 1U
}
 Reference voltage source. More...
 
enum  adc12_hardware_average_mode_t {
  kADC12_HardwareAverageCount4 = 0U,
  kADC12_HardwareAverageCount8 = 1U,
  kADC12_HardwareAverageCount16 = 2U,
  kADC12_HardwareAverageCount32 = 3U,
  kADC12_HardwareAverageDisabled = 4U
}
 Hardware average mode. More...
 
enum  adc12_hardware_compare_mode_t {
  kADC12_HardwareCompareMode0 = 0U,
  kADC12_HardwareCompareMode1 = 1U,
  kADC12_HardwareCompareMode2 = 2U,
  kADC12_HardwareCompareMode3 = 3U
}
 Hardware compare mode. More...
 

Initialization

void ADC12_Init (ADC_Type *base, const adc12_config_t *config)
 Initialize the ADC12 module. More...
 
void ADC12_Deinit (ADC_Type *base)
 De-initialize the ADC12 module. More...
 
void ADC12_GetDefaultConfig (adc12_config_t *config)
 Gets an available pre-defined settings for converter's configuration. More...
 

Basic Operations

void ADC12_SetChannelConfig (ADC_Type *base, uint32_t channelGroup, const adc12_channel_config_t *config)
 Configure the conversion channel. More...
 
static uint32_t ADC12_GetChannelConversionValue (ADC_Type *base, uint32_t channelGroup)
 Get the conversion value. More...
 
uint32_t ADC12_GetChannelStatusFlags (ADC_Type *base, uint32_t channelGroup)
 Get the status flags of channel. More...
 

Advanced Operations

status_t ADC12_DoAutoCalibration (ADC_Type *base)
 Automate the hardware calibration. More...
 
static void ADC12_SetOffsetValue (ADC_Type *base, uint32_t value)
 Set the offset value for the conversion result. More...
 
static void ADC12_SetGainValue (ADC_Type *base, uint32_t value)
 Set the gain value for the conversion result. More...
 
static void ADC12_EnableHardwareTrigger (ADC_Type *base, bool enable)
 Enable of disable the hardware trigger mode. More...
 
void ADC12_SetHardwareCompareConfig (ADC_Type *base, const adc12_hardware_compare_config_t *config)
 Configure the hardware compare mode. More...
 
void ADC12_SetHardwareAverage (ADC_Type *base, adc12_hardware_average_mode_t mode)
 Set the hardware average mode. More...
 
uint32_t ADC12_GetStatusFlags (ADC_Type *base)
 Get the status flags of the converter. More...
 

Data Structure Documentation

struct adc12_config_t

Data Fields

adc12_reference_voltage_source_t referenceVoltageSource
 Select the reference voltage source. More...
 
adc12_clock_source_t clockSource
 Select the input clock source to converter. More...
 
adc12_clock_divider_t clockDivider
 Select the divider of input clock source. More...
 
adc12_resolution_t resolution
 Select the sample resolution mode. More...
 
uint32_t sampleClockCount
 Select the sample clock count. More...
 
bool enableContinuousConversion
 Enable continuous conversion mode. More...
 

Field Documentation

adc12_reference_voltage_source_t adc12_config_t::referenceVoltageSource
adc12_clock_source_t adc12_config_t::clockSource
adc12_clock_divider_t adc12_config_t::clockDivider
adc12_resolution_t adc12_config_t::resolution
uint32_t adc12_config_t::sampleClockCount

Add its value may improve the stability of the conversion result.

bool adc12_config_t::enableContinuousConversion
struct adc12_hardware_compare_config_t

Data Fields

adc12_hardware_compare_mode_t hardwareCompareMode
 Select the hardware compare mode. More...
 
int16_t value1
 Setting value1 for hardware compare mode. More...
 
int16_t value2
 Setting value2 for hardware compare mode. More...
 

Field Documentation

adc12_hardware_compare_mode_t adc12_hardware_compare_config_t::hardwareCompareMode
int16_t adc12_hardware_compare_config_t::value1
int16_t adc12_hardware_compare_config_t::value2
struct adc12_channel_config_t

Data Fields

uint32_t channelNumber
 Setting the conversion channel number. More...
 
bool enableInterruptOnConversionCompleted
 Generate a interrupt request once the conversion is completed. More...
 

Field Documentation

uint32_t adc12_channel_config_t::channelNumber

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

bool adc12_channel_config_t::enableInterruptOnConversionCompleted

Macro Definition Documentation

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

Version 2.0.2.

Enumeration Type Documentation

Enumerator
kADC12_ChannelConversionCompletedFlag 

Conversion done.

Enumerator
kADC12_ActiveFlag 

Converter is active.

kADC12_CalibrationFailedFlag 

Calibration is failed.

Enumerator
kADC12_ClockDivider1 

For divider 1 from the input clock to the module.

kADC12_ClockDivider2 

For divider 2 from the input clock to the module.

kADC12_ClockDivider4 

For divider 4 from the input clock to the module.

kADC12_ClockDivider8 

For divider 8 from the input clock to the module.

Enumerator
kADC12_Resolution8Bit 

8 bit resolution.

kADC12_Resolution12Bit 

12 bit resolution.

kADC12_Resolution10Bit 

10 bit resolution.

Enumerator
kADC12_ClockSourceAlt0 

Alternate clock 1 (ADC_ALTCLK1).

kADC12_ClockSourceAlt1 

Alternate clock 2 (ADC_ALTCLK2).

kADC12_ClockSourceAlt2 

Alternate clock 3 (ADC_ALTCLK3).

kADC12_ClockSourceAlt3 

Alternate clock 4 (ADC_ALTCLK4).

Enumerator
kADC12_ReferenceVoltageSourceVref 

For external pins pair of VrefH and VrefL.

kADC12_ReferenceVoltageSourceValt 

For alternate reference pair of ValtH and ValtL.

Enumerator
kADC12_HardwareAverageCount4 

For hardware average with 4 samples.

kADC12_HardwareAverageCount8 

For hardware average with 8 samples.

kADC12_HardwareAverageCount16 

For hardware average with 16 samples.

kADC12_HardwareAverageCount32 

For hardware average with 32 samples.

kADC12_HardwareAverageDisabled 

Disable the hardware average feature.

Enumerator
kADC12_HardwareCompareMode0 

x < value1.

kADC12_HardwareCompareMode1 

x > value1.

kADC12_HardwareCompareMode2 

if value1 <= value2, then x < value1 || x > value2; else, value1 > x > value2.

kADC12_HardwareCompareMode3 

if value1 <= value2, then value1 <= x <= value2; else x >= value1 || x <= value2.

Function Documentation

void ADC12_Init ( ADC_Type *  base,
const adc12_config_t config 
)
Parameters
baseADC12 peripheral base address.
configPointer to "adc12_config_t" structure.
void ADC12_Deinit ( ADC_Type *  base)
Parameters
baseADC12 peripheral base address.
void ADC12_GetDefaultConfig ( adc12_config_t config)

This function initializes the converter configuration structure with an available settings. The default values are:

Example:

config->referenceVoltageSource = kADC12_ReferenceVoltageSourceVref;
config->clockSource = kADC12_ClockSourceAlt0;
config->clockDivider = kADC12_ClockDivider1;
config->resolution = kADC12_Resolution8Bit;
config->sampleClockCount = 12U;
config->enableContinuousConversion = false;
Parameters
configPointer to "adc12_config_t" structure.
void ADC12_SetChannelConfig ( ADC_Type *  base,
uint32_t  channelGroup,
const adc12_channel_config_t config 
)

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

Note that the "Channel Group" has a detailed description. To allow sequential conversions of the ADC to be triggered by internal peripherals, the ADC can have more than one group of status and control register, one for each conversion. The channel group parameter indicates which group of registers are used, channel group 0 is for Group A registers and channel group 1 is for Group B registers. The channel groups are used in a "ping-pong" approach to control the ADC operation. At any time, only one of the channel groups is actively controlling ADC conversions. Channel group 0 is used for both software and hardware trigger modes of operation. Channel groups 1 and greater indicate potentially multiple channel group registers for use only in hardware trigger mode. See the chip configuration information in the MCU reference manual about the number of SC1n registers (channel groups) specific to this device. None of the channel groups 1 or greater are used for software trigger operation and therefore writes to these channel groups do not initiate a new conversion. Updating channel group 0 while a different channel group is actively controlling a conversion is allowed and vice versa. Writing any of the channel group registers while that specific channel group is actively controlling a conversion aborts the current conversion.

Parameters
baseADC12 peripheral base address.
channelGroupChannel group index.
configPointer to "adc12_channel_config_t" structure.
static uint32_t ADC12_GetChannelConversionValue ( ADC_Type *  base,
uint32_t  channelGroup 
)
inlinestatic
Parameters
baseADC12 peripheral base address.
channelGroupChannel group index.
Returns
Conversion value.
uint32_t ADC12_GetChannelStatusFlags ( ADC_Type *  base,
uint32_t  channelGroup 
)
Parameters
baseADC12 peripheral base address.
channelGroupChannel group index.
Returns
Flags' mask if indicated flags are asserted. See to "_adc12_channel_status_flags".
status_t ADC12_DoAutoCalibration ( ADC_Type *  base)

This auto calibration helps to adjust the gain automatically according to the converter's working environment. Execute the calibration before conversion. Note that the software trigger should be used during calibration.

Note
The calibration function has bug in the SOC. The calibration failed flag may be set after calibration process even if you configure the ADC12 as the reference manual correctly. It is a known issue now and may be fixed in the future.
Parameters
baseADC12 peripheral base address.
Return values
kStatus_SuccessCalibration is done successfully.
kStatus_FailCalibration is failed.
static void ADC12_SetOffsetValue ( ADC_Type *  base,
uint32_t  value 
)
inlinestatic

This offset value takes effect on the conversion result. If the offset value is not zero, the conversion result is substracted by it.

Parameters
baseADC12 peripheral base address.
valueOffset value.
static void ADC12_SetGainValue ( ADC_Type *  base,
uint32_t  value 
)
inlinestatic

This gain value takes effect on the conversion result. If the gain value is not zero, the conversion result is amplified as it.

Parameters
baseADC12 peripheral base address.
valueGain value.
static void ADC12_EnableHardwareTrigger ( ADC_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseADC12 peripheral base address.
enableSwitcher of hardware trigger feature. "true" means to enable, "false" means not.
void ADC12_SetHardwareCompareConfig ( ADC_Type *  base,
const adc12_hardware_compare_config_t config 
)

The hardware compare mode provides a way to process the conversion result automatically by hardware. Only the result in compare range is available. To compare the range, see "adc12_hardware_compare_mode_t", or the reference manual document for more detailed information.

Parameters
baseADC12 peripheral base address.
configPointer to "adc12_hardware_compare_config_t" structure. Pass "NULL" to disable the feature.
void ADC12_SetHardwareAverage ( ADC_Type *  base,
adc12_hardware_average_mode_t  mode 
)

Hardware average mode provides a way to process the conversion result automatically by hardware. The multiple conversion results are accumulated and averaged internally. This aids to get more accurate conversion result.

Parameters
baseADC12 peripheral base address.
modeSetting hardware average mode. See to "adc12_hardware_average_mode_t".
uint32_t ADC12_GetStatusFlags ( ADC_Type *  base)
Parameters
baseADC12 peripheral base address.
Returns
Flags' mask if indicated flags are asserted. See to "_adc12_status_flags".