RA Flexible Software Package Documentation
Release v5.6.0
|
|
Driver for the TAU peripheral on RA MCUs. This module implements the Timer Interface.
The TAU module has the following features:
Channel | Interval Timer | Square Wave Output | External Event Counter | Divider | Input Pulse Interval Measurement | Delay Counter | Measure High-Low Level Pulse Width | 8-bit timer operation | Operation clocks | Input signals | Output signals |
---|---|---|---|---|---|---|---|---|---|---|---|
TAU00 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | CK00, CK01 | TI00, ELC | TO00 | |
TAU01 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | CK00, CK01, CK02, CK03 | TI01, ELC | TO01 | |
TAU02 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | CK00, CK01 | TI02 | TO02 | ||
TAU03 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | CK00, CK01, CK02, CK03 | TI03 | TO03 | |
TAU04 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | CK00, CK01 | TI04 | TO04 | ||
TAU05 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | CK00, CK01 | TI05, MOCO, LOCO, FSUB | TO05 | ||
TAU06 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | CK00, CK01 | TI06 | TO06 | ||
TAU07 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | CK00, CK01 | TI07, RXD2 | TO07 |
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Interrupt Support |
| Enabled | Enable support for interrupts |
Pin Output Support |
| Disabled | Enable output for either square wave or divider output |
Pin Input Support |
| Disabled | Enable input for pulse width measurement, level width measurement, pulse/edge counting or divider functions. |
Extra Input Mode Support |
| Disabled | Enable support for event counting, system clock count sources and input noise filtering when Pin Input Support is enabled. |
8-Bit Mode Support |
| Disabled | Enable support for 8-bit timer modes (only available on channels 1 and 3). |
Configuration | Options | Default | Description |
---|---|---|---|
General | |||
Name | Name must be a valid C symbol | g_timer0 | Module name. |
Channel | Channel number must be a non-negative integer | 0 | Physical hardware channel. |
Function |
| Interval Timer | Function selection. Note: The calculation of the input pulse function and the high-low level pulse width measurement function is implemented using interrupts. ISR's must be enabled for these functions even if callback is unused. |
Bit Timer Mode |
| 16-bit timer | Specify the 16 or 8-bit timer mode |
Operation Clock |
| CK00 | Specify the selection of operation clock |
Period | Value must be a non-negative integer | 0x10000 | Specify the timer period based on the selected units. When the unit is set to 'Raw Counts', setting the period to 0x10000 results in the maximum period at the lowest divisor (fastest timer tick). When Pulse width measurement or high-low level pulse width measurement is enabled, this period is always generated as zero.. The period should be set maximally 0x100 when lower 8-bit mode or higher and lower 8-bit mode is enabled. When 'Input->Trigger Edge' is set to 'Trigger Edge Rising' or 'Trigger Edge Falling', this period can be maximally set to 0x20000 when using the divider function. If the requested period cannot be achieved, the settings with the largest possible period, that does not exceed the requested period, are used. The theoretical calculated period is printed in a comment in the timer_cfg_t structure. |
Period Unit |
| Raw Counts | Unit of the period specified above |
Period (Higher 8-bit timer) | Value must be a non-negative integer | 0x100 | Specify the higher 8-bit timer period based on the selected unit. When the unit is set to 'Raw Counts', setting the period to 0x100 results in the maximum period at the lowest divisor (fastest timer tick). This setting is only applicable in interval timer function with higher 8bit mode or higher and lower 8bit mode. If the requested period cannot be achieved, the settings with the largest possible period that is less than or equal to the requested period are used. The theoretical calculated period is printed in a comment in the tau_extended_cfg_t structure. |
Period Unit (Higher 8-bit timer) |
| Raw Counts | Unit of the period specified above |
Input | |||
Input Source | MCU Specific Options | Input source, applies in input pulse width measurement function, high-low level pulse width measurement function, external event count function, and divider function. | |
Trigger Edge |
| Trigger Edge Rising | Select the trigger edge. Applies in input pulse width measurement function, high-low level pulse width measurement function, external event count function, and divider function. |
Input Filter |
| Disabled | Input filter, applies in input pulse width measurement function, high-low level pulse width measurement function, external event count function, and divider function. |
Output | |||
Initial Output |
| Disabled | Initial output, applies in divider function and square wave. |
Interrupts | |||
Setting of starting count and interrupt |
| Timer interrupt is not generated when counting is started/Start trigger is invalid during counting operation. | Specify OPIRQ bit setting |
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 timer period elapses. |
Interrupt Priority | MCU Specific Options | Timer interrupt priority. | |
Higher 8-bit Interrupt Priority | MCU Specific Options | Timer higher 8-bit interrupt priority. |
The TAU clock is based on the peripheral module clock (PCLKB) which is equal to the system clock (ICLK).
Each TAU channel has certain operation clocks selections, these can be set with the General>Operation Clock property in the module configuration. When the operation clock of a channel is set to CK00, CK01, CK02, or CK03, the TAU module provides divisor values for each of those clocks. These divisors may be set in the Clocks tab. As such, setting a divisor in the Clocks tab affects all TAU channels that use that CK0x clock as an input. Adjusting these settings determines the frequency range achievable by a TAU channel. If a desired frequency is not achievable, the divider in the Clocks tab may be adjusted. The clock dividers cannot be adjusted at runtime.
This module should use the TOmn pins as output pins for Square Wave Output, Divider Function
For input source, the input signal must be applied to External Event Counter, Divider, Input Pulse Interval Measurement, Delay Counter, and Measure High-Low Level Pulse Width Function
The RA Configuration editor will automatically calculate the period count value based on the selected period time, units, operation clock (set by General>Operation Clock property in the module configuration), and clock divisor value (set in Clocks tab).
When the selected unit is "Raw counts", the maximum and minimum allowed period setting varies depending on the selected clock source:
Clock divisor | Minimum period (counts) | Maximum period (counts) |
---|---|---|
ICLK/1 | 0x00002 | 0x10000 |
All other divisors | 0x00001 | 0x10000 |
Clock divisor | Minimum Higher 8-bit period (counts) | Maximum Higher 8-bit period (counts) |
---|---|---|
All divisors | 0x001 | 0x100 |
This function can be used as a reference timer to generate TAU0_TMI0n (timer interrupt) at fixed intervals. The interrupt generation period can be calculated by the following expression.
The Interval Timer Function can operate as the higher/lower 8-bits mode.
When "Interrupts > Setting of starting count and interrupt" is "Timer interrupt is generated when counting is started/Start trigger is valid during counting operation.", an interrupt is generated immediately after R_TAU_Start() function is called and timer output also changed.
This function can use TO0n to perform a toggle operation as soon as TAU0_TMI0n has been generated, and outputs a square wave with a duty factor of 50%.
The period and frequency for outputting a square wave from TO0n can be calculated by the following expressions.
The Square Wave Output Function can operate as the lower 8-bits mode.
When "Interrupts > Setting of starting count and interrupt" is "Timer interrupt is generated when counting is started/Start trigger is valid during counting operation.", an interrupt is generated immediately after R_TAU_Start() function is called and output pin is also changed.
The timer array unit can be used as an external event counter that counts the number of times the valid input edge (external event) is detected in the TI0n pin. When a specified count value is reached, the event counter generates an interrupt. The specified number of counts can be calculated by the following expression.
Instead of using the TI0n pin input, a channel specified for the External Event Counter Function can also use the signal as "Middle-speed on-chip oscillator (MOCO)", "Low-speed on-chip oscillator (LOCO)", "Subsystem clock (FSUB)", and ELC event which selected in Input>Input Source property as its input source to drive counting.
The External Event Counter Function can operate as the lower 8-bits mode.
It is possible to start counting down when the valid edge of the TI0n pin input is detected (an external event), and then generate TAU0_TMI0n (a timer interrupt) after any specified interval. The interrupt generation period can be calculated by the following expression. Generation period of TAU0_TMI0n (timer interrupt) = Period of count clock × (Set value of TDR0n + 1)
Instead of using the TI0n pin input, a channel specified for the Delay Counter Function can also use the signal as "Middle-speed on-chip oscillator (MOCO)", "Low-speed on-chip oscillator (LOCO)", "Subsystem clock (FSUB)", and ELC event which selected in Input>Input Source property as its input source to drive counting.
The Delay Counter Function can operate as the lower 8-bits mode.
When "Interrupts > Setting of starting count and interrupt" is "Timer interrupt is generated when counting is started/Start trigger is valid during counting operation.", a start trigger is valid during counting operation.
The timer array unit can be used as a frequency divider that divides a clock input to the TI00 pin and outputs the result from the TO00 pin. The divided clock frequency output from TO00 can be calculated by the following expression. When rising edge/falling edge is selected:
When "Interrupts > Setting of starting count and interrupt" is "Timer interrupt is generated when counting is started/Start trigger is valid during counting operation.", an interrupt is generated immediately after first input signal is detected and output pin is also changed.
The count value can be captured at the TI0n valid edge and the interval of the pulse input to TI0n can be measured. The pulse interval can be calculated by the following expression.
Instead of using the TI0n pin input, a channel specified for the Input Pulse Interval Measurement can also use the signal as "Middle-speed on-chip oscillator (MOCO)", "Low-speed on-chip oscillator (LOCO)", "Subsystem clock (FSUB)", "Input signal of the RXD2 pin", and ELC event which selected in Input>Input Source property as its input source to drive counting.
By starting counting at one edge of the TI0n pin input and capturing the number of counts at another edge, the signal width (high-level width or low-level width) of TI0n can be measured. The signal width of TI0n can be calculated by the following expression.
Instead of using the TI0n pin input, a channel specified for the High-Low Level Pulse Width Function can also use the signal as "Middle-speed on-chip oscillator (MOCO)", "Low-speed on-chip oscillator (LOCO)", "Subsystem clock (FSUB)", "Input signal of the RXD2 pin", and ELC event which selected in Input>Input Source property as its input source to drive counting.
The TAU timer can trigger the start of other peripherals. The Event Link Controller (r_elc) guide provides a list of all available peripherals.
This is a basic example of minimal use of the TAU in an application.
This is an example of a timer callback.
To use the TAU as 16-bit or 8-bit mode, select Bit Mode Timer.
This is an example of using the TAU to capture pulse width or pulse period measurements.
This is an example of updating the period.
This is an example of configuration for Square Wave Output Function.
This is an example of configuration for External Event Counter Function.
This is an example of configuration for Divider Function.
This is an example of configuration for Delay Counter Function.
Data Structures | |
struct | tau_instance_ctrl_t |
struct | tau_extended_cfg_t |
Enumerations | |
enum | tau_function_t |
enum | tau_bit_mode_t |
enum | tau_operation_ck_t |
enum | tau_trigger_edge_t |
enum | tau_interrupt_opirq_bit_t |
enum | tau_input_source_t |
enum | tau_pin_output_cfg_t |
enum | tau_input_noise_filter_t |
struct tau_instance_ctrl_t |
Channel control block. DO NOT INITIALIZE. Initialization occurs when timer_api_t::open is called.
struct tau_extended_cfg_t |
Optional TAU extension data structure.
Data Fields | ||
---|---|---|
tau_interrupt_opirq_bit_t | opirq: 1 | Setting of starting count and interrupt. |
tau_function_t | tau_func | Setting of Function for TAU. |
tau_bit_mode_t | bit_mode | Setting of 16-bit timer or 8-bit timer. |
tau_pin_output_cfg_t | initial_output | Setting of Function for TAU. |
tau_input_source_t | input_source | |
tau_input_noise_filter_t | tau_filter | Input filter for TAU. |
tau_trigger_edge_t | trigger_edge | Trigger edge to start pulse period measurement or count external event. |
tau_operation_ck_t | operation_clock | |
uint16_t | period_higher_8bit_counts | Period in raw higher 8 bit timer counts. |
uint8_t | higher_8bit_cycle_end_ipl | Cycle higher 8-bit end interrupt priority. |
IRQn_Type | higher_8bit_cycle_end_irq | Cycle higher 8-bit end interrupt. |
enum tau_function_t |
Timer function
enum tau_bit_mode_t |
enum tau_operation_ck_t |
Timer operation clock.
enum tau_trigger_edge_t |
Trigger edge for pulse period measurement mode, high-low measurement, divider, delay counter and event counting mode.
Interrupt and starting Count Mode
enum tau_input_source_t |
Input source
enum tau_pin_output_cfg_t |
fsp_err_t R_TAU_Open | ( | timer_ctrl_t *const | p_ctrl, |
timer_cfg_t const *const | p_cfg | ||
) |
Initializes the timer module and applies configurations. Implements timer_api_t::open.
The TAU implementation of the general timer can accept a tau_extended_cfg_t extension parameter.
Example:
FSP_SUCCESS | Initialization was successful and timer has started. |
FSP_ERR_ASSERTION | A required input pointer is NULL or the period is not in the valid range |
FSP_ERR_ALREADY_OPEN | Module is already open. |
FSP_ERR_INVALID_CHANNEL | The channel does not support this feature. |
FSP_ERR_IRQ_BSP_DISABLED | Timer_cfg_t::p_callback is not NULL, but ISR is not enabled. ISR must be enabled to use callback |
FSP_ERR_INVALID_MODE | Invalid configuration for p_extend. |
FSP_ERR_IP_CHANNEL_NOT_PRESENT | The channel requested in the p_cfg parameter is not available on this device. |
fsp_err_t R_TAU_Stop | ( | timer_ctrl_t *const | p_ctrl | ) |
Stops timer. Implements timer_api_t::stop.
Example:
FSP_SUCCESS | Timer successfully stopped. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
fsp_err_t R_TAU_Start | ( | timer_ctrl_t *const | p_ctrl | ) |
Starts timer. Implements timer_api_t::start.
Example:
FSP_SUCCESS | Timer successfully started. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
fsp_err_t R_TAU_Reset | ( | timer_ctrl_t *const | p_ctrl | ) |
Resets the counter value to the period minus one. Input Pulse Function is reset counter value to 0. Implements timer_api_t::reset.
FSP_SUCCESS | The counter value written successfully. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
fsp_err_t R_TAU_Enable | ( | timer_ctrl_t *const | p_ctrl | ) |
Enables external event triggers that start, stop, clear, or capture the counter. Implements timer_api_t::enable.
Example:
FSP_SUCCESS | External events successfully enabled. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
fsp_err_t R_TAU_Disable | ( | timer_ctrl_t *const | p_ctrl | ) |
Disables external event triggers that start, stop, clear, or capture the counter. Implements timer_api_t::disable.
Example:
FSP_SUCCESS | External events successfully disabled. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
fsp_err_t R_TAU_PeriodSet | ( | timer_ctrl_t *const | p_ctrl, |
uint32_t const | period_counts | ||
) |
Sets period value provided. If the timer is running, the period will be updated after the next counter underflow. If the timer is stopped, this function resets the counter and updates the period. This Function is not supported for Input pulse Function, High-Low Measurement Function. Implements timer_api_t::periodSet.
Example:
FSP_SUCCESS | Period value written successfully. |
FSP_ERR_ASSERTION | p_ctrl was NULL or period is invalid range. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
FSP_ERR_UNSUPPORTED | Unsupported for Input pulse Function, High-Low Measurement Function |
fsp_err_t R_TAU_CompareMatchSet | ( | timer_ctrl_t *const | p_ctrl, |
uint32_t const | compare_match_value, | ||
timer_compare_match_t const | match_channel | ||
) |
Placeholder for unsupported compareMatch function. Implements timer_api_t::compareMatchSet.
FSP_ERR_UNSUPPORTED | TAU compare match is not supported. |
fsp_err_t R_TAU_DutyCycleSet | ( | timer_ctrl_t *const | p_ctrl, |
uint32_t const | duty_cycle_counts, | ||
uint32_t const | pin | ||
) |
timer_api_t::dutyCycleSet is not supported on the R_TAU Independent channels.
FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
fsp_err_t R_TAU_InfoGet | ( | timer_ctrl_t *const | p_ctrl, |
timer_info_t *const | p_info | ||
) |
Get timer information and store it in provided pointer p_info. Implements timer_api_t::infoGet.
Example:
FSP_SUCCESS | Period, count direction, frequency, and ELC event written to caller's structure successfully. |
FSP_ERR_ASSERTION | p_ctrl or p_info was NULL. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
fsp_err_t R_TAU_StatusGet | ( | timer_ctrl_t *const | p_ctrl, |
timer_status_t *const | p_status | ||
) |
Get current timer status and store it in provided pointer p_status. Implements timer_api_t::statusGet.
Example:
FSP_SUCCESS | Current timer state and counter value set successfully. |
FSP_ERR_ASSERTION | p_ctrl or p_status was NULL. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
fsp_err_t R_TAU_CallbackSet | ( | timer_ctrl_t *const | p_api_ctrl, |
void(*)(timer_callback_args_t *) | p_callback, | ||
void const *const | p_context, | ||
timer_callback_args_t *const | p_callback_memory | ||
) |
Updates the user callback. Implements timer_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. |
fsp_err_t R_TAU_Close | ( | timer_ctrl_t *const | p_ctrl | ) |
Stops counter, disables output pins, and clears internal driver data. Implements timer_api_t::close.
FSP_SUCCESS | Successful close. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
FSP_ERR_NOT_OPEN | The instance is not opened. |