|
fsp_err_t | R_ADC_D_Open (adc_ctrl_t *p_ctrl, adc_cfg_t const *const p_cfg) |
|
fsp_err_t | R_ADC_D_ScanCfg (adc_ctrl_t *p_ctrl, void const *const p_channel_cfg) |
|
fsp_err_t | R_ADC_D_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_D_ScanStart (adc_ctrl_t *p_ctrl) |
|
fsp_err_t | R_ADC_D_ScanGroupStart (adc_ctrl_t *p_ctrl, adc_group_mask_t group_id) |
|
fsp_err_t | R_ADC_D_ScanStop (adc_ctrl_t *p_ctrl) |
|
fsp_err_t | R_ADC_D_StatusGet (adc_ctrl_t *p_ctrl, adc_status_t *p_status) |
|
fsp_err_t | R_ADC_D_Read (adc_ctrl_t *p_ctrl, adc_channel_t const reg_id, uint16_t *const p_data) |
|
fsp_err_t | R_ADC_D_Read32 (adc_ctrl_t *p_ctrl, adc_channel_t const reg_id, uint32_t *const p_data) |
|
fsp_err_t | R_ADC_D_InfoGet (adc_ctrl_t *p_ctrl, adc_info_t *p_adc_info) |
|
fsp_err_t | R_ADC_D_Close (adc_ctrl_t *p_ctrl) |
|
fsp_err_t | R_ADC_D_Calibrate (adc_ctrl_t *const p_ctrl, void const *p_extend) |
|
fsp_err_t | R_ADC_D_OffsetSet (adc_ctrl_t *const p_ctrl, adc_channel_t const reg_id, int32_t offset) |
|
fsp_err_t | R_ADC_D_SnoozeModePrepare (adc_ctrl_t *const p_ctrl) |
|
fsp_err_t | R_ADC_D_SnoozeModeExit (adc_ctrl_t *const p_ctrl) |
|
Driver for ADC_D version of the ADC12 peripheral on RA MCUs. This module implements the ADC Interface.
Overview
Features
The ADC module supports the following features:
- 8-, 10-, or 12-bit maximum resolution depending on the MCU
- Configure scans to include:
- Single channel or Scan channels
- Temperature sensor channel
- Voltage sensor channel
- Configurable scan start trigger:
- Software scan triggers with no-wait mode or wait mode
- Hardware scan triggers with no-wait mode or wait mode (timer expiration, for example)
- Configurable scan mode:
- One-shot scan mode, where each trigger starts a single scan
- Sequential scan mode, where all channels are scanned continuously
- Optional callback when scan completes
- Generated an interrupt request when ADLL <= ADCRn <= ADUL
- Generated an interrupt request when ADUL < ADCRn or ADLL > ADCRn
- Test mode support
- Checking whether the ADC_D converter is operating normally
Configuration
Build Time Configurations for r_adc_d
The following build time configurations are defined in fsp_cfg/r_adc_d_cfg.h:
Configuration | Options | Default | Description |
Parameter Checking |
-
Default (BSP)
-
Enabled
-
Disabled
| Default (BSP) | If selected code for parameter checking is included in the build. |
Internal Reference Voltage Support |
| Disabled | Enable Internal Reference Voltage support for the ADC module. |
Snooze Mode Support |
| Disabled | Enable Snooze Mode Support. |
Interrupt Support |
| Enabled | Enable Scan End Interrupt support for the ADC module. |
Configurations for Analog > ADC (r_adc_d)
This module can be added to the Stacks tab via New Stack > Analog > ADC (r_adc_d).
Configuration | Options | Default | Description |
General |
Name | Name must be a valid C symbol | g_adc0 | Module name |
Resolution |
| 12-Bit | Specifies the conversion resolution for this unit. |
Conversion operation |
| One-shot | Specifies the conversion operation mode. |
Operation trigger |
| Wait | Specifies the operation trigger mode. |
Operation voltage |
-
Normal 1
-
Normal 2
-
Low voltage 1
-
Low voltage 2
| Normal 1 | Specifies operation voltage mode. |
Conversion Clock (fAD) |
-
PCLK
-
PCLK/2
-
PCLK/4
-
PCLK/8
-
PCLK/16
-
PCLK/32
| PCLK | Specifies divider for conversion clock (fAD). |
Input |
Channel Selection Mode |
| Select | Specifies the channel selection mode. |
A/D Input channel | MCU Specific Options | | Specifies the input channels. |
Negative Side Reference Voltage |
| VSS | Selection of the Negative Side Reference Voltage. |
Positive Side Reference Voltage |
-
VCC
-
VREFH0
-
Internal Reference Voltage
| VCC | Selection of the Positive Side Reference Voltage. |
Interrupts |
Interrupts > Conversion Result upper/lower bound value setting |
Generates an interrupt request (INTAD) |
-
The interrupt signal is output when the ADLL register <= the ADCRn register <= the ADUL register
-
The interrupt signal is output when the ADCRn register < the ADLL register or the ADUL register < the ADCRn register
| The interrupt signal is output when the ADLL register <= the ADCRn register <= the ADUL register | Specify condition generates an interrupt(INTAD) after each time the ADC scan completes. |
Upper bound (ADUL) value | Must be a valid integer | 255 | Specify the upper limit conversion value that corresponds to the condition to generate an interrupt request (INTAD). |
Lower bound (ADLL) value | Must be a valid integer | 0 | Specify the lower limit conversion value that corresponds to the condition to generate an interrupt request (INTAD). |
Callback | Name must be a valid C symbol | NULL | 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 Priority | MCU Specific Options | | Select scan end interrupt priority. |
Start trigger source | MCU Specific Options | | Specifies the trigger type to be used for this unit. |
Clock Configuration
The ADC_D conversion clock source may be configured to use ICLK with a selectable division ratio.
The ADC_D clock must be at least 1 MHz when the ADC is used.
Pin Configuration
The ANxxx pins are analog input channels that can be used with the ADC_D.
Usage Notes
ADC_D Operational Conversion
The driver supports two operation conversion mode: One-shot scan and Sequential scan modes. For each time conversion, ADC peripheral only converts for each a pin or group of pins depending on channels selection mode, it can be changed to another pin or group of other pins by calling R_ADC_D_ScanCfg().
Oneshot-scan Mode
In One-shot scan mode, one or group specified channels are scanned once per trigger.
Sequential-scan Mode
In Sequential scan mode, a single trigger is required to start the scan. Scans continue until R_ADC_D_ScanStop() is called.
When Interrupt Is Not Enabled
If interrupts are not enabled, the R_ADC_D_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.
When Interrupt Is Enabled
An interrupt is generated depend on setting condition of converted ADC result is in range or out of range of Upper Bound Value (ADUL) and Low Bound Value (ADLL). Please refer to "Figure ADRCK Bit Interrupt Signal Generation Range" in RA0E1 User's Manual (R01UH1040EJ0100).
Selecting Reference Voltage
The ADC_D positive and negative side reference voltages may be configured for selected MCU's. Please refer to the RA Configuration editor in e2 studio for further details.
- Note
- When the internal reference voltage is selected as the positive side reference voltage. Please refer condition as below
- Select operation voltage is low-voltage mode 1 or 2.
- The conversion clock (fAD) must be range 1 to 2 MHZ.
- Do not setting select internal reference voltage or temperature sensor channel as an A/D conversion channel.
Selecting Internal Reference Voltage or Temperature Sensor channel
When the internal reference voltage or temperature sensor output voltage is selected as the target for A/D conversion, please setting operation voltage is normal mode 2 or low-voltage mode 2.
- Note
- when using operation voltage is low-voltage mode 2, setting a conversion clock (fAD) is less than or equal 16 MHz.
Selecting Conversion Clock
Range for frequency of Conversion Clock (fAD) depends on frequency of ICK. Please refer table as below.
Frequency of ICLK | Frequency of Conversion Clock (fAD) |
4 MHz < ICLK <= 32 MHz | ICLK to ICLK/32 |
1 MHz <= fCLK <= 4 MHz | ICLK to ICLK/4 |
Selecting Operation Voltage
The operation voltage is selectable depending on the analog input channel, VREFH0 voltage, operation mode, and ICLK. For detail, refer table A/D Conversion Time Selection in Section A/D Converter (ADC) in RA0E1 User's Manual (R01UH1040EJ0100).
- Note
- When operation voltage is low-voltage modes 1 or 2 in the Electrical Characteristics section in RA0E1 User's Manual (R01UH1040EJ0100), setting frequency of ICLK should be used with a frequency less than or equal 24 MHz.
ADC_D conversion in Test Mode
The conversion target for testing can be selected by using the Input > A/D Input channel property in the module configuration.
- Note
- For more details on the method of checking, refer to section 25.8 "Testing of the A/D Converter" in RA0E1 User's Manual (R01UH1040EJ0100).
Using the Temperature Sensor with the ADC_D
The ADC_D 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 (degrees C)
- Vs: Voltage output by the temperature sensor at the time of temperature measurement (Volts)
- T1: Temperature experimentally measured at one point (degrees 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 (degrees C)
- V2: Voltage output by the temperature sensor at the time of measurement of T2 (Volts)
- Slope: Temperature gradient of the temperature sensor (V/degrees C); slope = (V2 - V1)/ (T2 - T1)
- Note
- The slope value can be obtained for each in the Electrical Characteristics Chapter - TSN Characteristics Table, Temperature slope entry.
For the setting flow, see section 25.6.5. "Example of Using the ADC12 when Selecting the Temperature Sensor Output Voltage or Internal Reference Voltage, and Software Trigger No-wait Mode and One-shot Conversion Mode" in RA0E1 User's Manual (R01UH1040EJ0100).
Examples
Basic Example
This is a basic example of minimal use of the ADC_D in an application.
{
};
{
}
void adc_d_basic_example (void)
{
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
{
}
uint16_t channel1_conversion_result;
assert(FSP_SUCCESS == err);
}
Temperature Sensor Example
This example shows how to calculate the MCU temperature using the ADC_D and the temperature sensor.
#define ADC_D_EXAMPLE_TEMPERATURE_VOLTAGE_V1 (1050000)
#define ADC_D_EXAMPLE_VCC_MICROVOLT (3300000)
#define ADC_D_EXAMPLE_TEMPERATURE_RESOLUTION (4096)
#define ADC_D_EXAMPLE_ADC_TEST_TEMPERATURE_CELSIUS_T1 (25)
#define ADC_PRV_COEFFICIENT (0.5)
void adc_d_temperature_example (void)
{
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
{
}
{
}
uint16_t temperature_conversion_result;
assert(FSP_SUCCESS == err);
int32_t slope_uv_per_c = BSP_FEATURE_ADC_TSN_SLOPE;
int32_t v1_uv = ADC_D_EXAMPLE_TEMPERATURE_VOLTAGE_V1;
int32_t vs_uv =
(int32_t) (((temperature_conversion_result - ADC_PRV_COEFFICIENT) * ADC_D_EXAMPLE_VCC_MICROVOLT) /
ADC_D_EXAMPLE_TEMPERATURE_RESOLUTION);
int32_t temperature_c =
(int32_t) ((vs_uv - v1_uv) / slope_uv_per_c + ADC_D_EXAMPLE_ADC_TEST_TEMPERATURE_CELSIUS_T1);
if ((temperature_c < 20) || (temperature_c > 25))
{
__BKPT(0);
}
}
Requesting Snooze mode using ADC_D Hardware Trigger
ADC_D can request snooze mode via a hardware trigger and perform an ADC conversion in the following modes:
- Hardware trigger wait mode (select mode, one-shot conversion mode)
- Hardware trigger wait mode (scan mode, one-shot conversion mode)
In order to enable this functionality, the application must call R_ADC_D_SnoozeModePrepare() immediately before entering software standby mode, and call R_ADC_D_SnoozeModeExit() immediately after returning from software standby mode.
void adc_d_snooze_request_example (void)
{
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
}
◆ adc_d_channel_cfg_t
struct adc_d_channel_cfg_t |
ADC_D channel(s) configuration
◆ adc_d_extended_cfg_t
struct adc_d_extended_cfg_t |
Extended configuration structure for ADC.
◆ adc_d_instance_ctrl_t
struct adc_d_instance_ctrl_t |
◆ adc_d_channel_mode_t
ADC_D channels mode selection
Enumerator |
---|
ADC_D_CHANNEL_MODE_SELECT | Select mode.
|
ADC_D_CHANNEL_MODE_SCAN | Scan mode.
|
◆ adc_d_voltage_mode_t
Operation voltage mode selection
Enumerator |
---|
ADC_D_VOLTAGE_MODE_NORMAL_1 | Normal 1.
|
ADC_D_VOLTAGE_MODE_NORMAL_2 | Normal 2.
|
ADC_D_VOLTAGE_MODE_LOW_1 | Low voltage 1.
|
ADC_D_VOLTAGE_MODE_LOW_2 | Low voltage 2.
|
◆ adc_d_clock_div_t
Divider for Conversion Clock (fAD)
Enumerator |
---|
ADC_D_CLOCK_DIV_32 | ADC_D clock division ICLK/32.
|
ADC_D_CLOCK_DIV_16 | ADC_D clock division ICLK/16.
|
ADC_D_CLOCK_DIV_8 | ADC_D clock division ICLK/8.
|
ADC_D_CLOCK_DIV_4 | ADC_D clock division ICLK/4.
|
ADC_D_CLOCK_DIV_2 | ADC_D clock division ICLK/2.
|
ADC_D_CLOCK_DIV_1 | ADC_D clock division ICLK/1.
|
◆ adc_d_trigger_source_t
Selection trigger signal
Enumerator |
---|
ADC_D_TRIGGER_SOURCE_TAU0_TMI01 | Timer channel 01 count or capture end interrupt signal.
|
ADC_D_TRIGGER_SOURCE_RTC_ALARM_OR_PERIOD | Realtime clock interrupt signal.
|
ADC_D_TRIGGER_SOURCE_TML0_ITL0 | 32-bit interval timer interrupt signal
|
ADC_D_TRIGGER_SOURCE_ELC | Event input from ELC.
|
ADC_D_TRIGGER_SOURCE_SOFTWARE | Software trigger, this option is controlled by bit ADCS, ADCE.
|
◆ adc_d_trigger_mode_t
Select trigger mode
Enumerator |
---|
ADC_D_TRIGGER_MODE_NO_WAIT | Trigger no-wait mode.
|
ADC_D_TRIGGER_MODE_WAIT | Trigger wait mode.
|
◆ adc_d_conversion_mode_t
Select conversion operation mode
Enumerator |
---|
ADC_D_CONVERSION_MODE_SEQUENTIAL | Continuous conversion mode.
|
ADC_D_CONVERSION_MODE_ONESHOT | Single conversion mode.
|
◆ adc_d_boundary_t
Select the upper limit and lower limit conversion result values
Enumerator |
---|
ADC_D_BOUNDARY_IN_RANGE | The interrupt signal (INTAD) is output in range ADLL and AULL.
|
ADC_D_BOUNDARY_OUT_OF_RANGE | The interrupt signal (INTAD) is output out of range ADLL and AULL.
|
◆ adc_d_negative_vref_t
The negative side reference voltage selection
Enumerator |
---|
ADC_D_NEGATIVE_VREF_VSS | Supplied from VSS.
|
ADC_D_NEGATIVE_VREF_VREFL0 | Supplied from VREFL0.
|
◆ adc_d_positive_vref_t
The positive side reference voltage selection
Enumerator |
---|
ADC_D_POSITIVE_VREF_VCC | Supplied from VSS.
|
ADC_D_POSITIVE_VREF_VREFH0 | Supplied from VREFH0.
|
ADC_D_POSITIVE_VREF_IVREF | Supplied from the internal reference voltage.
|
◆ R_ADC_D_Open()
Initialize the ADC_D peripheral. If interrupt is enabled, the function registers a callback function for notifying the user when a scan has completed. Implements adc_api_t::open.
- Return values
-
FSP_SUCCESS | Module is ready for use. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_ALREADY_OPEN | The instance control structure has already been opened. |
FSP_ERR_IRQ_BSP_DISABLED | A callback is provided, but the interrupt is not enabled. |
FSP_ERR_INVALID_HW_CONDITION | Invalid configuration corresponds to condition HardWare UM. |
◆ R_ADC_D_ScanCfg()
Configures the ADC_D scan parameters. Channel specific settings are set in this function. Pass a pointer to adc_d_channel_cfg_t to p_channel_cfg.
- Return values
-
FSP_SUCCESS | Channel specific settings applied. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | Unit is not open. |
FSP_ERR_INVALID_HW_CONDITION | Invalid configuration corresponds to condition HardWare UM. |
FSP_ERR_INVALID_STATE | Invalid Scan Configuration. |
FSP_ERR_INVALID_CHANNEL | Channel is invalid. |
◆ R_ADC_D_CallbackSet()
Updates the user callback and has option of providing memory for callback structure. Implements adc_api_t::callbackSet
- Return values
-
FSP_SUCCESS | Callback updated successfully. |
FSP_ERR_NOT_OPEN | Unit is not open. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
◆ R_ADC_D_ScanStart()
Starts a software trigger scan or enables the hardware trigger mode for a scan depending on how the triggers were configured in the R_ADC_D_Open call. If the unit was configured for ELC or interrupt hardware triggering, then this function allows the trigger signal to get to the ADC_D. The function is not able to control the generation of the trigger itself.
- Precondition
- Call R_ADC_D_ScanCfg after R_ADC_D_Open before starting a scan.
- Return values
-
FSP_SUCCESS | Scan started (software trigger) or hardware trigger mode enabled. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | ADC_D is not open. |
FSP_ERR_NOT_INITIALIZED | ADC_D is not initialized. |
◆ R_ADC_D_ScanGroupStart()
adc_api_t::scanStart is not supported on the ADC_D. Use scanStart instead.
- Return values
-
FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
◆ R_ADC_D_ScanStop()
Disables the hardware trigger for a scan or select mode and immediately stops converters. This function will abort conversions.
- Return values
-
FSP_SUCCESS | Scan stopped (software trigger) or hardware triggers disabled. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | Unit is not open. |
FSP_ERR_NOT_INITIALIZED | Unit is not initialized. |
◆ R_ADC_D_StatusGet()
Provides the status of any scan process that was started, including scans started by ELC or interrupts triggers.
- Note
- In Hardware no-wait mode, ADCS retains the value 1 after conversion end.
- Return values
-
FSP_SUCCESS | Module status stored in the provided pointer p_status. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | ADC_D is not open. |
◆ R_ADC_D_Read()
Reads conversion results from a channel or sensor.
- Return values
-
FSP_SUCCESS | Data read into provided p_data. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | Unit is not open. |
FSP_ERR_NOT_INITIALIZED | Unit is not initialized. |
FSP_ERR_INVALID_MODE | Invalid configuration for channel_mode. |
◆ R_ADC_D_Read32()
Reads conversion results from a select/scan channel or sensor register into a 32-bit result.
- Return values
-
FSP_SUCCESS | Data read into provided p_data. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | ADC_D is not open. |
FSP_ERR_NOT_INITIALIZED | ADC_D is not initialized. |
FSP_ERR_INVALID_MODE | Invalid configuration for channel_mode. |
◆ R_ADC_D_InfoGet()
Get information of address ADCR to reading the data, determine the size of data that must be read, size data of each transfer, name of the ELC event for the peripheral, name of the peripheral in the ELC list
- Return values
-
FSP_SUCCESS | Information stored in p_adc_info. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | ADC_D is not open. |
FSP_ERR_NOT_INITIALIZED | ADC_D is not initialized. |
◆ R_ADC_D_Close()
This function ends any scan or select mode in progress, disables interrupts, and removes power to the A/D peripheral.
- Return values
-
FSP_SUCCESS | Module closed. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | ADC_D is not open. |
◆ R_ADC_D_Calibrate()
adc_api_t::calibrate is not supported on the ADC_D.
- Return values
-
FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
◆ R_ADC_D_OffsetSet()
adc_api_t::offsetSet is not supported on the ADC_D.
- Return values
-
FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
◆ R_ADC_D_SnoozeModePrepare()
Prepare ADC_D to enter snooze mode via a hardware trigger. This function must be called immediately before entering software standby mode in order to allow the configured hardware trigger to transition the MCU from software standby mode to snooze mode and perform an ADC conversion.
Supported modes for requesting snooze mode via hardware trigger:
- channel_mode = ADC_D_CHANNEL_MODE_SELECT, conversion_operation = ADC_D_CONVERSION_MODE_ONESHOT
- channel_mode = ADC_D_CHANNEL_MODE_SCAN, conversion_operation = ADC_D_CONVERSION_MODE_ONESHOT
- Parameters
-
[in] | p_ctrl | Pointer to the ADC control block |
- Precondition
- The R_ADC_D_ScanStart must be called in advance.
- Return values
-
FSP_SUCCESS | ADC is configured to request Snooze mode. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | ADC_D is not open. |
FSP_ERR_INVALID_MODE | ADC is in an invalid mode for requesting Snooze mode. |
◆ R_ADC_D_SnoozeModeExit()
After exiting snooze mode, if the ADC_D module was in snooze mode, then this function must be called in order to restore ADC operation to normal mode.
- Parameters
-
[in] | p_ctrl | Pointer to the ADC control block |
- Return values
-
FSP_SUCCESS | ADC is configured to request Snooze mode. |
FSP_ERR_INVALID_MODE | ADC is in an invalid mode for requesting Snooze mode. |