adc_driver.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include "device_registers.h"

Go to the source code of this file.

Data Structures

struct  adc_converter_config_t
 Defines the converter configuration. More...
 
struct  adc_compare_config_t
 Defines the hardware compare configuration. More...
 
struct  adc_average_config_t
 Defines the hardware average configuration. More...
 
struct  adc_chan_config_t
 Defines the control channel configuration. More...
 
struct  adc_calibration_t
 Defines the user calibration configuration. More...
 

Enumerations

enum  adc_clk_divide_t { ADC_CLK_DIVIDE_1 = 0x00U, ADC_CLK_DIVIDE_2 = 0x01U, ADC_CLK_DIVIDE_4 = 0x02U, ADC_CLK_DIVIDE_8 = 0x03U }
 Clock Divider selection. More...
 
enum  adc_resolution_t { ADC_RESOLUTION_8BIT = 0x00U, ADC_RESOLUTION_12BIT = 0x01U, ADC_RESOLUTION_10BIT = 0x02U }
 Conversion resolution selection. More...
 
enum  adc_input_clock_t { ADC_CLK_ALT_1 = 0x00U, ADC_CLK_ALT_2 = 0x01U, ADC_CLK_ALT_3 = 0x02U, ADC_CLK_ALT_4 = 0x03U }
 Input clock source selection. More...
 
enum  adc_trigger_t { ADC_TRIGGER_SOFTWARE = 0x00U, ADC_TRIGGER_HARDWARE = 0x01U }
 Trigger type selection. More...
 
enum  adc_pretrigger_sel_t { ADC_PRETRIGGER_SEL_PDB = 0x00U, ADC_PRETRIGGER_SEL_TRGMUX = 0x01U, ADC_PRETRIGGER_SEL_SW = 0x02U }
 Pretrigger types selectable from Trigger Latching and Arbitration Unit. More...
 
enum  adc_trigger_sel_t { ADC_TRIGGER_SEL_PDB = 0x00U, ADC_TRIGGER_SEL_TRGMUX = 0x01U }
 Trigger source selectable from Trigger Latching and Arbitration Unit. More...
 
enum  adc_sw_pretrigger_t {
  ADC_SW_PRETRIGGER_DISABLED = 0x00U, ADC_SW_PRETRIGGER_0 = 0x04U, ADC_SW_PRETRIGGER_1 = 0x05U, ADC_SW_PRETRIGGER_2 = 0x06U,
  ADC_SW_PRETRIGGER_3 = 0x07U
}
 Software pretriggers which may be set from Trigger Latching and Arbitration Unit. More...
 
enum  adc_voltage_reference_t { ADC_VOLTAGEREF_VREF = 0x00U, ADC_VOLTAGEREF_VALT = 0x01U }
 Voltage reference selection. More...
 
enum  adc_average_t { ADC_AVERAGE_4 = 0x00U, ADC_AVERAGE_8 = 0x01U, ADC_AVERAGE_16 = 0x02U, ADC_AVERAGE_32 = 0x03U }
 Hardware average selection. More...
 
enum  adc_inputchannel_t {
  ADC_INPUTCHAN_EXT0 = 0x00U, ADC_INPUTCHAN_EXT1 = 0x01U, ADC_INPUTCHAN_EXT2 = 0x02U, ADC_INPUTCHAN_EXT3 = 0x03U,
  ADC_INPUTCHAN_EXT4 = 0x04U, ADC_INPUTCHAN_EXT5 = 0x05U, ADC_INPUTCHAN_EXT6 = 0x06U, ADC_INPUTCHAN_EXT7 = 0x07U,
  ADC_INPUTCHAN_EXT8 = 0x08U, ADC_INPUTCHAN_EXT9 = 0x09U, ADC_INPUTCHAN_EXT10 = 0x0AU, ADC_INPUTCHAN_EXT11 = 0x0BU,
  ADC_INPUTCHAN_EXT12 = 0x0CU, ADC_INPUTCHAN_EXT13 = 0x0DU, ADC_INPUTCHAN_EXT14 = 0x0EU, ADC_INPUTCHAN_EXT15 = 0x0FU,
  ADC_INPUTCHAN_DISABLED = 0x1Fu, ADC_INPUTCHAN_INT0 = 0x15, ADC_INPUTCHAN_INT1 = 0x16, ADC_INPUTCHAN_INT2 = 0x17,
  ADC_INPUTCHAN_INT3 = 0x1C, ADC_INPUTCHAN_TEMP = 0x1A, ADC_INPUTCHAN_BANDGAP = 0x1B, ADC_INPUTCHAN_VREFSH = 0x1D,
  ADC_INPUTCHAN_VREFSL = 0x1E, ADC_INPUTCHAN_SUPPLY_VDD = 0xF00U, ADC_INPUTCHAN_SUPPLY_VDDA = 0xF01U, ADC_INPUTCHAN_SUPPLY_VREFH = 0xF02U,
  ADC_INPUTCHAN_SUPPLY_VDD_3V = 0xF03U, ADC_INPUTCHAN_SUPPLY_VDD_FLASH_3V = 0xF04U, ADC_INPUTCHAN_SUPPLY_VDD_LV = 0xF05U
}
 Enumeration of input channels assignable to a control channel.
Note 0: entries in this enum are affected by ::FEATURE_ADC_NUM_EXT_CHANS, which is device dependent and controlled from "device_name"_features.h file. More...
 
enum  adc_latch_clear_t { ADC_LATCH_CLEAR_WAIT, ADC_LATCH_CLEAR_FORCE }
 Defines the trigger latch clear method Implements : adc_latch_clear_t_Class. More...
 

Functions

Converter

Converter specific methods. These are used to configure and use the A/D Converter specific functionality, including:

  • clock input and divider
  • sample time in A/D clocks
  • resolution
  • trigger source
  • voltage reference
  • enable DMA
  • enable continuous conversion on one channel

To start a conversion, a control channel (see Channel Configuration) and a trigger source must be configured. Once a conversion is started, the user application can wait for it to be finished by calling the ADC_DRV_WaitConvDone() function.

Only the first control channel can be triggered by software. To start a conversion in this case, an input channel must be written in the channel selection register using the ADC_DRV_ConfigChan() method. Writing a value to the control channel while a conversion is being performed on that channel will start a new conversion.

void ADC_DRV_InitConverterStruct (adc_converter_config_t *const config)
 Initializes the converter configuration structure. More...
 
void ADC_DRV_ConfigConverter (const uint32_t instance, const adc_converter_config_t *const config)
 Configures the converter with the given configuration structure. More...
 
void ADC_DRV_GetConverterConfig (const uint32_t instance, adc_converter_config_t *const config)
 Gets the current converter configuration. More...
 
void ADC_DRV_Reset (const uint32_t instance)
 Resets the converter (sets all configurations to reset values) More...
 
void ADC_DRV_WaitConvDone (const uint32_t instance)
 Waits for a conversion/calibration to finish. More...
 
bool ADC_DRV_GetConvCompleteFlag (const uint32_t instance, const uint8_t chanIndex)
 Gets the control channel Conversion Complete Flag state. More...
 
Hardware Compare

The Hardware Compare feature of the S32K144 ADC is a versatile mechanism that can be used to monitor that a value is within certain values. Measurements can be monitored to be within certain ranges:

  • less than/ greater than a fixed value
  • inside or outside of a certain range

Two compare values can be configured (the second value is used only for range function mode). The compare values must be written in 12-bit resolution mode regardless of the actual used resolution mode.

Once the hardware compare feature is enabled, a conversion is considered complete only when the measured value is within the allowable range set by the configuration.

void ADC_DRV_InitHwCompareStruct (adc_compare_config_t *const config)
 Initializes the Hardware Compare configuration structure. More...
 
void ADC_DRV_ConfigHwCompare (const uint32_t instance, const adc_compare_config_t *const config)
 Configures the Hardware Compare feature with the given configuration structure. More...
 
void ADC_DRV_GetHwCompareConfig (const uint32_t instance, adc_compare_config_t *const config)
 Gets the current Hardware Compare configuration. More...
 
Hardware Average

The Hardware Average feature of the S32K144 allows for a set of measurements to be averaged together as a single conversion. The number of samples to be averaged is selectable (4, 8, 16 or 32 samples).

void ADC_DRV_InitHwAverageStruct (adc_average_config_t *const config)
 Initializes the Hardware Average configuration structure. More...
 
void ADC_DRV_ConfigHwAverage (const uint32_t instance, const adc_average_config_t *const config)
 Configures the Hardware Average feature with the given configuration structure. More...
 
void ADC_DRV_GetHwAverageConfig (const uint32_t instance, adc_average_config_t *const config)
 Gets the current Hardware Average configuration. More...
 
Channel configuration

Control register specific functions. These functions control configurations for each control channel (input channel selection and interrupt enable).

When software triggering is enabled, calling the ADC_DRV_ConfigChan() method for control channel 0 starts a new conversion.

After a conversion is finished, the result can be retrieved using the ADC_DRV_GetChanResult() method.

void ADC_DRV_InitChanStruct (adc_chan_config_t *const config)
 Initializes the control channel configuration structure. More...
 
void ADC_DRV_ConfigChan (const uint32_t instance, const uint8_t chanIndex, const adc_chan_config_t *const config)
 Configures the selected control channel with the given configuration structure. More...
 
void ADC_DRV_GetChanConfig (const uint32_t instance, const uint8_t chanIndex, adc_chan_config_t *const config)
 Gets the current control channel configuration for the selected channel index. More...
 
void ADC_DRV_SetSwPretrigger (const uint32_t instance, const adc_sw_pretrigger_t swPretrigger)
 This function sets the software pretrigger - affects only first 4 control channels. More...
 
void ADC_DRV_GetChanResult (const uint32_t instance, const uint8_t chanIndex, uint16_t *const result)
 Gets the last result for the selected control channel. More...
 
Automatic Calibration

These methods control the Calibration feature of the ADC.

The ADC_DRV_AutoCalibration() method can be called to execute a calibration sequence, or a calibration can be retrieved with the ADC_DRV_GetUserCalibration() and saved to non-volatile storage, to avoid calibration on every power-on. The calibration structure can be written with the ADC_DRV_ConfigUserCalibration() method.

void ADC_DRV_AutoCalibration (const uint32_t instance)
 Executes an Auto-Calibration. More...
 
void ADC_DRV_InitUserCalibrationStruct (adc_calibration_t *const config)
 Initializes the User Calibration configuration structure. More...
 
void ADC_DRV_ConfigUserCalibration (const uint32_t instance, const adc_calibration_t *const config)
 Configures the User Calibration feature with the given configuration structure. More...
 
void ADC_DRV_GetUserCalibration (const uint32_t instance, adc_calibration_t *const config)
 Gets the current User Calibration configuration. More...
 
Interrupts

This method returns the interrupt number for an ADC instance, which can be used to configure the interrupt, like in Interrupt Manager.

IRQn_Type ADC_DRV_GetInterruptNumber (const uint32_t instance)
 Returns the interrupt number for the ADC instance. More...
 
Latched triggers processing

These functions provide basic operations for using the trigger latch mechanism.

void ADC_DRV_ClearLatchedTriggers (const uint32_t instance, const adc_latch_clear_t clearMode)
 Clear latched triggers under processing. More...
 
void ADC_DRV_ClearTriggerErrors (const uint32_t instance)
 Clear all latch trigger error. More...
 
uint32_t ADC_DRV_GetTriggerErrorFlags (const uint32_t instance)
 Get the trigger error flags bits of the ADC instance. More...