Synergy Software Package User's Manual
ADC Driver

ADC HAL Module Introduction

The ADC HAL module implements an API for analog-to-digital conversion applications. It supports the ADC12, ADC14, and ADC16 (for supported MCUs) for the associated peripherals available on Synergy MCUs. A user-defined callback can be used to process the data each time a new sample is complete.

ADC HAL Module Features

  • 16-Bit A/D Converter (S1JA)
  • 14-Bit A/D Converter (S3A7, S3A3, S3A6, S3A1, S128, S124)
  • 12-Bit A/D Converter (S7G2, S5D9, S5D5)
  • Multiple Operation Modes
    • Single Scan
    • Group Scan
    • Continuous Scan
  • Multiple Channels
    • All analog channels on MCU
      • 13 channels (unit 0) or 12 channels (unit 1) for S7G2
      • 17 channels for S1JA
      • 18 channels for S124
      • 28 channels for S3A7
    • Temperature sensor channel
    • Voltage sensor channel
  • Reference voltage selection on 16-Bit A/D Converter (S1JA).
  • Programmable gain amplifier (PGA) (S7G2, S5D9, S5D3)
    • Single ended input mode
    • Differential input mode
ADC_BD.png
ADC HAL Module Block Diagram

ADC Hardware support details

The following hardware features are, or are not, supported by the SSP for the ADC:

Legend:

Symbol Meaning
Available (Tested)
Not Available (Not tested/not functional or both)
N/A Not supported by MCU 
MCU
Group
Support for all Analog Channels (Unit 0 for all MCUs and Unit 0 & 1 for S5 and S7 series) 8-Bit 10-bit 12-Bit 14-bit 16-bit Single scan
Mode
S124 N/A N/A N/A
S128 N/A N/A N/A
S1JA N/A N/A N/A N/A
S3A1 N/A N/A N/A
S3A3 N/A N/A N/A
S3A6 N/A N/A N/A
S3A7 N/A N/A N/A
S5D3 N/A N/A
S5D5 N/A N/A
S5D9 N/A N/A
S7G2 N/A N/A
MCU
Group
Continuous Scan Mode Group Scan
Mode
Programmable Gain
Amplifier
Event link function through ELC
HAL driver*
S124 N/A
S128 N/A
S1JA N/A
S3A1 N/A
S3A3 N/A
S3A6 N/A
S3A7 N/A
S5D3
S5D5 N/A
S5D9
S7G2
  • Note: ELC is supported but only for Group mode. This must be set up manually by programming the Event Link Controller.

ADC HAL Module APIs Overview

The ADC HAL module defines APIs to open, configure scans, start scans, stop scans, read the conversion results of the ADC scans, and close the ADC unit. A complete list of the available APIs, an example API call, and a short description of each can be found in the following table. A table of status return values follows the API summary table.

ADC HAL Module API Summary

Function Name Example API Call and Description
open g_adc.p_api->open(g_adc.p_ctrl, g_adc.p_cfg);
Initialize ADC Unit; apply power, set the operational mode, trigger sources, interrupt priority, and configurations common to all channels and sensors.
scanCfg g_adc.p_api->scanCfg(g_adc.p_ctrl, g_adc.p_channel_cfg);
Configure the scan including the channels, groups and scan triggers to be used for the unit that was initialized in the open call.
scanStart g_adc.p_api->scanStart(g_adc.p_ctrl);
Start the scan (in case of a software trigger), or enable the hardware trigger.
scanStop g_adc.p_api->scanStop(g_adc.p_ctrl);
Stop the ADC scan (in case of a software trigger), or disable the hardware trigger.
scanStatusGet g_adc.p_api->scanStatusGet(g_adc.p_ctrl);
Check scan status.
read g_adc.p_api->read(g_adc.p_ctrl, ADC_REG_CHANNEL_13, &adc_data);
Read ADC conversion result(s).
sampleStateCountSet g_adc.p_api->sampleStateCountSet(g_adc.p_ctrl,&adc_sample);
Set the sample state count for the specified channel.
close g_adc.p_api->close(g_adc.p_ctrl);
Close the specified ADC unit by ending any scan in progress, disabling interrupts, and removing power to the specified A/D unit.
infoGet g_adc.p_api->infoGet(g_adc.p_ctrl, &adc_info);
Return the ADC data register address of the first (lowest number) channel and the total number of bytes to be read for the DTC/DMAC to read the conversion results of all configured channels.
versionGet g_adc.p_api->versionGet(&version);
Retrieve the API version with the version pointer.
Note
For more complete descriptions of operation and definitions for the function data structures, typedefs, defines, API data, API structures, and function variables, review the SSP User's Manual API References for the associated module.

Status Return Values

Name Description
SSP_SUCCESS API call successful.
SSP_ERR_INVALID_ARGUMENT Parameter has invalid value.
SSP_ERR_NOT_OPEN Unit is not open.
SSP_ERR_ASSERTION The parameter p_ctrl or p_sample is NULL.
SSP_ERR_IN_USE Peripheral is still running in another mode; perform R_ADC_Close first.
SSP_ERR_INVALID_POINTER The parameter p_data is NULL.
Note
Lower-level drivers may return common error codes. Refer to the SSP User's Manual API References for the associated module for a definition of all relevant status return values.

ADC HAL Module Operational Overview

The ADC driver on r_adc HAL module controls the ADC peripherals on a Synergy microcontroller, as configured by the user. It directly controls the ADC hardware without using any RTOS elements. It provides convenient API functions to simplify development.

The driver supports three operation modes: single-scan, continuous-scan, and group-scan modes.

Single-scan Mode

In single scan mode, one or more specified channels are scanned once per trigger.  A channel bit-mask is used in the channel properties configuration settings to indicate the scanned channels. Single-scan mode sequentially converts the analog inputs of the selected channels in the ascending order of the channel number. A callback event is generated after all selected channels have completed the conversion operation.

Continuous-scan Mode

Continuous-scan mode sequentially converts the analog inputs of selected channels continuously in the ascending order of the channel numbers. A single trigger is required to start the scan. No callback is used in this mode and interrupts must be disabled. The scanStatusGet API function is used to determine when data is available.

Group-scan Mode

Group-scan mode allows the application to allocate channels to one of two groups (A and B). Analog inputs of the selected channels are converted for each group in the ascending order of the channel numbers. Conversion begins when the specified start trigger for that group is received. A callback interrupt is generated after all selected channels in the associated group have completed the conversion operation. The interrupt event indicates which group has completed conversion.

In group mode, only hardware triggers can be used, as opposed to normal mode, where software triggers or an external trigger can be used. With the priority configuration parameter, you can specify:

  • Whether a trigger for one group can interrupt an ongoing scan for the other group.
  • Whether an interrupted scan resumes or restarts or simply aborts the current scan and waits for the next trigger.

Interrupt and Callback Overview

When a scan or calibration (on supported MCUs) is complete and a callback is provided in the application code, (and if interrupts are enabled) the module invokes the defined callback and provides an argument that indicates the ADC unit, the event, the address of the converted data, and the channel.

The module supports two interrupts:

  • The Normal/Group A Interrupt (Scan End Interrupt) fires when a scan is completed in single scan mode, when a Group A scan is completed in group mode, or at the end of calibration for supported MCUs.
  • The Group B Interrupt (Scan End Group B Interrupt) fires when a group B scan is completed in group mode.

Interrupts function differently in each mode:

  • In single-scan mode, the Normal interrupt (Scan End Interrupt) is triggered when the scan is completed.
  • In continuous scan-mode, the hardware will constantly scan the selected channels. In this mode, the driver will return an error if interrupts are enabled, so they must be disabled in this mode. 
  • In group mode, the ADC unit provides two interrupts (when enabled). The Normal interrupt (called Group A interrupt in this mode, even though it is the same vector as the Normal interrupt) and the Group B interrupt. The Group A interrupt (Scan End Interrupt) is triggered when a Group A scan is completed. The Group B interrupt (Scan End Group B Interrupt) is triggered when a Group B scan is completed.
Note
You must change the Scan End Interrupt Priority and Scan End Group B Interrupt Priority configuration setting in the selected units' properties window from the default Disabled setting to the desired Priority level to Enable the associated interrupts.

When Interrupts Are Not Enabled

If interrupts are not enabled, the scanStatusGet API is used to poll the ADC to determine when the scan has completed. The read API function is used to access the converted ADC result.

For MCUs that support calibration, if interrupts are not enabled, the application program must wait 24 ms and then check the status of the calibration function using the infoGet API. Once calibration is complete, another API can be used.

ADC HAL Module Important Operational Notes and Limitations

ADC HAL Module Operational Notes

Sample-State Count Setting

The application program can modify the setting of the sample-state count by calling the adc_api_t::sampleStateCountSet API function. The application program only needs to modify the sample-state count settings from their default values to increase the sampling time. This can be either because the impedance of the input signal is too high to secure sufficient sampling time under the default setting or if the ADCLK is too slow. To modify the sample-state count for a given channel, set the channel number and the number of states when calling the adc_api_t::sampleStateCountSet API function. Valid sample state counts are 7-255.

Note
Although the hardware supports a minimum number of sample states of 5, some Synergy MCUs require 7 states, so the minimum is set to 7. At the lowest supported ADC conversion clock rate (1 MHz), these extra states will lead to, at worst case, a 2 microsecond increase in conversion time. At 60 MHz the extra states will add 33.4 ns to the conversion time.

If the sample state count needs to be changed for multiple channels, the application program must call the adc_api_t::sampleStateCountSet API function repeatedly, with appropriately modified arguments for each channel.

Triggering a Data Transfer with the ADC

To trigger a transfer of data when the ADC scan completes, configure the data transfer with the activation_source set to ELC_EVENT_ADCn_SCAN_END or ELC_EVENT_ADCn_SCAN_END_B (where n is the ADC channel number). The adc_api_t::infoGet API function can be called to retrieve the ADC unit-specific information to use with the transfer API. Refer to the ELC Module Overview for additional information.

Triggering ELC Events with the ADC

The ADC unit can trigger the start of other peripherals by using the ELC. Refer to the ELC Module Overview for additional information.

Using the Temperature Sensor with the ADC

The ADC HAL module supports reading the data from the on-chip temperature sensor. The value returned from the sensor can be converted into degrees Celsius or Fahrenheit in the application program using the following formula, T = (Vs – V1)/slope + T1, where:

  • T: Measured temperature (°C)
  • Vs: Voltage output by the temperature sensor at the time of temperature measurement (Volts)
  • T1: Temperature experimentally measured at one point (°C)
  • V1: Voltage output by the temperature sensor at the time of measurement of T1 (Volts)
  • T2: Temperature at the experimental measurement of another point (°C)
  • V2: Voltage output by the temperature sensor at the time of measurement of T2 (Volts)
  • Slope: Temperature gradient of the temperature sensor (V/°C); slope = (V2 – V1)/ (T2 – T1)
Note
The slope value can be obtained from the hardware manual for each device in the Electrical Characteristics Chapter- TSN Characteristics Table, Temperature slope entry. The slope is positive for S7 and S5 devices and negative for S3 and S1 devices.

ADC HAL Module Limitations

When configuring the module, the temperature and voltage sensors must not be selected if any of the other available channels are also selected. The temperature sensor and the voltage sensor can both be used together, but neither can be used if any of the regular ADC channels are used.

Refer to the most recent SSP Release Notes for any additional operational limitations for this module.

Including the ADC HAL Module in an Application

This section describes how to include the ADC HAL Module in an application using the SSP configurator.

Note
This section assumes you are familiar with creating a project, adding threads, adding a stack to a thread and configuring a block within the stack. If you are unfamiliar with any of these items, refer to the first few chapters of the SSP User's Manual to learn how to manage each of these important steps in creating SSP-based applications.

To add the ADC Driver to an application, simply add it to a thread using the stacks selection sequence given in the following table. (The default name for the ADC Driver is g_adc0. This name can be changed in the associated Properties window.)

ADC HAL Module Selection Sequence

Resource ISDE Tab Stacks Selection Sequence
g_adc0 ADC Driver on r_adc Threads New Stack> Driver> Analog> ADC Driver on r_adc

When the ADC Driver on r_adc is added to the thread stack as shown in the following figure, the configurator automatically adds any needed lower‑level modules. Any modules needing additional configuration information have the box text highlighted in Red. Modules with a Gray band are individual modules that stand alone.

ADC_MS.png
ADC HAL Module Stack

Configuring the ADC HAL Module

The ADC HAL Module must be configured by the user for the desired operation. The available configuration settings and defaults for all the user-accessible properties are given in the properties tab within the SSP configurator and are shown in the following tables for easy reference. Only properties that can be changed without causing conflicts are available for modification. Other properties are locked and not available for changes and are identified with a lock icon for the locked property in the Properties window in the ISDE. This approach simplifies the configuration process and makes it much less error-prone than previous manual approaches to configuration. The available configuration settings and defaults for all the user-accessible properties are given in the Properties tab within the SSP Configurator and are shown in the following tables for easy reference.

Note
You may want to open your ISDE, create the module, and explore the property settings in parallel with looking over the following configuration table settings. This will help orient you and can be a useful 'hands-on' approach to learning the ins and outs of developing with SSP.

Configuration Settings for the ADC HAL Module on r_adc

ISDE Property Value Description
Parameter Checking BSP, Enabled, Disabled
Default: Enabled
If selected, code for parameter checking is included in the build.
Name g_adc0 Module name.
Unit 0, 1 (S7G2, S5D9 and S5D5)
Default: 0
Specify the ADC Unit to be used. The S7G2 has two units; 0 and 1.
Resolution (resolution varies by MCU) 14-Bit, 12-Bit, 10-Bit, 8-Bit
Default: 8-Bit
Specify the conversion resolution for this unit.
Alignment Right, Left
Default: Right
Specify the conversion result alignment.
Clear after read Off, On
Default: On
Specify if the result register must be automatically cleared after the conversion result is read.

Note
If this is enabled, then watching the result register using a debugger always results in a 0.
Mode Single Scan, Continuous Scan, Group Scan
Default: Single Scan
Specify the mode that this ADC unit is used in.
Internal Calibration During Open() Disabled, Enabled
Default: Enabled
Internal calibration during open selection.
Channel 0 - Unused, PGA 0: Configure gain from below field.
- Use in Normal/Group A,
- Use in Group B 
 
Default: Unused
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example, if it is set to 0x101, then channels 0 and 2 are enabled.
In group mode, this field is used to specify which channels belong to group A.
Channel 1 - Unused,
- Use in Normal/Group A,
- Use in Group B
PGA 1: Configure gain from below field.
Default: Unused
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example, if it is set to 0x101, then channels 0 and 2 are enabled.
In group mode, this field is used to specify which channels belong to group A.
Channel 2 - Unused,
- Use in Normal/Group A,
- Use in Group B
PGA 2: Configure gain from below field.
Default: Unused
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example, if it is set to 0x101, then channels 0 and 2 are enabled.
Channels 3-13 Unused, Use in Normal/Group A, Use in Group B
Default: Unused
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example, if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
Channel 14 (S3 Series Only) Unused, Use in Normal/Group A, Use in Group B
Default: Unused
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example, if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
Channel 15 (S3A7/S3A3 Only) Unused, Use in Normal/Group A, Use in Group B
Default: Unused
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example, if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
Channels 16-20 Unused, Use in Normal/Group A, Use in Group B
Default: Unused
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example, if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
Channel 21 (Unit 0 Only) Unused, Use in Normal/Group A, Use in Group B
Default: Unused
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example, if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
Channels 22-24 Unused, Use in Normal/Group A, Use in Group B
Default: Unused
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example, if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
Channel 25 (S3 series only) Unused, Use in Normal/Group A, Use in Group B
Default: Unused
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example, if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
Channel 26 (S3A7/S3A3 Only) Unused, Use in Normal/Group A, Use in Group B
Default: Unused
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example, if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
Channel 27 (S3A7/S3A3 Only) Unused, Use in Normal/Group A, Use in Group B
Default: Unused
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example, if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
Temperature Sensor Unused, Use in Normal/Group A, Use in Group B
Default: Unused
Temperature sensor use selection for Channel Scan Mask.
Voltage Sensor Unused, Use in Normal/Group A, Use in Group B
Default: Unused
Voltage sensor use selection for Channel Scan Mask.
Normal/Group A Trigger None, Asynchronous External Trigger 0, ELC Event, Software
Default: Software
Specify the trigger type to be used for this unit. If group mode is used adc_cfg_t::mode, then this field is used to set the Group A trigger.

Note
The only valid option in group mode is the ELC trigger.
Group B Trigger (Valid Only in Group Scan Mode) ELC Event (The only valid trigger for either group in Group Scan Mode) Specify the group B trigger. This option is only valid if group mode is chosen in adc_cfg_t::mode.
Group Priority (Valid only in Group Scan Mode) Group A cannot interrupt Group B, Group A can interrupt Group B; Group B scan restarts at next trigger, Group A can interrupt Group B; Group B scan restarts immediately, Group A can interrupt Group B; Group B scan restarts immediately and scans continuously
Default: Group A cannot interrupt Group B
Determines whether an ongoing group B scan can be interrupted by a group A trigger, whether it should abort on a group A trigger, or if it should pause to allow group A scan and restart immediately after group A scan is complete.

Note
This field is valid only in group mode.
Add/Average Count Disabled, Add two samples, Add three samples, Add four samples, Add sixteen samples, Average two samples, Average four samples, Average eight, Average sixteen
Default: Disabled
Specify if addition or averaging needs to be done for any of the channels in this unit. The actual channels are specified by using a channel mask adc_channel_cfg_t::add_mask.
Average eight and Average sixteen options are applicable only for S1JA.
Add count option is not applicable for S1JA.
Channels 0-27 Disabled, Enabled
Default: Disabled
This field is valid only if adc_cfg_t::add_average_count is enabled. This field determines what channels results are to be averaged or summed.
Temperature Sensor Disabled, Enabled
Default: Disabled
Temperature sensor use selection for Addition/Averaging Mask.
Voltage Sensor Disabled, Enabled
Default: Disabled
Voltage sensor use selection for Addition/Averaging Mask.
Sample and Hold Mask Select channels for which individual sample and hold circuit is to be enabled Sample and hold mask selection.
Channels 0-2 Disabled, Enabled
Default: Disabled
Determines which of channels 0, 1 and 2 are using the updated sample-and-hold states value specified in adc_channel_cfg_t::sample_hold_states. This field must only be set if it is desired to modify the default sample and hold count value for channels 0, 1 and 2.
Sample Hold States (Applies only to the 3 channels selected above) 24 Specifies the updated sample-and-hold count for the channel dedicated sample-and-hold circuit. This field is valid only if adc_channel_cfg_t::sample_hold_mask is not 0. Only channels 0, 1 and 2 have dedicated sample and hold circuits.

Note
Use this to modify the default number of states (24) for which the value is sampled. Each state is equal to 1/ADCLK time.
Callback NULL A user callback function can be registered in adc_api_t::open. If this callback function is provided, it is called from the interrupt service routine (ISR) each time the ADC scan completes.

Warning: Since the callback is called from an ISR, care should be taken not to use blocking calls or lengthy processing. Spending excessive time in an ISR can affect the responsiveness of the system.
Scan End Interrupt Priority Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX)
Default: Disabled
Scan End Interrupt Priority selection.
Scan End Group B Interrupt Priority Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX)
Default: Disabled
Scan End Group B Interrupt Priority selection.
Voltage reference (Only for S1JA) - External VREFH0
- Internal VREF 1.5V
- Internal VREF 2.0V
- Internal VREF 2.5V
The ADC module will use the selected one as reference voltage.
Over-current protection (Only for S1JA) - Enable
- Disabled
Enables or disable over-current detection on sensor module.
Programmable Gain Amplifier Select PGA channel from 'Channel Mask Scan' and Gain from below options Select PGA channel from 'Channel Mask Scan' and Gain from below options.
PGA 0 - Disabled
- Single Input_x2
- Single Input_x2.5
- Single Input_x_2.66
- Single Input_x_2.85
- Single Input_x_3.07
- Single Input_x_3.33
- Single Input_x_3.63
- Single Input_x_4.00
- Single Input_x_4.44
- Single Input_x_5.00
- Single Input_x_5.71
- Single Input_x_6.66
- Single Input_x_8.00
- Single Input_x_10.0
- Single Input_x_13.33
- Diff Input_x_1.5"
- Diff Input_x_2.3"
- Diff Input_x_4.0"
- Diff Input_x_5.66" 
Applicable only for S7G2, S5D9, S5D3.
PGA 1 - Disabled
- Single Input_x2
- Single Input_x2.5
- Single Input_x_2.66
- Single Input_x_2.85
- Single Input_x_3.07
- Single Input_x_3.33
- Single Input_x_3.63
- Single Input_x_4.00
- Single Input_x_4.44
- Single Input_x_5.00
- Single Input_x_5.71
- Single Input_x_6.66
- Single Input_x_8.00
- Single Input_x_10.0
- Single Input_x_13.33
- Diff Input_x_1.5" 
- Diff Input_x_2.3" 
- Diff Input_x_4.0" 
- Diff Input_x_5.66" 
Applicable only for S7G2, S5D9, S5D3.
PGA 2 - Disabled
- Single Input_x2
- Single Input_x2.5
- Single Input_x_2.66
- Single Input_x_2.85
- Single Input_x_3.07
- Single Input_x_3.33
- Single Input_x_3.63
- Single Input_x_4.00
- Single Input_x_4.44
- Single Input_x_5.00
- Single Input_x_5.71
- Single Input_x_6.66
- Single Input_x_8.00
- Single Input_x_10.0
- Single Input_x_13.33
- Diff Input_x_1.5" 
- Diff Input_x_2.3" 
- Diff Input_x_4.0" 
- Diff Input_x_5.66" 
Applicable only for S7G2, S5D9, S5D3.
Note
The example settings and defaults are for a project using the Synergy S7G2 MCU Group. Other MCUs may have different default values and available configuration settings.

ADC HAL Module Clock Configuration

The ADC HAL module uses the PCLKC as its clock source (ADCLK.) The only restriction when configuring this clock is that it should be set to less than the max ADC clock; there is also a restriction on the ratio of the PCLKC and PCLKB clocks specified in the hardware manual.

The ADC-conversion time depends on the PCLKC setting.

To set the PCLKB and PCLKC frequencies, use the clock configurator in the ISDE.

To change the clock frequency at run-time, use the CGC Interface.

ADC HAL Module Pin Configuration

To use the ADC HAL module, the port pins for the channels receiving the analog input must be set as input pins in the pin configurator in the ISDE. The following table illustrates the method for selecting the pins within the ISDE configuration window:

Pin Selection for the ADC HAL Module on r_adc

Resource ISDE Tab Pin selection Sequence
ADC Pins Select Peripherals> Analog Pins> **ADC0\1**> AN_XX

Using the ADC HAL Module in an Application

The typical steps in using the ADC HAL module in an application are:

  1. Initialize the ADC using the adc_api_t::open API. (If calibration is enabled in the configuration, it will be performed as a part of the open call for the MCUs that support calibration.)
  2. Configure the channels using the adc_api_t::scanCfg API. For MCUs that support calibration, if the calibration was not enabled in the configuration, then it must be performed before starting the first scan. Start the calibration (for supported MCUs) using the adc_api_t::calibrate API.
    1. If interrupts are disabled wait for at least 24 ms (for 32 MHz PCLKB), check status using the adc_api_t::infoGet API to insure the calibration is complete before using other ADC APIs.
    2. If interrupts are enabled, the callback will be invoked when the calibration is complete.
  3. Start a conversion using the desired trigger with the adc_api_t::scanStart API.
    1. If a hardware trigger is used, this call enables the ADC unit to be triggered by the hardware trigger. If a software trigger is used, then this call starts the ADC scan.
  4. If interrupts are disabled, use the adc_api_t::scanStatusGet API to determine if the scan is complete.
  5. If interrupts are enabled, the callback will be invoked when the scan is complete.
  6. Read the results of the conversion using the adc_api_t::read API.
  7. Stop the ADC scan by calling the adc_api_t::scanStop API
    1. This prevents the ADC from being triggered by an external trigger or a hardware trigger; it also forces a stop of a software-triggered scan if one is ongoing.
  8. Operate on the received data as needed by the application.
  9. Use the adc_api_t::close API to power down the peripheral.

These common steps are illustrated in a typical operational flow diagram in the following figure:

ADC_TA.png
Flow Diagram of a Typical ADC HAL Module Application