|
fsp_err_t | R_ADC_C_Open (adc_ctrl_t *p_ctrl, adc_cfg_t const *const p_cfg) |
|
fsp_err_t | R_ADC_C_ScanCfg (adc_ctrl_t *p_ctrl, void const *const p_channel_cfg) |
|
fsp_err_t | R_ADC_C_InfoGet (adc_ctrl_t *p_ctrl, adc_info_t *p_adc_info) |
|
fsp_err_t | R_ADC_C_ScanStart (adc_ctrl_t *p_ctrl) |
|
fsp_err_t | R_ADC_C_ScanGroupStart (adc_ctrl_t *p_ctrl, adc_group_mask_t group_id) |
|
fsp_err_t | R_ADC_C_ScanStop (adc_ctrl_t *p_ctrl) |
|
fsp_err_t | R_ADC_C_StatusGet (adc_ctrl_t *p_ctrl, adc_status_t *p_status) |
|
fsp_err_t | R_ADC_C_Read (adc_ctrl_t *p_ctrl, adc_channel_t const reg_id, uint16_t *const p_data) |
|
fsp_err_t | R_ADC_C_Read32 (adc_ctrl_t *p_ctrl, adc_channel_t const reg_id, uint32_t *const p_data) |
|
fsp_err_t | R_ADC_C_SampleStateCountSet (adc_ctrl_t *p_ctrl, uint16_t num_states) |
|
fsp_err_t | R_ADC_C_Close (adc_ctrl_t *p_ctrl) |
|
fsp_err_t | R_ADC_C_OffsetSet (adc_ctrl_t *const p_ctrl, adc_channel_t const reg_id, int32_t offset) |
|
fsp_err_t | R_ADC_C_Calibrate (adc_ctrl_t *const p_ctrl, void const *p_extend) |
|
fsp_err_t | R_ADC_C_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) |
|
Driver for the ADC peripheral on RZ/A3UL. This module implements the ADC Interface.
Overview
Features
The ADC module supports the following features:
- 12 bit resolution depending on the MPU
- Supports selection of multiple analog input channels
- Configurable scan start trigger:
- Software scan triggers
- Hardware scan triggers
- Asynchronous trigger using an external pin (ADC_TRG)
- Synchronous trigger using the multi-function timer pulse unit 3 (MTU3a)
- In hardware trigger mode, the available trigger input modes are auto mode and step mode
- External scan triggers from the ADTRGn port pins
- Configurable operating mode:
- Select mode to convert the specified single analog input channel
- Scan mode to convert the analog inputs of arbitrarily selected channels in ascending order of channel number
- 1-buffer mode or 4-buffer mode can be specified for storing the A/D conversion result
- Configurable conversion mode:
- Single mode to proceed A/D conversion only once
- Repeat mode to repeatedly proceed A/D conversion *1
- Optional callback when scan completes
- An A/D conversion end interrupt (INTAD) can be generated on completion of A/D conversion
- The division ratio of ADC_ADCLK (TSU clock) can only be set to 4, and other settings are prohibited
- Sample and hold support
*1 Repeat mode is valid only in hardware trigger mode and step mode.
Configuration
Build Time Configurations for r_adc_c
The following build time configurations are defined in fsp_cfg/r_adc_c_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. |
Configurations for Analog > ADC Driver on r_adc_c
This module can be added to the Stacks tab via New Stack > Analog > ADC Driver on r_adc_c.
Configuration | Options | Default | Description |
General > Name | Name must be a valid C symbol | g_adc0 | Module name |
General > Trigger mode |
-
Software trgger mode
-
Hardware trgger mode
| Software trgger mode | Select trigger mode. |
General > Operating mode |
| Scan mode | Select the operating mode. |
General > Conversion mode |
| Single mode | Select the conversion mode. |
General > Buffer mode |
-
1-buffer mode
-
4-buffer mode
| 1-buffer mode | Select the buffer mode.4-buffer mode is prohibited in scan mode. |
General > Analog input channel |
| | Specify the analog input channel.Multiple selection is prohibited in select mode. |
General > Sampling time | Value must be between 6 and 2800 | 6 | Set the sampling time.(unit:ADIVCLK cycle) |
General > Number of stages of the AD external trigger pin filter |
-
Disabled
-
4 stages
-
8 stages
-
12 stages
-
16 stages
| Disabled | Select the number of stages of the AD external trigger pin filter.The signal to be filtered is ADC_ADCLK(TSUϕ) (80 MHz). |
Hardware trigger mode > Hardware trigger source | Refer to the RZA Configuration tool for available options. | External trigger input (ADC_TRG) | Select hardware trigger source. |
Hardware trigger mode > Valid edge of the trigger source (Only when ADC_TRG is selected) |
-
Falling edge
-
Rising edge
-
Both edges
| Falling edge | Select the valid edge of the trigger. |
Hardware trigger mode > Trigger input mode |
| Auto mode | Selects the trigger input mode. |
Interrupts > Callback | Name must be a valid C symbol | NULL | A user callback function can be provided here. If this callback function is provided, it is called from the interrupt service routine (ISR) |
Interrupts > Conversion end interrupt Enable |
| Disabled | Enable or disable the conversion end interrupt. |
Interrupts > Conversion end Interrupt Priority | Value must be between 0 and 31 | 24 | Select the interrupt priority for Conversion end. |
Clock Configuration
The ADC clock is ADC_ADCLK(TSU clock)(80 MHz)
Pin Configuration
The ADC_CHx pins are analog input channels that can be used with the ADC.
ADC_TRG can be used to start scans with an external trigger. 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 Conversion Modes
Single mode and repeat mode are available.
Single-scan Mode
In single scan mode, one or more specified channels are scanned once per trigger.
Repeat-scan Mode
In repeat scan mode, a single trigger is required to start the scan. Scans continue until R_ADC_C_ScanStop() is called.
ADC Trigger Modes
Software trigger mode and hardware trigger mode are the two types of trigger modes in which the trigger is the timing for starting the A/D conversion processing.
Software-trigger Mode
In software trigger mode, A/D conversion is started for the input of the ADC_CH1, ADC_CH0 pins. The hardware trigger is invalid when software trigger mode is set.
Hardware-trigger Mode
There are two triggers in hardware trigger mode: asynchronous trigger using the ADC_TRG pin as the activation source and synchronous trigger using the multi-function timer pulse unit 3 (MTU3a) as the activation source. In hardware trigger mode, the available trigger input modes are auto mode and step mode. In auto mode, when a hardware trigger is input once, A/D conversion is repeated automatically for the conversion count in accordance with the specified conversion settings. In step mode, A/D conversion proceeds every time a hardware trigger is input. For example, if select mode, single mode, and 4- buffer mode are selected, conversion finishes when a hardware trigger has been input four times.
ADC Operating Modes
There are two operating modes: select mode and scan mode. The select mode has 1-buffer mode and 4-buffer mode as sub-modes.
Select Mode
A/D conversion proceeds for the analog input specified. The A/D conversion results are stored in the ADCR3 to ADCR0 registers corresponding to the analog inputs. In select mode, 1-buffer mode or 4-buffer mode can be used as the method for storing the A/D conversion results. Only one channel is selectable for A/D conversion in select mode.
In 1-buffer mode, A/D conversion proceeds only once for the analog input specified. This mode is usable for reading the result of a single conversion.
In 4-buffer mode, A/D conversion proceeds four times for the analog input specified and the conversion results are stored ADCR3 to ADCR0 registers. This mode is usable for obtaining the average of the A/D conversion results.
Scan Mode
A/D conversion proceeds for the analog inputs of channels selected, in ascending order of channel number. The A/D conversion results are stored in the ADCR3 to ADCR0 registers corresponding to the analog inputs. This mode is usable for constantly monitoring multiple analog signals. In scan mode, only 1-buffer mode can be specified.
When Interrupts Are Not Enabled
If interrupts are not enabled, the R_ADC_C_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.
Sample-State Count Setting
The application program can modify the setting of the sample-state count for analog channels by calling the R_ADC_C_SampleStateCountSet() API function. To modify the sample-state count, set the number of states when calling the R_ADC_C_SampleStateCountSet() API function. Valid sample state counts are 6-2800.
Examples
Basic Example
This is a basic example of minimal use of the ADC in an application.
{
};
void adc_basic_example (void)
{
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
{
}
uint16_t channel1_conversion_result;
assert(FSP_SUCCESS == err);
}
Repeat Mode Example
This example shows how to perform repeated AD conversions.
{
.sampling_time = 100,
};
{
.p_callback = adc_callback,
.p_context = NULL,
.p_extend = &g_adc0_cfg_extend,
.scan_end_irq = ADC_INTAD_IRQn,
.scan_end_ipl = 12,
};
{
};
{
.p_cfg = &g_adc0_cfg,
.p_channel_cfg = &g_adc0_channel_cfg,
.p_api = &g_adc_on_adc_c
};
{
(void) p_unused;
uint16_t channel1_conversion_result;
assert(FSP_SUCCESS == err);
}
void adc_repeatmode_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);
while (1)
;
}
◆ adc_c_extended_cfg_t
struct adc_c_extended_cfg_t |
Extended configuration structure for ADC.
◆ adc_c_channel_cfg_t
struct adc_c_channel_cfg_t |
ADC channel(s) configuration
◆ adc_c_instance_ctrl_t
struct adc_c_instance_ctrl_t |
◆ adc_c_mask_t
For ADC Scan configuration adc_channel_cfg_t::scan_mask. Use bitwise OR to combine these masks for desired channels.
Enumerator |
---|
ADC_C_MASK_OFF | No channels selected.
|
ADC_C_MASK_CHANNEL_0 | Channel 0 mask.
|
ADC_C_MASK_CHANNEL_1 | Channel 1 mask.
|
◆ adc_c_trigger_mode_t
ADC trigger mode select
Enumerator |
---|
ADC_C_TRIGGER_MODE_SOFTWARE | Software trigger mode.
|
ADC_C_TRIGGER_MODE_HARDWARE | Hardware trigger mode.
|
◆ adc_c_active_trigger_t
ADC hardware trigger source select
Enumerator |
---|
ADC_C_ACTIVE_TRIGGER_EXTERNAL | External trigger input.
|
ADC_C_ACTIVE_TRIGGER_TRGA0N | Compare match with or input capture to MTU0.TGRA.
|
ADC_C_ACTIVE_TRIGGER_TRGA1N | Compare match with or input capture to MTU1.TGRA.
|
ADC_C_ACTIVE_TRIGGER_TRGA2N | Compare match with or input capture to MTU2.TGRA.
|
ADC_C_ACTIVE_TRIGGER_TRGA3N | Compare match with or input capture to MTU3.TGRA.
|
ADC_C_ACTIVE_TRIGGER_TRGA4N | Compare match with or input capture to MTU4.TGRA.
|
ADC_C_ACTIVE_TRIGGER_TRGA6N | Compare match with or input capture to MTU6.TGRA.
|
ADC_C_ACTIVE_TRIGGER_TRGA7N | Compare match with or input capture to MTU7.TGRA.
|
ADC_C_ACTIVE_TRIGGER_TRG0N | Compare match with MTU0.TGRE.
|
ADC_C_ACTIVE_TRIGGER_TRG4AN | Compare match between MTU4.TADCORA and MTU4.TCNT.
|
ADC_C_ACTIVE_TRIGGER_TRG4BN | Compare match between MTU4.TADCORB and MTU4.TCNT.
|
ADC_C_ACTIVE_TRIGGER_TRG4AN_BN | Compare match between MTU4.TADCORA and MTU4.TCNT, or between MTU4.TADCORB and MTU4.TCNT.
|
ADC_C_ACTIVE_TRIGGER_TRG4ABN | Compare match between MTU4.TADCORA and MTU4.TCNT, and between MTU4.TADCORB and MTU4.TCNT (when interrupt skipping function 2 is in use)
|
ADC_C_ACTIVE_TRIGGER_TRG7AN | Compare match between MTU7.TADCORA and MTU7.TCNT.
|
ADC_C_ACTIVE_TRIGGER_TRG7BN | Compare match between MTU7.TADCORB and MTU7.TCNT.
|
ADC_C_ACTIVE_TRIGGER_TRG7AN_BN | Compare match between MTU7.TADCORA and MTU7.TCNT, or between MTU7.TADCORB and MTU7.TCNT.
|
ADC_C_ACTIVE_TRIGGER_TRG7ABN | Compare match between MTU7.TADCORA and MTU7.TCNT, and between MTU7.TADCORB and MTU7.TCNT.
|
◆ adc_c_trigger_edge_t
valid edge of the trigger select
Enumerator |
---|
ADC_C_TRIGGER_EDGE_FALLING | Falling edge.
|
ADC_C_TRIGGER_EDGE_RISING | Rising edge.
|
ADC_C_TRIGGER_EDGE_BOTH | Both edges.
|
◆ adc_c_input_mode_t
ADC trigger input mode select
Enumerator |
---|
ADC_C_INPUT_MODE_AUTO | Auto mode.
|
ADC_C_INPUT_MODE_STEP | Step mode.
|
◆ adc_c_operating_mode_t
ADC operating mode select
Enumerator |
---|
ADC_C_OPERATING_MODE_SCAN | Scan mode.
|
ADC_C_OPERATING_MODE_SELECT | Select mode.
|
◆ adc_c_buffer_mode_t
ADC buffer mode select
Enumerator |
---|
ADC_C_BUFFER_MODE_1 | 1-buffer mode
|
ADC_C_BUFFER_MODE_4 | 4-buffer mode
|
◆ adc_c_filter_stage_setting_t
Select the number of stages of the AD external trigger pin filter.
Enumerator |
---|
ADC_C_FILTER_STAGE_SETTING_DISABLE | Filter is disabled.
|
ADC_C_FILTER_STAGE_SETTING_4 | 12.5 ns (80 MHz) x 4 stages
|
ADC_C_FILTER_STAGE_SETTING_8 | 12.5 ns (80 MHz) x 8 stages
|
ADC_C_FILTER_STAGE_SETTING_12 | 12.5 ns (80 MHz) x 12 stages
|
ADC_C_FILTER_STAGE_SETTING_16 | 12.5 ns (80 MHz) x 16 stages
|
◆ adc_c_interrupt_channel_setting_t
Enable or disable the conversion end interrupt of channel
Enumerator |
---|
ADC_C_INTERRUPT_CHANNEL_SETTING_DISABLE | Interrupt output is disabled.
|
ADC_C_INTERRUPT_CHANNEL_SETTING_ENABLE | Interrupt output is enabled.
|
◆ R_ADC_C_Open()
Initializes the ADC module and applies configurations.
- 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. |
◆ R_ADC_C_ScanCfg()
Configures the ADC_C scan parameters. Channel specific settings are set in this function. Pass a pointer to adc_c_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. |
◆ R_ADC_C_InfoGet()
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. If no channels are configured, then a length of 0 is returned.
- Return values
-
FSP_SUCCESS | Information stored in p_adc_info. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | Unit is not open. |
◆ R_ADC_C_ScanStart()
Start A/D conversion.
- Precondition
- Call R_ADC_C_ScanCfg after R_ADC_C_Open before starting a scan.
- Return values
-
FSP_SUCCESS | Scan started (software trigger) or hardware triggers enabled. |
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_IN_USE | Another scan is still in progress (software trigger). |
◆ R_ADC_C_ScanGroupStart()
adc_api_t::scanGroupStart is not supported. Use scanStart instead.
- Return values
-
FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
◆ R_ADC_C_ScanStop()
Stop A/D conversion.
- 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_C_StatusGet()
Get current ADC_C status and store it in provided pointer p_status.
- 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 | Unit is not open. |
◆ R_ADC_C_Read()
Reads conversion results from a single 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. |
◆ R_ADC_C_Read32()
Reads conversion results from a single 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 | Unit is not open. |
FSP_ERR_NOT_INITIALIZED | Unit is not initialized. |
◆ R_ADC_C_SampleStateCountSet()
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_C_ScanCfg.
- Return values
-
FSP_SUCCESS | Sample state count updated. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_INITIALIZED | Unit is not initialized. |
FSP_ERR_NOT_OPEN | Unit is not open. |
FSP_ERR_IN_USE | A/D conversion ongoing. |
◆ R_ADC_C_Close()
This function ends any scan 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 | Unit is not open. |
◆ R_ADC_C_OffsetSet()
adc_api_t::offsetSet is not supported.
- Return values
-
FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
◆ R_ADC_C_Calibrate()
adc_api_t::calibrate is not supported.
- Return values
-
FSP_ERR_UNSUPPORTED | Calibration not supported on this MCU. |
◆ R_ADC_C_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_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_NO_CALLBACK_MEMORY | p_callback is non-secure and p_callback_memory is either secure or NULL. |