![]() |
Synergy Software Package User's Manual
|
The SDADC HAL module provides a high level API for analog-to-digital conversions and supports the SDADC24 24-bit analog-to-digital converter peripheral available on the Synergy microcontroller hardware. A user-defined callback can be created to process the data each time a new sample is available.
The following hardware features are, or are not, supported by SSP for SDADC:
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 | 24-Bit | Single-scan Mode | Continuous-scan mode |
|---|---|---|---|---|
| S124 | N/A | N/A | N/A | N/A |
| S128 | N/A | N/A | N/A | N/A |
| S1JA | ✓ | ✓ | ✓ | ✓ |
| S3A1 | N/A | N/A | N/A | N/A |
| S3A3 | N/A | N/A | N/A | N/A |
| S3A6 | N/A | N/A | N/A | N/A |
| S3A7 | N/A | N/A | N/A | N/A |
| S5D3 | N/A | N/A | N/A | N/A |
| S5D5 | N/A | N/A | N/A | N/A |
| S5D9 | N/A | N/A | N/A | N/A |
| S7G2 | N/A | N/A | N/A | N/A |
| MCU Group | Single-ended input | Differential input | Programmable Gain Amplifier | Configurable oversampling ratio |
|---|---|---|---|---|
| S124 | N/A | N/A | N/A | N/A |
| S128 | N/A | N/A | N/A | N/A |
| S1JA | ✓ | ✓ | ✓ | ✓ |
| S3A1 | N/A | N/A | N/A | N/A |
| S3A3 | N/A | N/A | N/A | N/A |
| S3A6 | N/A | N/A | N/A | N/A |
| S3A7 | N/A | N/A | N/A | N/A |
| S5D3 | N/A | N/A | N/A | N/A |
| S5D5 | N/A | N/A | N/A | N/A |
| S5D9 | N/A | N/A | N/A | N/A |
| S7G2 | N/A | N/A | N/A | N/A |
The SDADC HAL module defines API functions to open, configure scans, start scans, stop scans, read the conversion results 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.
SDADC 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. |
| read32 | g_adc.p_api->read32(g_adc.p_ctrl, ADC_REG_CHANNEL_13, &adc_data);Read ADC conversion result into a 32-bit word. |
| sampleStateCountSet | g_adc.p_api-> sampleStateCountSet(g_adc.p_ctrl,&adc_sample);Set the sample state count for the specified channel. |
| calibrate | g_adc.p_api-> calibrate(g_adc.p_ctrl, reg_id, offset);Calibrate ADC or associated PGA (programmable gain amplifier). The driver may require implementation specific arguments to the p_extend input. |
| offsetSet | g_adc.p_api-> offsetSet(g_adc.p_ctrl, p_extend);Set offset for input PGA configured for differential input. |
| 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. |
| SSP_ERR_CALIBRATION_FAILED | Calibration failed. |
The SDADC HAL module controls the SDADC peripheral on a Synergy microcontroller. It directly controls the SDADC hardware without using any RTOS elements and provides convenient APIs to simplify development.
In this document, the term 'scan' refers to the AUTOSCAN feature of the SDADC, which works as follows:
The driver supports single-scan and continuous scan operation modes.
Interrupts and Callbacks
When a conversion is complete and a callback is provided by the user, the SDADC HAL module calls the callback (adc_cfg_t::p_callback) with the argument adc_callback_args_t, indicating the unit and the event adc_cb_event_t.
The SDADC driver supports the following callback events:
Triggering a Data Transfer with the SDADC
To trigger a transfer of data when the SDADC scan completes, configure the data transfer with transfer_cfg_t::activation_source set to ELC_EVENT_SDADCn_SCAN_END. The ELC events are listed under elc_event_t. To retrieve the SDADC specific information to use with the Transfer Interface API, use the adc_api_t::infoGet function call.
Triggering ELC Events with the SDADC
The SDADC unit can trigger the start of other peripherals listed in elc_peripheral_t. Refer to the "ELC Interface" in the SSP User's Manual for more information.
This module only works for selected Synergy MCUs. Consult the release notes for your current SSP release to see which MCUs are supported by this module. Additionally, the MCU Hardware Manual shows which peripherals are available.
Refer to the most recent SSP Release Notes for any additional operational limitations for this module.
This section describes how to include the SDADC HAL Module in an application using the SSP configurator.
To add the SDADC 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 SDADC Driver is g_sdadc0. This name can be changed in the associated Properties window.)
SDADC HAL Module Selection Sequence
| Resource | ISDE Tab | Stacks Selection Sequence |
|---|---|---|
| g_sdadc0 SDADC Driver on r_adc | Threads | New Stack> Driver> Analog> SDADC Driver on r_sdadc |
When the SDADC Driver on r_sdadc 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. Modules with a Blue band are shared or common; they need only be added once and can be used by multiple stacks. Modules with a Pink band can require the selection of lower-level modules; these are either optional or recommended. (This is indicated in the block with the inclusion of this text.) If the addition of lower-level modules is required, the module description include Add in the text. Clicking on any Pink banded modules brings up the New icon and displays possible choices.
The SDADC 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 SDADC HAL Module on r_sdadc
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Enable or disable parameter error checking. |
| Name | g_adc0 | Module name. |
| Mode | Single Scan, Continuous Scan Default: Continuous Scan | In single scan mode, all channels are converted once per start trigger, and conversion stops after all enabled channels are scanned. In continuous scan mode, conversion starts after a start trigger, then continues until stopped in software. |
| Resolution | 16 Bit, 24 Bit Default: 24 Bit | Select 24-bit or 16-bit resolution. |
| Alignment | Right, Left Default: Right | Select left or right alignment. |
| Trigger | ELC Hardware Event, Software Default: Software | Select conversion start trigger. Conversion can be started in software, or conversion can be started when a hardware event occurs if the hardware event is linked to the SDADC peripheral using the ELC API. |
| Vref Source | Internal, External Default: Internal | Vref can be sourced internally and output on the SBIAS pin, or Vref can be input from VREFI. |
| Vref Voltage | 0.8V, 1.0V, 1.2V, 1.4V, 1.6V, 1.8V, 2.0V, 2.2V, 2.4V Default: 1.0V | Select Vref voltage. If Vref is input externally, the voltage on VREFI must match the voltage selected within 3%. |
| Internal Calibration During Open() | Enabled, Disabled Default: Enabled | Calibration is required for all channels configured for differential input. Internal calibration is performed automatically during open for these channels unless it is disabled here. |
| Callback | NULL | Enter the name of the callback function to be called when conversion completes or a scan ends. |
| Conversion End Interrupt Priority | Priority 0 (highest), Priority 1, Priority 2, Priority 3 (lowest - not valid if using ThreadX) Default: Priority 2 | Select the interrupt priority for the conversion end interrupt. [Required] |
| Scan End Interrupt Priority | Priority 0 (highest), Priority 1, Priority 2, Priority 3 (lowest - not valid if using ThreadX), Disabled Default: Disabled | Select the interrupt priority for the scan end interrupt. [Required] |
| Calibration End Interrupt Priority | Priority 0 (highest), Priority 1, Priority 2, Priority 3 (lowest - not valid if using ThreadX), Disabled Default: Disabled | Select the interrupt priority for the calibration end interrupt. [Required] |
The SDADC HAL module uses the SDADCCLK as its clock source and it must be set to 4 MHz.
To use the SDADC 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 SDADC HAL Module on r_sdadc
| Resource | ISDE Tab | Pin selection Sequence |
|---|---|---|
| SDADC | Pins | Select Peripherals> Analog:SDADC> SDADCn, where n is the channel number. |
The typical steps in using the SDADC HAL module in an application are:
These common steps are illustrated in a typical operational flow diagram in the following figure: