RA Flexible Software Package Documentation  Release v5.7.0

 
ADC (r_adc)

Functions

fsp_err_t R_ADC_Open (adc_ctrl_t *p_ctrl, adc_cfg_t const *const p_cfg)
 
fsp_err_t R_ADC_ScanCfg (adc_ctrl_t *p_ctrl, void const *const p_channel_cfg)
 
fsp_err_t R_ADC_CallbackSet (adc_ctrl_t *const p_api_ctrl, void(*p_callback)(adc_callback_args_t *), void const *const p_context, adc_callback_args_t *const p_callback_memory)
 
fsp_err_t R_ADC_ScanStart (adc_ctrl_t *p_ctrl)
 
fsp_err_t R_ADC_ScanGroupStart (adc_ctrl_t *p_ctrl, adc_group_mask_t group_id)
 
fsp_err_t R_ADC_ScanStop (adc_ctrl_t *p_ctrl)
 
fsp_err_t R_ADC_StatusGet (adc_ctrl_t *p_ctrl, adc_status_t *p_status)
 
fsp_err_t R_ADC_Read (adc_ctrl_t *p_ctrl, adc_channel_t const reg_id, uint16_t *const p_data)
 
fsp_err_t R_ADC_Read32 (adc_ctrl_t *p_ctrl, adc_channel_t const reg_id, uint32_t *const p_data)
 
fsp_err_t R_ADC_SampleStateCountSet (adc_ctrl_t *p_ctrl, adc_sample_state_t *p_sample)
 
fsp_err_t R_ADC_InfoGet (adc_ctrl_t *p_ctrl, adc_info_t *p_adc_info)
 
fsp_err_t R_ADC_Close (adc_ctrl_t *p_ctrl)
 
fsp_err_t R_ADC_Calibrate (adc_ctrl_t *const p_ctrl, void const *p_extend)
 
fsp_err_t R_ADC_OffsetSet (adc_ctrl_t *const p_ctrl, adc_channel_t const reg_id, int32_t offset)
 

Detailed Description

Driver for the ADC12, ADC14, and ADC16 peripherals on RA MCUs. This module implements the ADC Interface.

Overview

Features

The ADC module supports the following features:

Configuration

Build Time Configurations for r_adc

The following build time configurations are defined in fsp_cfg/r_adc_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.

Configurations for Analog > ADC (r_adc)

This module can be added to the Stacks tab via New Stack > Analog > ADC (r_adc). Non-secure callable guard functions can be generated for this module by right clicking the module in the RA Configuration tool and checking the "Non-secure Callable" box.

ConfigurationOptionsDefaultDescription
General
NameName must be a valid C symbolg_adc0 Module name
UnitUnit must be a non-negative integer0 Specifies the ADC Unit to be used.
ResolutionMCU Specific OptionsSpecifies the conversion resolution for this unit.
AlignmentMCU Specific OptionsSpecifies the conversion result alignment.
Clear after read
  • Off
  • On
On Specifies if the result register will be automatically cleared after the conversion result is read.
Mode
  • Single Scan
  • Continuous Scan
  • Group Scan
Single Scan Specifies the mode that this ADC unit is used in.
Double-trigger
  • Disabled
  • Enabled
  • Enabled (extended mode)
Disabled When enabled, the scan-end interrupt for Group A is only thrown on every second scan. Extended double-trigger mode (single-scan only) triggers on both ELC events, allowing (for example) a scan on two different timer compare match values.

In group mode Group B is unaffected.

Input
Input > Sample and Hold
Sample and Hold Channels (Available only on selected MCUs)
  • Channel 0
  • Channel 1
  • Channel 2
Specifies if this channel is included in the Sample and Hold Mask.
Sample Hold States (Applies only to channels 0, 1, 2)Must be a valid non-negative integer with configurable value 4 to 25524 Specifies the updated sample-and-hold count for the channel dedicated sample-and-hold circuit
Input > Window Compare
Input > Window Compare > Window A
Enable
  • Disabled
  • Enabled
Disabled Enable or disable comparison with Window A.
Channels to compare (channel availability varies by MCU and unit)Refer to the RA Configuration tool for available options.Select channels to be compared to Window A.
Channel comparison mode (channel availability varies by MCU and unit)Refer to the RA Configuration tool for available options.Checking a box sets the comparison mode for that channel to Greater Than or Inside Window depending on whether Window Mode is disabled or enabled (respectively). If left unchecked the comparison mode will likewise be Less Than or Outside Window (respectively).
Lower ReferenceMust be a positive 16-bit integer.0 Set the lower comparison value.
Upper ReferenceMust be a positive 16-bit integer.0 Set the upper comparison value.
Input > Window Compare > Window B
Enable
  • Disabled
  • Enabled
Disabled Enable or disable comparison with Window B.
Channel to compare (channel availability varies by MCU and unit)Refer to the RA Configuration tool for available options.Channel 0 Select a channel to be compared to Window B.
Comparison mode
  • Less Than or Outside Window
  • Greater Than or Inside Window
module.driver.adc.compare.window_b.mode Select the comparison mode for Window B. For each option, the first condition applies when Window Mode is disabled and the second option applies when Window Mode is enabled.
Lower ReferenceMust be a positive 16-bit integer.0 Set the lower comparison value.
Upper ReferenceMust be a positive 16-bit integer.0 Set the upper comparison value.
Window Mode
  • Disabled
  • Enabled
Disabled When disabled, ADC values will be compared only with the lower reference on each comparator. When enabled, both the lower and upper reference values will be used to create a comparison window.
Event Output
  • OR
  • XOR
  • AND
OR Select how comparison results should be composited for event output.
Channel Scan Mask (channel availability varies by MCU)Refer to the RA Configuration tool for available options.In Normal mode of operation, this bitmask field specifies the channels that are enabled in that ADC unit. In group mode, this field specifies which channels belong to group A.
Group B Scan Mask (channel availability varies by MCU)Refer to the RA Configuration tool for available options.In group mode, this field specifies which channels belong to group B.
Add/Average CountMCU Specific OptionsSpecifies if addition or averaging needs to be done for any of the channels in this unit.
Reference Voltage controlMCU Specific OptionsSpecify VREFH/VREFADC output voltage control.
Addition/Averaging Mask (channel availability varies by MCU and unit)Refer to the RA Configuration tool for available options.Select channels to include in the Addition/Averaging Mask
Interrupts
Normal/Group A TriggerMCU Specific OptionsSpecifies the trigger type to be used for this unit. Triggers that specify ADC Unit must be selected for correct ADC unit to operate correctly.
Group B TriggerMCU Specific OptionsSpecifies the trigger for Group B scanning in group scanning mode. This event is also used to trigger Group A in extended double-trigger mode. Triggers that specify ADC Unit must be selected for correct ADC unit to operate correctly.
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
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.
CallbackName must be a valid C symbolNULL A user callback function. If this callback function is provided, it is called from the interrupt service routine (ISR) each time the ADC scan completes.
Scan End Interrupt PriorityMCU Specific OptionsSelect scan end interrupt priority.
Scan End Group B Interrupt PriorityMCU Specific OptionsSelect group B scan end interrupt priority.
Window Compare A Interrupt PriorityMCU Specific OptionsSelect Window Compare A interrupt priority.
Window Compare B Interrupt PriorityMCU Specific OptionsSelect Window Compare B interrupt priority.
Extra
ADC Ring BufferMCU Specific OptionsADC Ring Buffer to be used only with DMAC transfers, keep this property disabled for normal ADC operations. When enabled, ADC converted data is stored in ADBUF registers in place of ADDR registers. The read API will not read from this location for normal ADC operations.

Clock Configuration

The ADC clock is PCLKC if the MCU has PCLKC, or PCLKD otherwise.

The clock for this module is derived from the following peripheral clock for each MCU group:

MCU GroupPeripheral Clock
RA0E1ICLK
RA2A1PCLKD
RA2A2PCLKD
RA2E1PCLKD
RA2E2PCLKD
RA2E3PCLKD
RA2L1PCLKD
RA4E1PCLKC
RA4E2PCLKC
RA4M1PCLKC
RA4M2PCLKC
RA4M3PCLKC
RA4T1PCLKC
RA4W1PCLKC
RA6E1PCLKC
RA6E2PCLKC
RA6M1PCLKC
RA6M2PCLKC
RA6M3PCLKC
RA6M4PCLKC
RA6M5PCLKC
RA6T1PCLKC
RA6T3PCLKC
RA8D1PCLKC
RA8E1PCLKC
RA8M1PCLKC
RA8T1PCLKC

The ADC clock must be at least 1 MHz when the ADC is used. Many MCUs also have PCLK ratio restrictions when the ADC is used. For details on PCLK ratio restrictions, reference the footnotes in the second table of the Clock Generation Circuit chapter of the MCU User's Manual (for example, Table 9.2 "Specifications of the clock generation circuit for the internal clocks" in the RA6M3 manual R01UH0886EJ0100).

Pin Configuration

The ANxxx pins are analog input channels that can be used with the ADC.

ADTRG0 and ADTRG1 can be used to start scans with an external trigger for unit 0 and 1 respectively. When external triggers are used, ADC scans begin on the falling edge of the ADTRG pin.

Usage Notes

Sample Hold

Enabling the sample and hold functionality reduces the maximum scan frequency because the sample and hold time is added to each scan. Refer to the hardware manual for details on the sample and hold time.

ADC Operational Modes

The driver supports three operation modes: single-scan, continuous-scan, and group-scan modes. In each mode, analog channels are converted in ascending order of channel number, followed by scans of the temperature sensor and voltage sensor if they are included in the mask of channels to scan.

Single-scan Mode

In single scan mode, one or more specified channels are scanned once per trigger.

Continuous-scan Mode

In continuous scan mode, a single trigger is required to start the scan. Scans continue until R_ADC_ScanStop() is called.

Note
1) To help ensure a responsive system, developers should consider system clock speed, ADCLK speed, and callback processing time. In particular, using a scan-end callback with a high scan rate relative to core clocks (for example, in continuous scan mode) may result in constant or high-frequency interrupts and is not recommended.
2) On some MCUs, scanning the temperature sensor or internal reference voltage in continuous or group scan modes is prohibited. Check the "ADC12 specifications" section of the device's User Manual to see if this restriction applies.

Group-scan Mode

Group-scan mode allows the application to allocate channels to one of two groups (A and B). Conversion begins when the specified ELC start trigger for that group is received.

With the priority configuration parameter, you can optionally give group A priority over group B. If group A has priority over group B, a group B scan is interrupted when a group A scan trigger occurs. The following options exist for group B when group A has priority:

Double-triggering

When double-triggering is enabled a single channel is selected to be scanned twice before an interrupt is thrown. The first scan result when using double-triggering is always saved to the selected channel's data register. The second result is saved to the data duplexing register (ADC_CHANNEL_DUPLEX).

Double-triggering uses Group A; only one channel can be selected when enabled. No other scanning is possible on Group A while double-trigger mode is selected. In addition, any special ADC channels (such as temperature sensors or voltage references) are not valid double-trigger channels.

When extended double-triggering is enabled, both ADC input (ELC) events are routed to Group A. The interrupt is still thrown after every two scans regardless of the triggering event(s). While the first and second scan are saved to the selected ADC data register and the ADC duplexing register as before, scans associated with event A and B are additionally copied into duplexing register A and B, respectively (ADC_CHANNEL_DUPLEX_A and ADC_CHANNEL_DUPLEX_B).

When Interrupts Are Not Enabled

If interrupts are not enabled, the R_ADC_StatusGet API can be used to poll the ADC to determine when the scan has completed. The read API function is used to access the converted ADC result. This applies to both normal scans and calibration scans for MCUs that support calibration.

Window Compare Function

The ADC contains comparators that allow scan data to be compared to user-provided reference values. When a value meets the configured condition an interrupt and/or an ELC event can be produced.

Each unit has two configurable comparison units, Window A and Window B. Window A allows for configuring multiple simultaneous channels to compare while Window B only allows one channel at a time.

The window compare function can be configured both through the RA Configuration tool and at runtime by providing a pointer to an adc_window_cfg_t struct to adc_channel_cfg_t::p_window_cfg when calling R_ADC_ScanCfg. The available comparison modes are shown below:

Window setting Channel mode 0 Channel mode 1
Disabled Scan < Low Ref Scan > Low Ref
Enabled (Scan < Low Ref) OR (Scan > High Ref) Low Ref < Scan < High Ref
Note
The window setting applies to all channels configured on a unit.

Event Output Function

To use the event output of compare function, Set the mode of operation to Single Scan Mode. The compare function can be configured by enabling both Window A and Window B. Select the channel of Window A. Select Window B channel to NOT SELECTED. Set the upper and lower reference values for both Window A and Window B.

Note
When using ADC12 in Snooze Mode, both Compare Window A and Compare Window B must be enabled.

Sample-State Count Setting

The application program can modify the setting of the sample-state count for analog channels by calling the R_ADC_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 R_ADC_SampleStateCountSet() API function. Valid sample state counts are 7-255.

Note
Although the hardware supports a minimum number of sample states of 5, some 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 R_ADC_SampleStateCountSet() API function repeatedly, with appropriately modified arguments for each channel.

If the ADCLK frequency changes, the sample states may need to be updated.

Sample States for Temperature Sensor and Internal Voltage Reference

Sample states for the temperature sensor and the internal reference voltage are calculated during R_ADC_ScanCfg() based on the ADCLK frequency at the time. The sample states for the temperature sensor and internal voltage reference cannot be updated with R_ADC_SampleStateCountSet(). If the ADCLK frequency changes, call R_ADC_ScanCfg() before using the temperature sensor or internal reference voltage again to ensure the sampling time for the temperature sensor and internal voltage reference is optimal.

Selecting Reference Voltage

The ADC high-potential and low-potential reference voltages may be configured for selected MCU's. Please refer to the RA Configuration editor in e² studio for further details.

Note
When using VREFADC, a stabilization time of 1500us is required after call for R_ADC_Open(). Consult Section 32.6 "Selecting Reference Voltage" in the RA2A1 User's Manual (R01UH0888EJ0100) for details.
When the internal reference voltage is selected as the high-potential reference voltage, the Low-power A/D Conversion mode will automatically be selected. Consult Section 29.6 "Selecting Reference Voltage" in the RA2E1 User's Manual (R01UH0852EJ0110) for details.

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:

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.

Reading CTSU TSCAP with ADC

Some MCUs support reading CTSU TSCAP with ADC. CTSU TSCAP is connected to ADC0 channel 16. Use existing enums for channel 16 to set sample states for the sensor connected to CTSU TSCAP, enable scanning of CTSU TSCAP, and read results for CTSU TSCAP.

Usage Notes for ADC16

Calibration

Calibration is required to use the ADC16 peripheral. When using this driver on an MCU that has ADC16, call R_ADC_Calibrate() after open, and prior to any other function.

Range of ADC16 Results

The range of the ADC16 is from 0 (lowest) to 0x7FFF (highest) when used in single-ended mode. This driver only supports single ended mode.

Limitations

Developers should be aware of the following limitations when using the ADC:

Examples

Basic Example

This is a basic example of minimal use of the ADC in an application.

/* A channel configuration is generated by the RA Configuration editor based on the options selected. If additional
* configurations are desired additional adc_channel_cfg_t elements can be defined and passed to R_ADC_ScanCfg. */
const adc_channel_cfg_t g_adc0_channel_cfg =
{
.scan_mask_group_b = 0,
.priority_group_a = (adc_group_a_t) 0,
.add_mask = 0,
.sample_hold_mask = 0,
.sample_hold_states = 0,
};
void adc_basic_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = R_ADC_Open(&g_adc0_ctrl, &g_adc0_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Enable channels. */
err = R_ADC_ScanCfg(&g_adc0_ctrl, &g_adc0_channel_cfg);
assert(FSP_SUCCESS == err);
/* In software trigger mode, start a scan by calling R_ADC_ScanStart(). In other modes, enable external
* triggers by calling R_ADC_ScanStart(). */
(void) R_ADC_ScanStart(&g_adc0_ctrl);
/* Wait for conversion to complete. */
adc_status_t status;
{
(void) R_ADC_StatusGet(&g_adc0_ctrl, &status);
}
/* Read converted data. */
uint16_t channel1_conversion_result;
err = R_ADC_Read(&g_adc0_ctrl, ADC_CHANNEL_1, &channel1_conversion_result);
assert(FSP_SUCCESS == err);
}

Temperature Sensor Example

This example shows how to calculate the MCU temperature using the ADC and the temperature sensor.

#define ADC_EXAMPLE_CALIBRATION_DATA_RA6M1 (0x7D5)
#define ADC_EXAMPLE_VCC_MICROVOLT (3300000)
#define ADC_EXAMPLE_TEMPERATURE_RESOLUTION (12U)
#define ADC_EXAMPLE_REFERENCE_CALIBRATION_TEMPERATURE (127)
void adc_temperature_example (void)
{
/* The following example calculates the temperature on an RA6M1 device using the data provided in the section
* 44.3.1 "Preparation for Using the Temperature Sensor" of the RA6M1 manual R01UH0884EJ0100. */
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = R_ADC_Open(&g_adc0_ctrl, &g_adc0_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Enable temperature sensor. */
err = R_ADC_ScanCfg(&g_adc0_ctrl, &g_adc0_channel_cfg);
assert(FSP_SUCCESS == err);
/* In software trigger mode, start a scan by calling R_ADC_ScanStart(). In other modes, enable external
* triggers by calling R_ADC_ScanStart(). */
(void) R_ADC_ScanStart(&g_adc0_ctrl);
/* Wait for conversion to complete. */
adc_status_t status;
{
(void) R_ADC_StatusGet(&g_adc0_ctrl, &status);
}
/* Read converted data. */
uint16_t temperature_conversion_result;
err = R_ADC_Read(&g_adc0_ctrl, ADC_CHANNEL_TEMPERATURE, &temperature_conversion_result);
assert(FSP_SUCCESS == err);
/* If the MCU does not provide calibration data, use the value in the hardware manual or determine it
* experimentally. */
/* Get Calibration data from the MCU if available. */
int32_t reference_calibration_data;
adc_info_t adc_info;
(void) R_ADC_InfoGet(&g_adc0_ctrl, &adc_info);
reference_calibration_data = (int32_t) adc_info.calibration_data;
/* NOTE: The slope of the temperature sensor varies from sensor to sensor. Renesas recommends calculating
* the slope of the temperature sensor experimentally.
*
* This example uses the typical slope provided in Table 52.38 "TSN characteristics" in the RA6M1 manual
* R01UM0011EU0050. */
int32_t slope_uv_per_c = BSP_FEATURE_ADC_TSN_SLOPE;
/* Formula for calculating temperature copied from section 44.3.1 "Preparation for Using the Temperature Sensor"
* of the RA6M1 manual R01UH0884EJ0100:
*
* In this MCU, the TSCDR register stores the temperature value (CAL127) of the temperature sensor measured
* under the condition Ta = Tj = 127 C and AVCC0 = 3.3 V. By using this value as the sample measurement result
* at the first point, preparation before using the temperature sensor can be omitted.
*
* If V1 is calculated from CAL127,
* V1 = 3.3 * CAL127 / 4096 [V]
*
* Using this, the measured temperature can be calculated according to the following formula.
*
* T = (Vs - V1) / Slope + 127 [C]
* T: Measured temperature (C)
* Vs: Voltage output by the temperature sensor when the temperature is measured (V)
* V1: Voltage output by the temperature sensor when Ta = Tj = 127 C and AVCC0 = 3.3 V (V)
* Slope: Temperature slope given in Table 52.38 / 1000 (V/C)
*/
int32_t v1_uv = (ADC_EXAMPLE_VCC_MICROVOLT >> ADC_EXAMPLE_TEMPERATURE_RESOLUTION) *
reference_calibration_data;
int32_t vs_uv = (ADC_EXAMPLE_VCC_MICROVOLT >> ADC_EXAMPLE_TEMPERATURE_RESOLUTION) *
temperature_conversion_result;
int32_t temperature_c = (vs_uv - v1_uv) / slope_uv_per_c + ADC_EXAMPLE_REFERENCE_CALIBRATION_TEMPERATURE;
/* Expect room temperature, break if temperature is outside the range of 20 C to 25 C. */
if ((temperature_c < 20) || (temperature_c > 25))
{
__BKPT(0);
}
}

Double-Trigger Example

This example demonstrates reading data from a double-trigger scan. A flag is used to wait for a callback event. Two scans must occur before the callback is called. These results are read via R_ADC_Read using the selected channel enum value as well as ADC_CHANNEL_DUPLEX.

volatile bool scan_complete_flag = false;
void adc_callback (adc_callback_args_t * p_args)
{
scan_complete_flag = true;
}
void adc_double_trigger_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initialize the module. */
err = R_ADC_Open(&g_adc0_ctrl, &g_adc0_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Enable double-trigger channel. */
err = R_ADC_ScanCfg(&g_adc0_ctrl, &g_adc0_channel_cfg);
assert(FSP_SUCCESS == err);
/* Enable scan triggering from ELC events. */
(void) R_ADC_ScanStart(&g_adc0_ctrl);
/* Wait for conversion to complete. Two scans must be triggered before a callback occurs. */
scan_complete_flag = false;
while (!scan_complete_flag)
{
/* Wait for callback to set flag. */
}
/* Read converted data from both scans. */
uint16_t channel1_conversion_result_0;
uint16_t channel1_conversion_result_1;
err = R_ADC_Read(&g_adc0_ctrl, ADC_CHANNEL_1, &channel1_conversion_result_0);
assert(FSP_SUCCESS == err);
err = R_ADC_Read(&g_adc0_ctrl, ADC_CHANNEL_DUPLEX, &channel1_conversion_result_1);
assert(FSP_SUCCESS == err);
}

ADC-DMAC Repeat-Block Transfer Example

This example demonstrates writing multiple data from DAC peripheral to ADC channels and storing the data in memory through DMAC using Repeat-Block Transfer mode. It creates single block to multiple ring buffer type of transfer topology. Ping-Pong mechanism is used to read the data from memory in between the transfers. This example is valid only for MCUs that have ADBUF.

#define ADC_DMAC_EXAMPLE_DATA_LOW (0U)
#define ADC_DMAC_EXAMPLE_DATA_HIGH (0x000FU)
#define ADC_DMAC_EXAMPLE_DELAY_1000_MS (1000U)
#define ADC_DMAC_EXAMPLE_NUM_PING_PONG_BUFFERS (2)
static uint16_t g_adc_dmac_example_buffer[ADC_DMAC_EXAMPLE_NUM_PING_PONG_BUFFERS][
ADC_DMAC_EXAMPLE_ADC_CHANNELS_PER_BLOCK][ADC_DMAC_EXAMPLE_SAMPLES_PER_CHANNEL]; // Destination buffer for DMAC transfers
static volatile uint16_t g_adc_dmac_example_ping_pong_index = 0U;
static volatile void * gp_read_data;
/* DMAC callback */
void adc_dmac_callback (dmac_callback_args_t * p_args)
{
(void) p_args;
/* Store the pointer to the last buffer that was written
* An array of data for the first enabled channel is at &g_adc_dmac_example_buffer[g_adc_dmac_example_ping_pong_index][0][0],
* an array of data for the next channel is at &g_adc_dmac_example_buffer[g_adc_dmac_example_ping_pong_index][1][0], etc.
*/
gp_read_data = &g_adc_dmac_example_buffer[g_adc_dmac_example_ping_pong_index][0][0];
/* Select the other ping-pong buffer which is free for writing */
g_adc_dmac_example_ping_pong_index = !g_adc_dmac_example_ping_pong_index;
/* Reset the destination pointer and DMAC peripheral */
R_DMAC_Reset(&g_transfer0_ctrl,
NULL,
(void *) &g_adc_dmac_example_buffer[g_adc_dmac_example_ping_pong_index][0][0],
ADC_DMAC_EXAMPLE_SAMPLES_PER_CHANNEL);
FSP_PARAMETER_NOT_USED(gp_read_data);
}
void adc_dmac_repeat_block_transfer_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Open ADC Module and configure the channels */
/* Enable the ADBUF property from configurations */
err = R_ADC_Open(&g_adc0_ctrl, &g_adc0_cfg);
assert(FSP_SUCCESS == err);
err = R_ADC_ScanCfg(&g_adc0_ctrl, &g_adc0_channel_cfg);
assert(FSP_SUCCESS == err);
/* Open DMAC channel for repeat-block transfer with following configurations
* (1) Destination address as &g_adc_dmac_example_buffer[g_adc_dmac_example_ping_pong_index][0][0]
* (2) Enable end of transfer interrupt
* (3) Configure source address mode as incremented and destination address mode as offset addition,
* fixed to address of ADBUF register by configurator with ADC-DMAC module
* (4) Configure source buffer size as total size of source buffer - Refer RA6M4 Hardware Manual R01UH0890EJ0110,
* section 16.2.15 for source buffer size limitations
* (5) Configure transfer mode as Repeat-Block mode
* (6) Refer RA6M4 Hardware Manual R01UH0890EJ0110,
* section 16.2.16 for total number of blocks which decides destination buffer size
* (7) Number of blocks is determined by the samples per channel property for ADC-DMAC module
* (8) Size of block is determined using the enabled ADC channels in the configurator when using ADC-DMAC-module
* (9) Configure DMAC activation source as A/D scan end interrupt
*/
err = R_DMAC_Open(&g_transfer0_ctrl, &g_transfer0_cfg);
assert(FSP_SUCCESS == err);
err = R_DMAC_Enable(&g_transfer0_ctrl);
assert(FSP_SUCCESS == err);
uint16_t count = ADC_DMAC_EXAMPLE_DATA_LOW;
adc_status_t adc_status;
/* Trigger the ADC scan for "count" times, this can be replaced by triggering the ADC using a timer */
while (count <= (uint16_t) ADC_DMAC_EXAMPLE_DATA_HIGH)
{
/* Scan the data with ADC channels*/
err = R_ADC_ScanStart(&g_adc0_ctrl);
assert(FSP_SUCCESS == err);
/* Wait for conversion to complete */
uint16_t timeout = UINT16_MAX;
while ((ADC_STATE_SCAN_IN_PROGRESS == adc_status.state) && (timeout > 0U))
{
timeout--;
R_ADC_StatusGet(&g_adc0_ctrl, &adc_status);
}
R_BSP_SoftwareDelay(ADC_DMAC_EXAMPLE_DELAY_1000_MS, BSP_DELAY_UNITS_MICROSECONDS);
count++;
}
}

Window Compare Example

This example shows how to configure the window compare function at runtime as well as how to handle events and obtain comparison results through a callback.

adc_window_cfg_t g_adc0_window_cfg =
{
/* Enable Window A and Window B; enable Window mode */
(adc_compare_cfg_t) (ADC_COMPARE_CFG_A_ENABLE | ADC_COMPARE_CFG_B_ENABLE | ADC_COMPARE_CFG_WINDOW_ENABLE),
/* Compare scan values from Channels 0 and 1 */
/* Set Channel 1 condition to be inside the window instead of outside */
.compare_mode_mask = ADC_MASK_CHANNEL_1,
/* Set reference voltage levels for Window A */
.compare_ref_low = ADC_SCAN_MAX / 3,
.compare_ref_high = ADC_SCAN_MAX * 2 / 3,
/* Configure Window B to compare Channel 2 (inside window) */
.compare_b_channel = ADC_WINDOW_B_CHANNEL_2,
.compare_b_mode = ADC_WINDOW_B_MODE_GREATER_THAN_OR_INSIDE,
/* Set reference voltage levels for Window B */
.compare_b_ref_low = ADC_SCAN_MAX / 4,
.compare_b_ref_high = ADC_SCAN_MAX * 3 / 4,
};
void adc0_callback (adc_callback_args_t * p_args)
{
{
/* Get channel that met the comparison criteria */
adc_channel_t channel = p_args->channel;
/* Process event here */
}
else if (ADC_EVENT_WINDOW_COMPARE_B == p_args->event)
{
/* Process Window B events here */
}
else
{
/* ... */
}
}
void adc_window_compare_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Open the ADC module */
err = R_ADC_Open(&g_adc0_ctrl, &g_adc0_cfg);
assert(FSP_SUCCESS == err);
/* Set the window compare configuration in the channel config */
g_adc0_channel_runtime_cfg.p_window_cfg = &g_adc0_window_cfg;
/* The window compare function is configured as part of the scan configuration */
err = R_ADC_ScanCfg(&g_adc0_ctrl, &g_adc0_channel_runtime_cfg);
assert(FSP_SUCCESS == err);
/* Main program loop - scan the ADC every second */
while (1)
{
/* Start a scan */
err = R_ADC_ScanStart(&g_adc0_ctrl);
assert(FSP_SUCCESS == err);
/* Delay; any compare events will be handled by the callback */
}
}

Data Structures

struct  adc_sample_state_t
 
struct  adc_window_cfg_t
 
struct  adc_extended_cfg_t
 
struct  adc_channel_cfg_t
 
struct  adc_instance_ctrl_t
 

Enumerations

enum  adc_mask_t
 
enum  adc_add_t
 
enum  adc_clear_t
 
enum  adc_vref_control_t
 
enum  adc_sample_state_reg_t
 
enum  adc_compare_cfg_t
 
enum  adc_window_b_channel_t
 
enum  adc_window_b_mode_t
 
enum  adc_group_a_t
 
enum  adc_double_trigger_t
 
enum  adc_start_source_t
 

Data Structure Documentation

◆ adc_sample_state_t

struct adc_sample_state_t

ADC sample state configuration

Data Fields
adc_sample_state_reg_t reg_id Sample state register ID.
uint8_t num_states Number of sampling states for conversion. Ch16-20/21 use the same value.

◆ adc_window_cfg_t

struct adc_window_cfg_t

ADC Window Compare configuration

Data Fields
uint32_t compare_mask Channel mask to compare with Window A.
uint32_t compare_mode_mask Per-channel condition mask for Window A.
adc_compare_cfg_t compare_cfg Window Compare configuration.
uint16_t compare_ref_low Window A lower reference value.
uint16_t compare_ref_high Window A upper reference value.
uint16_t compare_b_ref_low Window B lower reference value.
uint16_t compare_b_ref_high Window A upper reference value.
adc_window_b_channel_t compare_b_channel Window B channel.
adc_window_b_mode_t compare_b_mode Window B condition setting.

◆ adc_extended_cfg_t

struct adc_extended_cfg_t

Extended configuration structure for ADC.

Data Fields
adc_add_t add_average_count Add or average samples.
adc_clear_t clearing Clear after read.
adc_start_source_t trigger Trigger source for ADC.
adc_start_source_t trigger_group_b Trigger source for ADC group B; valid only for group mode.
adc_double_trigger_t double_trigger_mode Double-trigger mode setting.
adc_vref_control_t adc_vref_control VREFADC output voltage control.
uint8_t enable_adbuf Enable ADC Ring Buffer, Valid only to use along with DMAC transfer.
IRQn_Type window_a_irq IRQ number for Window Compare A interrupts.
IRQn_Type window_b_irq IRQ number for Window Compare B interrupts.
uint8_t window_a_ipl Priority for Window Compare A interrupts.
uint8_t window_b_ipl Priority for Window Compare B interrupts.

◆ adc_channel_cfg_t

struct adc_channel_cfg_t

ADC channel(s) configuration

Data Fields
uint32_t scan_mask Channels/bits: bit 0 is ch0; bit 15 is ch15.
uint32_t scan_mask_group_b Valid for group modes.
uint32_t add_mask Valid if add enabled in Open().
adc_window_cfg_t * p_window_cfg Pointer to Window Compare configuration.
adc_group_a_t priority_group_a Valid for group modes.
uint8_t sample_hold_mask Channels/bits 0-2.
uint8_t sample_hold_states Number of states to be used for sample and hold. Affects channels 0-2.

◆ adc_instance_ctrl_t

struct adc_instance_ctrl_t

ADC instance control block. DO NOT INITIALIZE. Initialized in adc_api_t::open().

Enumeration Type Documentation

◆ adc_mask_t

enum adc_mask_t

For ADC Scan configuration adc_channel_cfg_t::scan_mask, adc_channel_cfg_t::scan_mask_group_b, adc_channel_cfg_t::add_mask and adc_channel_cfg_t::sample_hold_mask. Use bitwise OR to combine these masks for desired channels and sensors.

Enumerator
ADC_MASK_OFF 

No channels selected.

ADC_MASK_CHANNEL_0 

Channel 0 mask.

ADC_MASK_CHANNEL_1 

Channel 1 mask.

ADC_MASK_CHANNEL_2 

Channel 2 mask.

ADC_MASK_CHANNEL_3 

Channel 3 mask.

ADC_MASK_CHANNEL_4 

Channel 4 mask.

ADC_MASK_CHANNEL_5 

Channel 5 mask.

ADC_MASK_CHANNEL_6 

Channel 6 mask.

ADC_MASK_CHANNEL_7 

Channel 7 mask.

ADC_MASK_CHANNEL_8 

Channel 8 mask.

ADC_MASK_CHANNEL_9 

Channel 9 mask.

ADC_MASK_CHANNEL_10 

Channel 10 mask.

ADC_MASK_CHANNEL_11 

Channel 11 mask.

ADC_MASK_CHANNEL_12 

Channel 12 mask.

ADC_MASK_CHANNEL_13 

Channel 13 mask.

ADC_MASK_CHANNEL_14 

Channel 14 mask.

ADC_MASK_CHANNEL_15 

Channel 15 mask.

ADC_MASK_CHANNEL_16 

Channel 16 mask.

ADC_MASK_CHANNEL_17 

Channel 17 mask.

ADC_MASK_CHANNEL_18 

Channel 18 mask.

ADC_MASK_CHANNEL_19 

Channel 19 mask.

ADC_MASK_CHANNEL_20 

Channel 20 mask.

ADC_MASK_CHANNEL_21 

Channel 21 mask.

ADC_MASK_CHANNEL_22 

Channel 22 mask.

ADC_MASK_CHANNEL_23 

Channel 23 mask.

ADC_MASK_CHANNEL_24 

Channel 24 mask.

ADC_MASK_CHANNEL_25 

Channel 25 mask.

ADC_MASK_CHANNEL_26 

Channel 26 mask.

ADC_MASK_CHANNEL_27 

Channel 27 mask.

ADC_MASK_CHANNEL_28 

Channel 28 mask.

ADC_MASK_TEMPERATURE 

Temperature sensor channel mask.

ADC_MASK_VOLT 

Voltage reference channel mask.

ADC_MASK_SENSORS 

All sensor channel mask.

◆ adc_add_t

enum adc_add_t

ADC data sample addition and averaging options

Enumerator
ADC_ADD_OFF 

Addition turned off for channels/sensors.

ADC_ADD_TWO 

Add two samples.

ADC_ADD_THREE 

Add three samples.

ADC_ADD_FOUR 

Add four samples.

ADC_ADD_SIXTEEN 

Add sixteen samples.

ADC_ADD_AVERAGE_TWO 

Average two samples.

ADC_ADD_AVERAGE_FOUR 

Average four samples.

ADC_ADD_AVERAGE_EIGHT 

Average eight samples.

ADC_ADD_AVERAGE_SIXTEEN 

Add sixteen samples.

◆ adc_clear_t

ADC clear after read definitions

Enumerator
ADC_CLEAR_AFTER_READ_OFF 

Clear after read off.

ADC_CLEAR_AFTER_READ_ON 

Clear after read on.

◆ adc_vref_control_t

Enumerator
ADC_VREF_CONTROL_VREFH 

VREFAMPCNT reset value. VREFADC Output voltage is Hi-Z.

ADC_VREF_CONTROL_1_5V_OUTPUT 

BGR turn ON. VREFADC Output voltage is 1.5 V.

ADC_VREF_CONTROL_2_0V_OUTPUT 

BGR turn ON. VREFADC Output voltage is 2.0 V.

ADC_VREF_CONTROL_2_5V_OUTPUT 

BGR turn ON. VREFADC Output voltage is 2.5 V.

ADC_VREF_CONTROL_AVCC0_AVSS0 

High potential is AVCC0, low potential is AVSS0.

ADC_VREF_CONTROL_VREFH0_AVSS0 

High potential is VREFH0, low potential is AVSS0.

ADC_VREF_CONTROL_IVREF_AVSS0 

High potential is internal reference voltage, low potential is AVSS0. When the high potential is set to the internal reference voltage, wait 5 us after R_ADC_Open() to start an ADC measurement.

ADC_VREF_CONTROL_AVCC0_VREFL0 

High potential is AVCC0, low potential is VREFL0.

ADC_VREF_CONTROL_VREFH0_VREFL0 

High potential is VREFH0, low potential is VREFL0.

ADC_VREF_CONTROL_IVREF_VREFL0 

High potential is internal reference voltage, low potential is VREFL0. When the high potential is set to the internal reference voltage, wait 5 us after R_ADC_Open() to start an ADC measurement.

◆ adc_sample_state_reg_t

ADC sample state registers

Enumerator
ADC_SAMPLE_STATE_CHANNEL_0 

Sample state register channel 0.

ADC_SAMPLE_STATE_CHANNEL_1 

Sample state register channel 1.

ADC_SAMPLE_STATE_CHANNEL_2 

Sample state register channel 2.

ADC_SAMPLE_STATE_CHANNEL_3 

Sample state register channel 3.

ADC_SAMPLE_STATE_CHANNEL_4 

Sample state register channel 4.

ADC_SAMPLE_STATE_CHANNEL_5 

Sample state register channel 5.

ADC_SAMPLE_STATE_CHANNEL_6 

Sample state register channel 6.

ADC_SAMPLE_STATE_CHANNEL_7 

Sample state register channel 7.

ADC_SAMPLE_STATE_CHANNEL_8 

Sample state register channel 8.

ADC_SAMPLE_STATE_CHANNEL_9 

Sample state register channel 9.

ADC_SAMPLE_STATE_CHANNEL_10 

Sample state register channel 10.

ADC_SAMPLE_STATE_CHANNEL_11 

Sample state register channel 11.

ADC_SAMPLE_STATE_CHANNEL_12 

Sample state register channel 12.

ADC_SAMPLE_STATE_CHANNEL_13 

Sample state register channel 13.

ADC_SAMPLE_STATE_CHANNEL_14 

Sample state register channel 14.

ADC_SAMPLE_STATE_CHANNEL_15 

Sample state register channel 15.

ADC_SAMPLE_STATE_CHANNEL_16_TO_31 

Sample state register channel 16 to 31.

◆ adc_compare_cfg_t

ADC comparison settings

◆ adc_window_b_channel_t

ADC Window B channel

◆ adc_window_b_mode_t

ADC Window B comparison mode

◆ adc_group_a_t

ADC action for group A interrupts group B scan. This enumeration is used to specify the priority between Group A and B in group mode.

Enumerator
ADC_GROUP_A_PRIORITY_OFF 

Group A ignored and does not interrupt ongoing group B scan.

ADC_GROUP_A_GROUP_B_WAIT_FOR_TRIGGER 

Group A interrupts Group B(single scan) which restarts at next Group B trigger.

ADC_GROUP_A_GROUP_B_RESTART_SCAN 

Group A interrupts Group B(single scan) which restarts immediately after Group A scan is complete.

ADC_GROUP_A_GROUP_B_CONTINUOUS_SCAN 

Group A interrupts Group B(continuous scan) which continues scanning without a new Group B trigger.

◆ adc_double_trigger_t

ADC double-trigger mode definitions

Enumerator
ADC_DOUBLE_TRIGGER_DISABLED 

Double-triggering disabled.

ADC_DOUBLE_TRIGGER_ENABLED 

Double-triggering enabled.

ADC_DOUBLE_TRIGGER_ENABLED_EXTENDED 

Double-triggering enabled on both ADC ELC events.

◆ adc_start_source_t

ADC Trigger synchronous start source Note: not all sources are available for all MCUs or channels. See User Manual for more information.

Enumerator
ADC_START_SOURCE_DISABLED 

ELC/GPT Start source disabled (For use with software start)

ADC_START_SOURCE_ASYNC_EXTERNAL 

External Trigger Input.

ADC_START_SOURCE_ELC_AD0 

ELC_AD0 (Converter 0 and Converter 1)

ADC_START_SOURCE_ELC_AD1 

ELC_AD1 (Converter 0 and Converter 1)

ADC_START_SOURCE_ELC_AD01 

ELC_AD0 and ELC_AD1 (Converter 0) also ELC_AD0 and ELC_AD1 (Converter 1)

ADC_START_SOURCE_GPT_A0_A4 

GTADTRA0 (Converter 0) and GTADTRA4 (Converter 1)

ADC_START_SOURCE_GPT_B0_B4 

GTADTRB0 (Converter 0) and GTADTRB4 (Converter 1)

ADC_START_SOURCE_GPT_A1_A5 

GTADTRA1 (Converter 0) and GTADTRB5 (Converter 1)

ADC_START_SOURCE_GPT_B1_B5 

GTADTRB1 (Converter 0) and GTADTRB5 (Converter 1)

ADC_START_SOURCE_GPT_A2_A6 

GTADTRA2 (Converter 0) and GTADTRA6 (Converter 1)

ADC_START_SOURCE_GPT_B2_B6 

GTADTRB2 (Converter 0) and GTADTRB6 (Converter 1)

ADC_START_SOURCE_GPT_A3_A7 

GTADTRA3 (Converter 0) and GTADTRA7 (Converter 1)

ADC_START_SOURCE_GPT_B3_B7 

GTADTRB3 (Converter 0) and GTADTRB7 (Converter 1)

ADC_START_SOURCE_GPT_AB0_AB4 

GTADTRA/B0 (Converter 0) and GTADTRA/B4 (Converter 1)

ADC_START_SOURCE_GPT_AB1_AB5 

GTADTRA/B1 (Converter 0) and GTADTRA/B5 (Converter 1)

ADC_START_SOURCE_GPT_AB2_AB6 

GTADTRA/B2 (Converter 0) and GTADTRA/B6 (Converter 1)

ADC_START_SOURCE_GPT_AB3_AB7 

GTADTRA/B3 (Converter 0) and GTADTRA/B7 (Converter 1)

Function Documentation

◆ R_ADC_Open()

fsp_err_t R_ADC_Open ( adc_ctrl_t p_ctrl,
adc_cfg_t const *const  p_cfg 
)

Sets the operational mode, trigger sources, interrupt priority, and configurations for the peripheral as a whole. If interrupt is enabled, the function registers a callback function pointer for notifying the user whenever a scan has completed.

Return values
FSP_SUCCESSModule is ready for use.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_ALREADY_OPENThe instance control structure has already been opened.
FSP_ERR_IRQ_BSP_DISABLEDA callback is provided, but the interrupt is not enabled.
FSP_ERR_IP_CHANNEL_NOT_PRESENTThe requested unit does not exist on this MCU.
FSP_ERR_INVALID_HW_CONDITIONThe ADC clock must be at least 1 MHz

◆ R_ADC_ScanCfg()

fsp_err_t R_ADC_ScanCfg ( adc_ctrl_t p_ctrl,
void const *const  p_channel_cfg 
)

Configures the ADC scan parameters. Channel specific settings are set in this function. Pass a pointer to adc_channel_cfg_t to p_channel_cfg.

Note
This starts group B scans if adc_channel_cfg_t::priority_group_a is set to ADC_GROUP_A_GROUP_B_CONTINUOUS_SCAN.
Return values
FSP_SUCCESSChannel specific settings applied.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.

◆ R_ADC_CallbackSet()

fsp_err_t R_ADC_CallbackSet ( adc_ctrl_t *const  p_api_ctrl,
void(*)(adc_callback_args_t *)  p_callback,
void const *const  p_context,
adc_callback_args_t *const  p_callback_memory 
)

Updates the user callback and has option of providing memory for callback structure. Implements adc_api_t::callbackSet

Return values
FSP_SUCCESSCallback updated successfully.
FSP_ERR_ASSERTIONA required pointer is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_NO_CALLBACK_MEMORYp_callback is non-secure and p_callback_memory is either secure or NULL.

◆ R_ADC_ScanStart()

fsp_err_t R_ADC_ScanStart ( adc_ctrl_t p_ctrl)

Starts a software scan or enables the hardware trigger for a scan depending on how the triggers were configured in the R_ADC_Open call. If the unit was configured for ELC or external hardware triggering, then this function allows the trigger signal to get to the ADC unit. The function is not able to control the generation of the trigger itself. If the unit was configured for software triggering, then this function starts the software triggered scan.

Precondition
Call R_ADC_ScanCfg after R_ADC_Open before starting a scan.
On MCUs that support calibration, call R_ADC_Calibrate and wait for calibration to complete before starting a scan.
Return values
FSP_SUCCESSScan started (software trigger) or hardware triggers enabled.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.
FSP_ERR_NOT_INITIALIZEDUnit is not initialized.
FSP_ERR_IN_USEAnother scan is still in progress (software trigger).

◆ R_ADC_ScanGroupStart()

fsp_err_t R_ADC_ScanGroupStart ( adc_ctrl_t p_ctrl,
adc_group_mask_t  group_id 
)

adc_api_t::scanStart is not supported on the ADCH. Use scanStart instead.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_ADC_ScanStop()

fsp_err_t R_ADC_ScanStop ( adc_ctrl_t p_ctrl)

Stops the software scan or disables the unit from being triggered by the hardware trigger (ELC or external) based on what type of trigger the unit was configured for in the R_ADC_Open function. Stopping a hardware triggered scan via this function does not abort an ongoing scan, but prevents the next scan from occurring. Stopping a software triggered scan aborts an ongoing scan.

Return values
FSP_SUCCESSScan stopped (software trigger) or hardware triggers disabled.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.
FSP_ERR_NOT_INITIALIZEDUnit is not initialized.

◆ R_ADC_StatusGet()

fsp_err_t R_ADC_StatusGet ( adc_ctrl_t p_ctrl,
adc_status_t p_status 
)

Provides the status of any scan process that was started, including scans started by ELC or external triggers and calibration scans on MCUs that support calibration.

Return values
FSP_SUCCESSModule status stored in the provided pointer p_status
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.

◆ R_ADC_Read()

fsp_err_t R_ADC_Read ( adc_ctrl_t p_ctrl,
adc_channel_t const  reg_id,
uint16_t *const  p_data 
)

Reads conversion results from a single channel or sensor.

Return values
FSP_SUCCESSData read into provided p_data.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.
FSP_ERR_NOT_INITIALIZEDUnit is not initialized.

◆ R_ADC_Read32()

fsp_err_t R_ADC_Read32 ( adc_ctrl_t p_ctrl,
adc_channel_t const  reg_id,
uint32_t *const  p_data 
)

Reads conversion results from a single channel or sensor register into a 32-bit result.

Return values
FSP_SUCCESSData read into provided p_data.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.
FSP_ERR_NOT_INITIALIZEDUnit is not initialized.

◆ R_ADC_SampleStateCountSet()

fsp_err_t R_ADC_SampleStateCountSet ( adc_ctrl_t p_ctrl,
adc_sample_state_t p_sample 
)

Sets the sample state count for individual channels. This only needs to be set for special use cases. Normally, use the default values out of reset.

Note
The sample states for the temperature and voltage sensor are set in R_ADC_ScanCfg.
Return values
FSP_SUCCESSSample state count updated.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_INITIALIZEDUnit is not initialized.
FSP_ERR_NOT_OPENUnit is not open.

◆ R_ADC_InfoGet()

fsp_err_t R_ADC_InfoGet ( adc_ctrl_t p_ctrl,
adc_info_t p_adc_info 
)

Returns the address of the lowest number configured channel and the total number of bytes to be read in order to read the results of the configured channels and return the ELC Event name. If no channels are configured, then a length of 0 is returned.

Also provides the temperature sensor slope and the calibration data for the sensor if available on this MCU. Otherwise, invalid calibration data of 0xFFFFFFFF will be returned.

Note
In group mode, information is returned for group A only. Calculating information for group B is not currently supported.
Return values
FSP_SUCCESSInformation stored in p_adc_info.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.

◆ R_ADC_Close()

fsp_err_t R_ADC_Close ( adc_ctrl_t p_ctrl)

This function ends any scan in progress, disables interrupts, and removes power to the A/D peripheral.

Return values
FSP_SUCCESSModule closed.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.

◆ R_ADC_Calibrate()

fsp_err_t R_ADC_Calibrate ( adc_ctrl_t *const  p_ctrl,
void const *  p_extend 
)

Initiates calibration of the ADC on MCUs that require calibration. This function must be called before starting a scan on MCUs that require calibration.

Calibration is complete when the callback is called with ADC_EVENT_CALIBRATION_COMPLETE or when R_ADC_StatusGet returns ADC_STATUS_IDLE. Reference Figure 32.35 "Software flow and operation example of calibration operation." in the RA2A1 manual R01UH0888EJ0100.

ADC calibration time: 12 PCLKB + 774,930 ADCLK. (Reference Table 32.16 "Required calibration time (shown as the number of ADCLK and PCLKB cycles)" in the RA2A1 manual R01UH0888EJ0100. The lowest supported ADCLK is 1MHz.

Calibration will take a minimum of 24 milliseconds at 32 MHz PCLKB and ADCLK. This wait could take up to 780 milliseconds for a 1 MHz PCLKD (ADCLK).

Parameters
[in]p_ctrlPointer to the instance control structure
[in]p_extendUnused argument. Pass NULL.
Return values
FSP_SUCCESSCalibration successfully initiated.
FSP_ERR_INVALID_HW_CONDITIONA scan is in progress or hardware triggers are enabled.
FSP_ERR_UNSUPPORTEDCalibration not supported on this MCU.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.

◆ R_ADC_OffsetSet()

fsp_err_t R_ADC_OffsetSet ( adc_ctrl_t *const  p_ctrl,
adc_channel_t const  reg_id,
int32_t  offset 
)

adc_api_t::offsetSet is not supported on the ADC.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.