RZT Flexible Software Package Documentation
Release v2.2.0
|
|
Driver for the and ADC12 peripherals on RZ microprocessor. This module implements the ADC Interface.
The ADC module supports the following features:
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Multiplex Interrupt |
| Disabled | Enable multiplex interrupt system-wide. |
Configuration | Options | Default | Description |
---|---|---|---|
General > Name | Name must be a valid C symbol | g_adc0 | Module name |
General > Unit | Unit must be a non-negative integer | 0 | Specifies the ADC Unit to be used. |
General > Clear after read |
| On | Specifies if the result register will be automatically cleared after the conversion result is read. |
General > Mode |
| Single Scan | Specifies the mode that this ADC unit is used in. |
General > Double-trigger |
| 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 > Sample and Hold > Sample and Hold Channels (Available only on selected MCUs) |
| Specifies if this channel is included in the Sample and Hold Mask. | |
Input > Sample and Hold > Sample Hold States (Applies only to channels 0, 1, 2) | Must be a valid non-negative integer with configurable value 4 to 255 | 24 | Specifies the updated sample-and-hold count for the channel dedicated sample-and-hold circuit |
Input > Window Compare > Window A > Enable | MCU Specific Options | Enable or disable comparison with Window A. | |
Input > Window Compare > Window A > Channels to compare (channel availability varies by MCU and unit) | Refer to the RZT Configuration tool for available options. | Select channels to be compared to Window A. | |
Input > Window Compare > Window A > Channel comparison mode (channel availability varies by MCU and unit) | Refer to the RZT 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). | |
Input > Window Compare > Window A > Lower Reference | Must be a positive 16-bit integer. | 0 | Set the lower comparison value. |
Input > Window Compare > Window A > Upper Reference | Must be a positive 16-bit integer. | 0 | Set the upper comparison value. |
Input > Window Compare > Window B > Enable | MCU Specific Options | Enable or disable comparison with Window B. | |
Input > Window Compare > Window B > Channel to compare (channel availability varies by MCU and unit) | MCU Specific Options | Select a channel to be compared to Window B. | |
Input > Window Compare > Window B > Comparison mode |
| 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. |
Input > Window Compare > Window B > Lower Reference | Must be a positive 16-bit integer. | 0 | Set the lower comparison value. |
Input > Window Compare > Window B > Upper Reference | Must be a positive 16-bit integer. | 0 | Set the upper comparison value. |
Input > Window Compare > Window Mode |
| 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. |
Input > Start Trigger > Group A | Refer to the RZT Configuration tool for available options. | Disabled | A/D Conversion Start Trigger Select for Group A. |
Input > Start Trigger > Group B | Refer to the RZT Configuration tool for available options. | Disabled | A/D Conversion Start Trigger Select for Group B. |
Input > Start Trigger > Group C Enabled |
| Disabled | Set to true to enable Group C, false to disable Group C. |
Input > Start Trigger > Group C | Refer to the RZT Configuration tool for available options. | Disabled | A/D Conversion Start Trigger Select for Group C. |
Input > Channel Scan Mask (channel availability varies by MCU) | Refer to the RZT 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. | |
Input > Group B Scan Mask (channel availability varies by MCU) | Refer to the RZT Configuration tool for available options. | In group mode, this field specifies which channels belong to group B. | |
Input > Add/Average Count |
| Disabled | Specifies if addition or averaging needs to be done for any of the channels in this unit. |
Input > Addition/Averaging Mask (channel availability varies by MCU and unit) | Refer to the RZT Configuration tool for available options. | Select channels to include in the Addition/Averaging Mask | |
Input > Group C Scan Mask (channel availability varies by MCU) | Refer to the RZT Configuration tool for available options. | In group mode, this field specifies which channels belong to group C. | |
Interrupts > Normal/Group A Trigger | MCU Specific Options | Specifies the trigger type to be used for this unit. | |
Interrupts > Group B Trigger | MCU Specific Options | Specifies the trigger for Group B scanning in group scanning mode. This event is also used to trigger Group A in extended double-trigger mode. | |
Interrupts > Group Priority (Valid only in Group Scan Mode) |
| 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. |
Interrupts > 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. |
Interrupts > Scan End Interrupt Priority | MCU Specific Options | Select scan end interrupt priority. | |
Interrupts > Scan End Group B Interrupt Priority | MCU Specific Options | Select group B scan end interrupt priority. | |
Interrupts > Scan End Group C Interrupt Priority | MCU Specific Options | Select group C scan end interrupt priority. | |
Interrupts > Window Compare A Interrupt Priority | MCU Specific Options | Select Window Compare A interrupt priority. | |
Interrupts > Window Compare B Interrupt Priority | MCU Specific Options | Select Window Compare B interrupt priority. | |
ELC > ADC0 event A > Trigger Source | MCU Specific Options | ELC_SSEL settings. | |
ELC > ADC0 event B > Trigger Source | MCU Specific Options | ELC_SSEL settings. | |
ELC > ADC1 event A > Trigger Source | MCU Specific Options | ELC_SSEL settings. | |
ELC > ADC1 event B > Trigger Source | MCU Specific Options | ELC_SSEL settings. | |
ELC > ADC2 event A > Trigger Source | MCU Specific Options | ELC_SSEL settings. | |
ELC > ADC2 event B > Trigger Source | MCU Specific Options | ELC_SSEL settings. | |
ELC > Output Event Signal |
| Single | A/D Event Link Control. |
Peripheral module clock (Unit 0: PCLKH, Unit 1: PCLKL) and A/D conversion clock PCLKADC can be set with the following division ratios: PCLKH to PCLKADC frequency ratios = 8:1
The ADC clock must be at 25 MHz or 18.75 MHz (ICLK/8) when the ADC is used.
For T2H device
Peripheral module clock (Unit 0: PCLKH, Unit 1: PCLKH, Unit 2: PCLKM) and A/D conversion clock PCLKADC can be set with the following division ratios: PCLKH to PCLKADC frequency ratios = 4:1
The ADC clock must be at 62.5 MHz (PCLKH/4) when the ADC is used.
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.
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.
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 voltage sensor if they are included in the mask of channels to scan.
In single scan mode, one or more specified channels are scanned once per trigger.
In continuous scan mode, a single trigger is required to start the scan. Scans continue until R_ADC_ScanStop() is called.
Group-scan mode allows the application to allocate channels to one of two groups (A and B and C). Conversion begins when the specified ELC start trigger for that group is received.
The priority of group priority operations is group A > group B > group C. In group priority operation, if the scan start of group B is accepted during the scan of group C, the scan of group C is interrupted and the scan of group B is started. If the scan start of group A is accepted during the scan of group C, the scan of group A is started. The scan of Group C is interrupted and the scan of Group A is started. Similarly, if the scan start of Group A is accepted during the scan of Group B, the scan of Group B is interrupted and the scan of Group A is started. The interrupted group scan is able to resume after the priority group scan is complete also.:
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.
When extended double-triggering is enabled both ADC input 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).
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 FSP 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 |
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 8-255.
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.
The ADC12 can select VREFH0 or VREFH1 as the high-potential reference voltage on selected MCU's.
The range of the ADC12 is from 0 (lowest) to 0xFFF (highest) when used in single-ended mode. This driver only supports single ended mode.
This is a basic example of minimal use of the ADC in an application.
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.
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.
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_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_active_trigger_t |
enum | adc_double_trigger_t |
enum | adc_elc_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. |
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 B 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. |
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_trigger_t | trigger_group_b | Group B trigger source; valid only for group mode. |
adc_double_trigger_t | double_trigger_mode | Double-trigger mode setting. |
adc_active_trigger_t | adc_start_trigger_a | A/D Conversion Start Trigger Group A. |
adc_active_trigger_t | adc_start_trigger_b | A/D Conversion Start Trigger Group B. |
bool | adc_start_trigger_c_enabled | Set to true to enable Group C, false to disable Group C. |
adc_active_trigger_t | adc_start_trigger_c | A/D Conversion Start Trigger Group C. |
adc_elc_t | adc_elc_ctrl | A/D Event Link Control. |
IRQn_Type | window_a_irq | IRQ number for Window Compare A interrupts. |
uint8_t | window_a_ipl | Priority for Window Compare A interrupts. |
IRQn_Type | window_b_irq | IRQ number for Window Compare B interrupts. |
uint8_t | window_b_ipl | Priority for Window Compare B interrupts. |
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 | scan_mask_group_c | 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. |
struct adc_instance_ctrl_t |
ADC instance control block. DO NOT INITIALIZE. Initialized in adc_api_t::open().
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.
enum adc_add_t |
ADC data sample addition and averaging options
enum adc_clear_t |
ADC sample state registers
enum adc_compare_cfg_t |
ADC comparison settings
ADC Window B channel
enum adc_window_b_mode_t |
enum 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.
enum adc_active_trigger_t |
Defines the registers settings for the ADC trigger.
enum adc_double_trigger_t |
enum adc_elc_t |
AD event link control definitions.
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.
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_IP_CHANNEL_NOT_PRESENT | The requested unit does not exist on this MCU. |
FSP_ERR_INVALID_HW_CONDITION | The ADC clock must be at least 1 MHz |
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.
FSP_SUCCESS | Channel specific settings applied. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | Unit is not open. |
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.
FSP_SUCCESS | Information stored in p_adc_info. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | Unit is not open. |
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.
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_IN_USE | Another scan is still in progress (software trigger). |
fsp_err_t R_ADC_ScanGroupStart | ( | adc_ctrl_t * | p_ctrl, |
adc_group_mask_t | group_mask | ||
) |
adc_api_t::scanGroupStart is not supported on the ADC. Use scanStart instead.
FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
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.
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_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.
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. |
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.
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_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.
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_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.
FSP_SUCCESS | Sample state count updated. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | Unit is not open. |
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.
FSP_SUCCESS | Module closed. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | Unit is not open. |
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.
FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
fsp_err_t R_ADC_Calibrate | ( | adc_ctrl_t *const | p_ctrl, |
void const * | p_extend | ||
) |
adc_api_t::R_ADC_Calibrate is not supported on the ADC.
FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
fsp_err_t R_ADC_CallbackSet | ( | adc_ctrl_t *const | p_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
FSP_SUCCESS | Callback updated successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |