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
|
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...
|
|
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 |
int16_t adc12_hardware_compare_config_t::value1 |
int16_t adc12_hardware_compare_config_t::value2 |
struct adc12_channel_config_t |
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 |
#define FSL_ADC12_DRIVER_VERSION (MAKE_VERSION(2, 0, 2)) |
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.
|
- Parameters
-
base | ADC12 peripheral base address. |
config | Pointer to "adc12_config_t" structure. |
void ADC12_Deinit |
( |
ADC_Type * |
base | ) |
|
- Parameters
-
base | ADC12 peripheral base address. |
This function initializes the converter configuration structure with an available settings. The default values are:
Example:
config->sampleClockCount = 12U;
config->enableContinuousConversion = false;
- Parameters
-
config | Pointer to "adc12_config_t" structure. |
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
-
base | ADC12 peripheral base address. |
channelGroup | Channel group index. |
config | Pointer to "adc12_channel_config_t" structure. |
static uint32_t ADC12_GetChannelConversionValue |
( |
ADC_Type * |
base, |
|
|
uint32_t |
channelGroup |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | ADC12 peripheral base address. |
channelGroup | Channel group index. |
- Returns
- Conversion value.
uint32_t ADC12_GetChannelStatusFlags |
( |
ADC_Type * |
base, |
|
|
uint32_t |
channelGroup |
|
) |
| |
- Parameters
-
base | ADC12 peripheral base address. |
channelGroup | Channel 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
-
base | ADC12 peripheral base address. |
- Return values
-
kStatus_Success | Calibration is done successfully. |
kStatus_Fail | Calibration 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
-
base | ADC12 peripheral base address. |
value | Offset 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
-
base | ADC12 peripheral base address. |
value | Gain value. |
static void ADC12_EnableHardwareTrigger |
( |
ADC_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | ADC12 peripheral base address. |
enable | Switcher of hardware trigger feature. "true" means to enable, "false" means not. |
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
-
base | ADC12 peripheral base address. |
config | Pointer to "adc12_hardware_compare_config_t" structure. Pass "NULL" to disable the feature. |
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
-
base | ADC12 peripheral base address. |
mode | Setting hardware average mode. See to "adc12_hardware_average_mode_t". |
uint32_t ADC12_GetStatusFlags |
( |
ADC_Type * |
base | ) |
|
- Parameters
-
base | ADC12 peripheral base address. |
- Returns
- Flags' mask if indicated flags are asserted. See to "_adc12_status_flags".