![]() |
Synergy Software Package User's Manual
|
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.
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 | ✓ | ✓ | ✓ | ✓ |
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. |
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. |
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:
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:
Interrupts function differently in each mode:
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.
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.
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:
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.
This section describes how to include the ADC HAL Module in an application using the SSP configurator.
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.
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.
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.
|
| 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.
|
| 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.
|
| 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.
|
| 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. |
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.
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 |
The typical steps in using the ADC HAL module in an application are:
These common steps are illustrated in a typical operational flow diagram in the following figure: