| Kinetis SDK API Reference Manual 1.0.0-beta Freescale Semiconductor, Inc.

- Introduction
- Related Pages
- API Usage

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Enumerations | Functions
ADC HAL Driver
Analog-to-Digital Converter (ADC)

The section describes the programming interface of the ADC HAL driver. More...

## Enumerations
enum | adc_clock_source_mode_t { kAdcClockSourceBusClk = 0U, kAdcClockSourceBusClk2 = 1U, kAdcClockSourceAlternate = 2U, kAdcClockSourceAsynchrounous = 3U }
| Defines the selection of the clock source that ADC module uses. More...
enum | adc_clock_divider_mode_t { kAdcClockDivider1 = 0U, kAdcClockDivider2 = 1U, kAdcClockDivider4 = 2U, kAdcClockDivider8 = 3U }
| Defines the selection of the clock divider. More...
enum | adc_reference_voltage_mode_t { kAdcVoltageVref = 0U, kAdcVoltageValt = 1U }
| Defines the selection of the voltage source that ADC module uses. More...
enum | adc_long_sample_mode_t { kAdcLongSampleExtra20 = 0U, kAdcLongSampleExtra12 = 1U, kAdcLongSampleExtra6 = 2U, kAdcLongSampleExtra2 = 3U }
| Defines the selection of the long sample extra cycle configuration. More...
enum | adc_resolution_mode_t { kAdcSingleDiff8or9 = 0U, kAdcSingleDiff12or13 = 1U, kAdcSingleDiff10or11 = 2U, kAdcSingleDiff16 = 3U }
| Defines the selection of the sample resolution. More...
enum | adc_group_mux_mode_t { kAdcChannelMuxA = 0U, kAdcChannelMuxB = 1U }
| Defines the selection of the A/B group mux. More...
enum | adc_hw_average_mode_t { kAdcHwAverageCount4 = 0U, kAdcHwAverageCount8 = 1U, kAdcHwAverageCount16 = 2U, kAdcHwAverageCount32 = 3U }
| Defines the selection of the time in a hard average mode. More...
enum | adc_channel_mode_t { kAdcChannel0 = 0U, kAdcChannell = 1U, kAdcChannel2 = 2U, kAdcChannel3 = 3U, kAdcChannel4 = 4U, kAdcChannel5 = 5U, kAdcChannel6 = 6U, kAdcChannel7 = 7U, kAdcChannel8 = 8U, kAdcChannel9 = 9U, kAdcChannel10 = 10U, kAdcChannel11 = 11U, kAdcChannel12 = 12U, kAdcChannel13 = 13U, kAdcChannel14 = 14U, kAdcChannel15 = 15U, kAdcChannel16 = 16U, kAdcChannel17 = 17U, kAdcChannel18 = 18U, kAdcChannel19 = 19U, kAdcChannel20 = 20U, kAdcChannel21 = 21U, kAdcChannel22 = 22U, kAdcChannel23 = 23U, kAdcChannelTemperature = 26U, kAdcChannelBandgap = 27U, kAdcChannelReferenceVoltageHigh = 29U, kAdcChannelReferenceVoltageLow = 30U, kAdcChannelDisable = 31U }
| Defines the selection of the channel inside the ADC module. More...
enum | adc_status_t { kStatus_ADC_Success = 0U, kStatus_ADC_InvalidArgument = 1U, kStatus_ADC_Failed = 2U }
| Defines the status returned from the ADC API. More...

## Functions
adc_status_t | adc_hal_start_calibration (uint32_t instance)
| Starts the calibration process. More...
static void | adc_hal_end_calibration (uint32_t instance)
| Ends the calibration process. More...
uint32_t | adc_hal_get_calibration_PG (uint32_t instance)
| Gets and calculates the plus-side calibration parameter. More...
static void | adc_hal_set_calibration_PG (uint32_t instance, uint32_t val)
| Sets the plus-side calibration parameter to the ADC instance. More...
uint32_t | adc_hal_get_calibration_MG (uint32_t instance)
| Gets and calculates the minus-side calibration parameter. More...
static void | adc_hal_set_calibration_MG (uint32_t instance, uint32_t val)
| Sets the minus-side calibration parameter to the ADC instance. More...
static uint32_t | adc_hal_get_calibration_offset (uint32_t instance)
| Gets the offset value after the auto-calibration. More...
static void | adc_hal_set_calibration_offset (uint32_t instance, uint32_t value)
| Sets the offset value for manual calibration. More...
static void | adc_hal_set_clock_source_mode (uint32_t instance, adc_clock_source_mode_t mode)
| Sets the selection of the clock source. More...
static void | adc_hal_configure_asynchronous_clock (uint32_t instance, bool isEnabled)
| Switches the asynchronous clock on/off. More...
static void | adc_hal_set_clock_divider_mode (uint32_t instance, adc_clock_divider_mode_t mode)
| Sets the selection of the clock divider. More...
static void | adc_hal_set_reference_voltage_mode (uint32_t instance, adc_reference_voltage_mode_t mode)
| Sets the selection of the reference voltage source. More...
static void | adc_hal_configure_high_speed (uint32_t instance, bool isEnabled)
| Switches the high speed mode on/off . More...
static void | adc_hal_configure_long_sample (uint32_t instance, bool isEnabled)
| Switch the long sample mode on/off. More...
static void | adc_hal_set_long_sample_mode (uint32_t instance, adc_long_sample_mode_t mode)
| Sets the selection of the long sample mode. More...
static void | adc_hal_configure_low_power (uint32_t instance, bool isEnabled)
| Switches the low power mode on/off. More...
static void | adc_hal_set_resolution_mode (uint32_t instance, adc_resolution_mode_t mode)
| Sets the selection of the resolution mode. More...
static void | adc_hal_configure_continuous_conversion (uint32_t instance, bool isEnabled)
| Switches the continuous conversion mode on/off. More...
static void | adc_hal_configure_hw_trigger (uint32_t instance, bool isEnabled)
| Switches the hardware trigger mode on/off . More...
static void | adc_hal_configure_hw_average (uint32_t instance, bool isEnabled)
| Switches the hardware average mode on/off. More...
static void | adc_hal_set_hw_average_mode (uint32_t instance, adc_hw_average_mode_t mode)
| Sets the selection of the hardware average mode. More...
static void | adc_hal_configure_hw_compare (uint32_t instance, bool isEnabled)
| Switches the hardware compare mode on/off. More...
static void | adc_hal_configure_hw_compare_greater (uint32_t instance, bool isEnabled)
| Switches the hardware compare greater configuration on/off . More...
static void | adc_hal_configure_hw_compare_in_range (uint32_t instance, bool isEnabled)
| Switches the hardware compare range configuration on/off . More...
static void | adc_hal_set_hw_compare_value1 (uint32_t instance, uint32_t value)
| Sets the value1 in the hardware compare. More...
static void | adc_hal_set_hw_compare_value2 (uint32_t instance, uint32_t value)
| Sets the value2 in the hardware compare. More...
static void | adc_hal_configure_dma (uint32_t instance, bool isEnabled)
| Switches the ADC DMA trigger on/off. More...
static void | adc_hal_disable (uint32_t instance, uint32_t group)
| Switches off the ADC channel conversion. More...
static void | adc_hal_enable (uint32_t instance, uint32_t group, adc_channel_mode_t mode, bool isDifferential)
| Sets the channel number and switches on the conversion. More...
static void | adc_hal_configure_interrupt (uint32_t instance, uint32_t group, bool isEnabled)
| Switches the ADC interrupt trigger on/off . More...
static bool | adc_hal_is_in_process (uint32_t instance)
| Checks whether the ADC is in process. More...
static bool | adc_hal_is_conversion_completed (uint32_t instance, uint32_t group)
| Checks whether the channel conversion is complete. More...
static bool | adc_hal_is_calibration_fail (uint32_t instance)
| Checks whether the calibration failed. More...
static uint32_t | adc_hal_get_conversion_value (uint32_t instance, uint32_t group)
| Gets the conversion value. More...
static void | adc_hal_set_group_mux (uint32_t instance, adc_group_mux_mode_t group)
| Sets the current group mux that executes the conversion. More...

### ADC hal driver

# Overview

The ADC HAL driver is used to mask the hardware and provide user a comprehensible way to use ADC hardware.

## Enumeration Type Documentation

enum adc_clock_source_mode_t

Enumerator
kAdcClockSourceBusClk | Use bus clock.
kAdcClockSourceBusClk2 | Use bus clock / 2.
kAdcClockSourceAlternate | Use the optional external clock.
kAdcClockSourceAsynchrounous | Use ADC's internal asynchronous clock.

enum adc_clock_divider_mode_t

Enumerator
kAdcClockDivider1 | Divide 1.
kAdcClockDivider2 | Divide 2.
kAdcClockDivider4 | Divide 4.
kAdcClockDivider8 | Divide 8.

enum adc_reference_voltage_mode_t

Enumerator
kAdcVoltageVref | Use V_REFH & V_REFL as ref source pin.
kAdcVoltageValt | Use V_ALTH & V_REFL as ref source pin.

enum adc_long_sample_mode_t

Enumerator
kAdcLongSampleExtra20 | Extra 20 cycles, total 24 cycles, default.
kAdcLongSampleExtra12 | Extra 12 cycles.
kAdcLongSampleExtra6 | Extra 6 cycles.
kAdcLongSampleExtra2 | Extra 2 cycles.

enum adc_resolution_mode_t

Enumerator
kAdcSingleDiff8or9 | 8-bits in single-end or 9-bits in differential.
kAdcSingleDiff12or13 | 12-bits in single-end or 13-bits in differential.
kAdcSingleDiff10or11 | 10-bits in single-end or 11-bits in differential.
kAdcSingleDiff16 | 16-bits both in single-end and differential.

enum adc_group_mux_mode_t

Enumerator
kAdcChannelMuxA | Mux A group is active.
kAdcChannelMuxB | Mux B group is active.

enum adc_hw_average_mode_t

Enumerator
kAdcHwAverageCount4 | Average the result after accumulating 4 conversion.
kAdcHwAverageCount8 | Average the result after accumulating 8 conversion.
kAdcHwAverageCount16 | Average the result after accumulating 16 conversion.
kAdcHwAverageCount32 | Average the result after accumulating 32 conversion.

enum adc_channel_mode_t

Enumerator
kAdcChannel0 | ADC channel 0.
kAdcChannell | ADC channel 1.
kAdcChannel2 | ADC channel 2.
kAdcChannel3 | ADC channel 3.
kAdcChannel4 | ADC channel 4.
kAdcChannel5 | ADC channel 5.
kAdcChannel6 | ADC channel 6.
kAdcChannel7 | ADC channel 7.
kAdcChannel8 | ADC channel 8.
kAdcChannel9 | ADC channel 9.
kAdcChannel10 | ADC channel 10.
kAdcChannel11 | ADC channel 11.
kAdcChannel12 | ADC channel 12.
kAdcChannel13 | ADC channel 13.
kAdcChannel14 | ADC channel 14.
kAdcChannel15 | ADC channel 15.
kAdcChannel16 | ADC channel 16.
kAdcChannel17 | ADC channel 17.
kAdcChannel18 | ADC channel 18.
kAdcChannel19 | ADC channel 19.
kAdcChannel20 | ADC channel 20.
kAdcChannel21 | ADC channel 21.
kAdcChannel22 | ADC channel 22.
kAdcChannel23 | ADC channel 23.
kAdcChannelTemperature | Internal temperature sensor.
kAdcChannelBandgap | Internal band gap.
kAdcChannelReferenceVoltageHigh | Internal ref voltage High.
kAdcChannelReferenceVoltageLow | Internal ref voltage L.
kAdcChannelDisable | Disable the sample process.

enum adc_status_t

Enumerator
kStatus_ADC_InvalidArgument | Parameter is not available for the current configuration.
kStatus_ADC_Failed | Function operation failed.

## Function Documentation

adc_status_t adc_hal_start_calibration | ( | uint32_t | instance | ) |

This function clears the calibration flag bit and sets the enable bit to start the calibration.

Parameters

  instance | ADC instance ID.

static void adc_hal_end_calibration | ( | uint32_t | instance | ) |
| inline static

This function clears the calibration enable bit to end the calibration.

Parameters

  instance | ADC instance ID.

uint32_t adc_hal_get_calibration_PG | ( | uint32_t | instance | ) |

This function gets the CLP0 - CLP4 and CLPS, accumulates them, and returns the value that can be set to the PG directly.

Parameters

  instance | ADC instance ID.

Returns
  the value that can be set to PG directly.

static void adc_hal_set_calibration_PG | ( | uint32_t | instance,
|  | uint32_t | val
| ) |  |
| inline static

This function sets the PG register directly.

Parameters

  instance | ADC instance ID.
  val | the value that can be set to PG directly.

uint32_t adc_hal_get_calibration_MG | ( | uint32_t | instance | ) |

This function gets the CLM0 - CLM4 and CLMS, accumulates them, and returns the value that can be set to the MG directly.

Parameters

  instance | ADC instance ID.

Returns
  the value that can be set to MG directly.

static void adc_hal_set_calibration_MG | ( | uint32_t | instance,
|  | uint32_t | val
| ) |  |
| inline static

This function sets the MG register directly.

Parameters

  instance | ADC instance ID.
  val | the value that can be set to MG directly.

static uint32_t adc_hal_get_calibration_offset | ( | uint32_t | instance | ) |
| inline static

If the user wants to adjust the offset value according to the application, the origin offset value will be a reference.

Parameters

  instance | ADC instance ID.

Returns
  The offset value created by auto-calibration.

static void adc_hal_set_calibration_offset | ( | uint32_t | instance,
|  | uint32_t | value
| ) |  |
| inline static

This function is to set the user selected or calibration generated offset error correction value. The value set here is subtracted from the conversion and the result is transferred into the result registers (Rn). If the result is above the maximum or below the minimum result value, it is forced to the appropriate limit for the current mode of operation.

Parameters

  instance | ADC instance ID.
  value | The manual offset value.

static void adc_hal_set_clock_source_mode | ( | uint32_t | instance,
|  | adc_clock_source_mode_t | mode
| ) |  |
| inline static

The selection of ADC clock source can see to the type definition of adc_clock_source_mode_t. This function selects the input clock source to generate the internal clock, ADCK. Note that when the ADACK clock source is selected, it does not have to be activated prior to the start of the conversion. When it is selected and it is not activated prior to start a conversion , the asynchronous clock will be activated at the start of a conversion and shuts off when conversions are terminated. In this case, there is an associated clock startup delay each time the clock source is re-activated.

Parameters

  instance | ADC instance ID.
  mode | The indicated clock source mode.

static void adc_hal_configure_asynchronous_clock | ( | uint32_t | instance,
|  | bool | isEnabled
| ) |  |
| inline static

When enables the ADC's asynchronous clock source and the clock source output regardless of the conversion and input clock select status of the ADC. Based on MCU configuration, the asynchronous clock may be used by other modules. Setting this mode allows the clock to be used even while the ADC is idle or operating from a different clock source. Also, latency of initiating a single or first-continuous conversion with the asynchronous clock selected is reduced since the ADACK clock is already operational.

Parameters

  instance | ADC instance ID.
  isEnabled | The switcher.

static void adc_hal_set_clock_divider_mode | ( | uint32_t | instance,
|  | adc_clock_divider_mode_t | mode
| ) |  |
| inline static

The selection of ADC's clock divider can see to the type definition of the adc_clock_divider_mode_t. This function selects the divide ratio used by the ADC to generate the internal clock ADCK.

Parameters

  instance | ADC instance ID.
  mode | The selection of the divider.

static void adc_hal_set_reference_voltage_mode | ( | uint32_t | instance,
|  | adc_reference_voltage_mode_t | mode
| ) |  |
| inline static

The selection of ADC's reference voltage can see to the type definition of adc_reference_voltage_mode_t. This function selects the voltage reference source used for conversions.

Parameters

  instance | ADC instance ID.
  mode | The selection of the reference voltage source.

static void adc_hal_configure_high_speed | ( | uint32_t | instance,
|  | bool | isEnabled
| ) |  |
| inline static

This function configures the ADC for high speed operations. The conversion sequence is altered (2 ADCK cycles added to the conversion time) to allow higher speed conversion clocks.

Parameters

  instance | ADC instance ID.
  isEnabled | The switcher.

static void adc_hal_configure_long_sample | ( | uint32_t | instance,
|  | bool | isEnabled
| ) |  |
| inline static

This function selects between the different sample times based on the conversion mode selected. It adjusts the sample period to allow higher impedance inputs to be accurately sampled or to maximize conversion speed for lower impedance inputs. Longer sample times can also be used to lower overall power consumption if the continuous conversions are enabled and the high conversion rates are not required. In fact this will be able to charge the SAR in a timely manner way without affecting the SAR configuration.

Parameters

  instance | ADC instance ID.
  isEnabled | The switcher.

static void adc_hal_set_long_sample_mode | ( | uint32_t | instance,
|  | adc_long_sample_mode_t | mode
| ) |  |
| inline static

The selection of ADC long sample mode can see to the type definition of the adc_long_sample_mode_t. This function selects the long sample mode that indicating the different count of extra ADCK cycles are needed.

Parameters

  instance | ADC instance ID.
  mode | The selection of long sample mode.

static void adc_hal_configure_low_power | ( | uint32_t | instance,
|  | bool | isEnabled
| ) |  |
| inline static

This function controls the power configuration of the successive approximation converter. This optimizes power consumption when higher sample rates are not required.

Parameters

  instance | ADC instance ID.
  isEnabled | The switcher.

static void adc_hal_set_resolution_mode | ( | uint32_t | instance,
|  | adc_resolution_mode_t | mode
| ) |  |
| inline static

The selection of ADC resolution mode can see to the type definition of the adc_resolution_mode_t. This function selects the ADC resolution mode. Note that the differential conversion is different to single-end conversion.

Parameters

  instance | ADC instance ID.
  mode | The selection of resolution mode.

static void adc_hal_configure_continuous_conversion | ( | uint32_t | instance,
|  | bool | isEnabled
| ) |  |
| inline static

This function configures the continuous conversions or sets of conversions if the hardware average function is enabled after initiating a conversion.

Parameters

  instance | ADC instance ID.
  isEnabled | The switcher.

static void adc_hal_configure_hw_trigger | ( | uint32_t | instance,
|  | bool | isEnabled
| ) |  |
| inline static

This function selects the type of trigger used for initiating a conversion. Two types of triggers can be selected: software trigger and hardware trigger. When software trigger is selected, a conversion is initiated following a write to SC1A. When hardware trigger is selected, a conversion is initiated following the assertion of the external events. The event will come through the signal on the line of ADHWT input after a pulse of ADHWTSn input inside SOC.

Parameters

  instance | ADC instance ID.
  isEnabled | The switcher.

static void adc_hal_configure_hw_average | ( | uint32_t | instance,
|  | bool | isEnabled
| ) |  |
| inline static

This function enables the hardware average function of the ADC.

Parameters

  instance | ADC instance ID.
  isEnabled | The switcher.

static void adc_hal_set_hw_average_mode | ( | uint32_t | instance,
|  | adc_hw_average_mode_t | mode
| ) |  |
| inline static

The selection of ADC hardware average mode can see to the type definition of the adc_hw_average_mode_t. This function determines how many ADC conversions are averaged to create the ADC average result.

Parameters

  instance | ADC instance ID.
  mode | The selection of hardware average mode.

static void adc_hal_configure_hw_compare | ( | uint32_t | instance,
|  | bool | isEnabled
| ) |  |
| inline static

This function enables the compare function.

Parameters

  instance | ADC instance ID.
  isEnabled | The switcher.

static void adc_hal_configure_hw_compare_greater | ( | uint32_t | instance,
|  | bool | isEnabled
| ) |  |
| inline static

This function configures the compare function to check the conversion result relative to the compare value register(s) (CV1 and CV2). To enable will configure greater than or equal to threshold, outside range inclusive and inside range inclusive functionality based on the values placed in the CV1 and CV2 registers. Otherwise, it will configure less than threshold, outside range not inclusive and inside range not inclusive functionality based on the values placed in the CV1 and CV2 registers.

Parameters

  instance | ADC instance ID.
  isEnabled | The switcher.

static void adc_hal_configure_hw_compare_in_range | ( | uint32_t | instance,
|  | bool | isEnabled
| ) |  |
| inline static

This function configures the compare function to check if the conversion result of the input being monitored is either inside or outside the range formed by the compare value registers (CV1 and CV2). However, the actual compare range should be determined alone with the function of adc_hal_configure_hw_compare_greater() as well.

Parameters

  instance | ADC instance ID.
  isEnabled | The switcher.

static void adc_hal_set_hw_compare_value1 | ( | uint32_t | instance,
|  | uint32_t | value
| ) |  |
| inline static

This function sets the value of the CV1 register.

Parameters

  instance | ADC instance ID.
  value | The setting value.

static void adc_hal_set_hw_compare_value2 | ( | uint32_t | instance,
|  | uint32_t | value
| ) |  |
| inline static

This function sets the value of the CV2 register.

Parameters

  instance | ADC instance ID.
  value | The setting value.

static void adc_hal_configure_dma | ( | uint32_t | instance,
|  | bool | isEnabled
| ) |  |
| inline static

When DMA is enabled, it asserts the ADC DMA request during the ADC conversion complete event noted by the assertion of any of the ADC COCO flags.

Parameters

  instance | ADC instance ID.
  isEnabled | The switcher.

static void adc_hal_disable | ( | uint32_t | instance,
|  | uint32_t | group
| ) |  |
| inline static

Here the "NUll" channel is set to the conversion channel.

Parameters

  instance | ADC instance ID.
  group | The group mux index.

static void adc_hal_enable | ( | uint32_t | instance,
|  | uint32_t | group,
|  | adc_channel_mode_t | mode,
|  | bool | isDifferential
| ) |  |
| inline static

When the available channel is set, the conversion begins to execute.

Parameters

  instance | ADC instance ID.
  group | The group mux index.
  mode | The selection of channel number.
  isDifferential | the selection of differential input.

static void adc_hal_configure_interrupt | ( | uint32_t | instance,
|  | uint32_t | group,
|  | bool | isEnabled
| ) |  |
| inline static

This function enables conversion complete interrupts. When COCO is set while the respective AIEN is high, an interrupt is asserted.

Parameters

  instance | ADC instance ID.
  group | The group mux index.
  inEnable | The switcher.

static bool adc_hal_is_in_process | ( | uint32_t | instance | ) |
| inline static

This function indicates that a conversion or hardware averaging is in progress. ADACT is set when a conversion is initiated and cleared when a conversion is completed or aborted. Note that if the continuous conversion is been use, this function will always return true.

Parameters

  instance | ADC instance ID.

Returns
  true if it is.

static bool adc_hal_is_conversion_completed | ( | uint32_t | instance,
|  | uint32_t | group
| ) |  |
| inline static

This function indicates whether each conversion is completed.

Parameters

  instance | ADC instance ID.
  group | The grout mux index.

Returns
  true if it is.

static bool adc_hal_is_calibration_fail | ( | uint32_t | instance | ) |
| inline static

This function displays the result of the calibration sequence.

Parameters

  instance | ADC instance ID.

Returns
  true if it is.

static uint32_t adc_hal_get_conversion_value | ( | uint32_t | instance,
|  | uint32_t | group
| ) |  |
| inline static

This function returns the conversion value kept in the Rn Register. Unused bits in the Rn register are cleared in unsigned right justified modes and carry the sign bit (MSB) in sign extended 2's complement modes.

Parameters

  instance | ADC instance ID.
  group | The group mux index.

static void adc_hal_set_group_mux | ( | uint32_t | instance,
|  | adc_group_mux_mode_t | group
| ) |  |
| inline static

ADC Mux select bit changes the ADC group setting to select between alternate sets of ADC channels. It will activate group A or group B.

Parameters

  instance | ADC instance ID.
  group | The group mux index.