![]() |
RAFW Flexible Software Package Documentation
Release v2.0.1
|
|
Driver for the TIM_W peripherals on RA for Wireless (RAFW) MCUs. This module implements the Timer Interface.
The TIM_W module can be used to count events, measure external input signals, generate a periodic interrupt, or output a periodic, one-shot or PWM signal to a GPIO pin.
The TIM_W module has the following features:
| Configuration | Options | Default | Description |
|---|---|---|---|
| Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
| Pin Output Support |
| Disabled | Enables or disables support for outputting PWM waveforms on GPIO pins. |
| Configuration | Options | Default | Description |
|---|---|---|---|
| General | |||
| General > Capture/Compare Match Operations | |||
| General > Capture/Compare Match Operations > Compare Match | |||
| Compare Match A Status | MCU Specific Options | ||
| Compare Match A Value | Value must be a non-negative integer less than 0x10000000000 | 0 | Specify the compare match A value in units that selected in Period Unit section. |
| Compare Match B Status | MCU Specific Options | ||
| Compare Match B Value | Value must be a non-negative integer less than 0x10000000000 | 0 | Specify the compare match B value in units that selected in Period Unit section. |
| Compare Match C Status | MCU Specific Options | ||
| Compare Match C Value | Value must be a non-negative integer less than 0x10000000000 | 0 | Specify the compare match C value in units that selected in Period Unit section. |
| Compare Match D Status | MCU Specific Options | ||
| Compare Match D Value | Value must be a non-negative integer less than 0x10000000000 | 0 | Specify the compare match D value in units that selected in Period Unit section. |
| Compare Match E Status | MCU Specific Options | ||
| Compare Match E Value | Value must be a non-negative integer less than 0x10000000000 | 0 | Specify the compare match E value in units that selected in Period Unit section. |
| Compare Match F Status | MCU Specific Options | ||
| Compare Match F Value | Value must be a non-negative integer less than 0x10000000000 | 0 | Specify the compare match F value in units that selected in Period Unit section. |
| Compare Match G Status | MCU Specific Options | ||
| Compare Match G Value | Value must be a non-negative integer less than 0x10000000000 | 0 | Specify the compare match G value in units that selected in Period Unit section. |
| Compare Match H Status | MCU Specific Options | ||
| Compare Match H Value | Value must be a non-negative integer less than 0x10000000000 | 0 | Specify the compare match H value in units that selected in Period Unit section. |
| General > Capture/Compare Match Operations > Capture | |||
| Sequential Captures | Value must be an integer between 1 and 8 | 0 | Specify the number of sequential captures that should be triggered before an interrupt is generated. If this option is set (1 up to 8), each captured value will be stored sequentially. |
| Single Capture Mode |
| Disabled | If the single capture mode is enabled, only the first edge will be captured and subsequent edges will be ignored. |
| Number of channels to be configured | Value must be a non-negative integer | 0 | Select the number of capture/compare channels to be configured. |
| General > One-Shot | |||
| delay | Value must be a non-negative integer less than 0x10000000000 | 0 | Select one-shot delay count. The restriction is the same as General->Period. To specify the desired period, please consider the prescaler setting of General->Period or specify it manually. |
| Automatic switching the mode from One-Shot to Periodic |
| Disabled | Enabled: The timer switches the mode from one-shot to periodic after the one-shot expires. Disabled: The timer keeps one-shot mode after the one-shot expiration and wait for next trigger. To receive the interrupt when one-shot expires, please enable this property. |
| Name | Name must be a valid C symbol | g_timer0 | Module name. |
| Channel | Enter the supported Channel number | 1 | Specify the hardware channel. |
| Mode |
| Periodic | Mode selection. Periodic: Generates periodic interrupts or fixed 50% duty PWM wave. One-shot: Generate a single interrupt or a pulse wave. PWM: Generates PWM waveforms with user-specific duty cycle. Edge Detect: Detects input edge. |
| Period | Value must be a non-negative integer less than 0x10000000000 (or less than 0x1000000 if pwm_support is enabled) | 0x10000 | Specify the timer period in units selected below. The period can be set up to 0x10000000000 (32-bit) which will use a divider of 256 with the maximum period. 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 generated timer_cfg_t structure. |
| Period Unit |
| Raw Counts | Unit of the period specified above |
| Low-Power Clock Frequency (Hz) | Value must be a positive integer | 0 | Specify the nominal or measured (via R_CAC) frequency of the selected LP Clock. |
| Clock select | MCU Specific Options | Timer clock | |
| Clock source divider | MCU Specific Options | Timer clock source division ratio | |
| Count Direction |
| Up | Timer count direction. |
| Free Run |
| Disabled | Timer does not zero after period expires. |
| Input | |||
| Input > Capture Trigger | |||
| Capture Channel GPIO A Trigger |
| Disabled | Capture trigger will occure on the selected edge when an option other than disabled is selected. |
| Capture Channel GPIO B Trigger |
| Disabled | Capture trigger will occure on the selected edge when an option other than disabled is selected. |
| Capture Channel GPIO C Trigger |
| Disabled | Capture trigger will occure on the selected edge when an option other than disabled is selected. |
| Capture Channel GPIO D Trigger |
| Disabled | Capture trigger will occure on the selected edge when an option other than disabled is selected. |
| Capture Channel GPIO E Trigger |
| Disabled | Capture trigger will occure on the selected edge when an option other than disabled is selected. |
| Capture Channel GPIO F Trigger |
| Disabled | Capture trigger will occure on the selected edge when an option other than disabled is selected. |
| Capture Channel GPIO G Trigger |
| Disabled | Capture trigger will occure on the selected edge when an option other than disabled is selected. |
| Capture Channel GPIO H Trigger |
| Disabled | Capture trigger will occure on the selected edge when an option other than disabled is selected. |
| Timer ELC Signal Source | MCU Specific Options | ELC source that will trigger the Timer | |
| ELC Task |
| Disabled | Select the task to be performed upon the reception of an ELC event. |
| ELC Capture Channel |
| Capture Channel A | Select the capture channel that will hold the captured value when triggered by the ELC task. |
| GPIO Trigger |
| Disabled | If GPIO trigger is not disabled, the GPIO source will be used to trigger One-shot (when in One-shot mode) and count up pulses (when in Edge Detect mode). |
| Output | |||
| Output > PWM Sync | |||
| Timer channel 2 | MCU Specific Options | If enabled, 2nd Timer will act as a slave to PWM Synchronization following Master Timer. | |
| Timer channel 3 | MCU Specific Options | If enabled, 3rd Timer will act as a slave to PWM Synchronization following Master Timer. | |
| Timer channel 4 | MCU Specific Options | If enabled, 4th Timer will act as a slave to PWM Synchronization following Master Timer. | |
| Timer channel 5 | MCU Specific Options | If enabled, 5th Timer will act as a slave to PWM Synchronization following Master Timer. | |
| Timer channel 6 | MCU Specific Options | If enabled, 6th Timer will act as a slave to PWM Synchronization following Master Timer. | |
| Timer channel 7 | MCU Specific Options | If enabled, 7th Timer will act as a slave to PWM Synchronization following Master Timer. | |
| Timer channel 8 | MCU Specific Options | If enabled, 8th Timer will act as a slave to PWM Synchronization following Master Timer. | |
| Timer channel 9 | MCU Specific Options | If enabled, 9th Timer will act as a slave to PWM Synchronization following Master Timer. | |
| Duty Cycle Percent (only applicable in PWM mode) | Value must be between 0 and 100 | 50 | Specify the timer duty cycle percent. Only used in PWM mode. |
| PWM Support |
| Disabled | If enabled, the module limits the period to 0x10000 to support PWM functionality. |
| Interrupts | |||
| Callback | Name must be a valid C symbol | NULL | A user callback function can be specified here. If this callback function is provided, it will be called from the interrupt service routine (ISR) each time the timer period elapses |
| Cycle end Interrupt Priority | MCU Specific Options | Select the cycle end interrupt priority. | |
| Overflow Interrupt Priority | MCU Specific Options | Select the overflow interrupt priority. | |
| Capture/Compare match A Interrupt Priority | MCU Specific Options | Select the interrupt priority for Capture/Compare match A. | |
| Capture/Compare match B Interrupt Priority | MCU Specific Options | Select the interrupt priority for Capture/Compare match B. | |
| Capture/Compare match C Interrupt Priority | MCU Specific Options | Select the interrupt priority for Capture/Compare match C. | |
| Capture/Compare match D Interrupt Priority | MCU Specific Options | Select the interrupt priority for Capture/Compare match D. | |
| Capture/Compare match E Interrupt Priority | MCU Specific Options | Select the interrupt priority for Capture/Compare match E. | |
| Capture/Compare match F Interrupt Priority | MCU Specific Options | Select the interrupt priority for Capture/Compare match F. | |
| Capture/Compare match G Interrupt Priority | MCU Specific Options | Select the interrupt priority for Capture/Compare match G. | |
| Capture/Compare match H Interrupt Priority | MCU Specific Options | Select the interrupt priority for Capture/Compare match H. | |
| Underflow Interrupt Priority | MCU Specific Options | Select the interrupt priority for the underflow interrupt. | |
TIM_W has two configurations available for clock source, DIVN and LP_CLK. Adjusting the TIM_W frequency can be done using the internal source clock divider. The TIM_W can operate in all low power modes as long as lp_clk is selected as the TIM_W source clock.
If LP_CLK is selected as timer source clock, the selected LP_CLK frequency must be specified in the general stack configuration
This module can use GPIO pins as Input sources:
To configure the GPIO pins as TIM_W inputs/outputs, the equivalent pins should be configured in the pins tab.
Capture/Compare operations can be configured in three steps.
Clock source divider is calculated automatically based on the period, source clock and period units set by the user, if the source divider property is set to "auto".
If a specific divider is required, the user can select it in Clock source divider property.
The Configuration editor will automatically calculate the period value and source clock divider based on the selected period time, units and clock speed.
When the selected period unit is "Raw counts", the maximum period setting is 0x10000000000. This will configure the TIM_W with the maximum period and a count clock divisor.
The period and duty cycle are updated immediately after calling R_TIM_W_PeriodSet() or R_TIM_W_DutyCycleSet().
To configure the TIM_W for the maximum period, set Period from the General Tab to 0x10000000000.
In One-shot mode, the TIM_W counts upwards only on period configured by the sum of Period and Delay. When One-shot has expired, TIM_W is ready to repeat the process.
To configure One-Shot:
To Configure One-Shot Trigger: One-Shot start can be triggered by: Software "R_TIM_W_Start()", GPIO Trigger, ELC Trigger. To configure One-Shot GPIO Triggers:
The output waveform in one-shot mode consists of two parts expressed in raw counts. When One-shot is triggered the first part generated is a delay period configured by (General Tab –> One-Shot –> Delay). During the delay phase, the output waveform is forced low. In the second part, the shot is generated after the delay period expires. The shot period is configured by (General Tab –> Period).
Examples of one-shot signals that can be generated by this module are shown below:
The output toggles twice each time the TIM_W expires in periodic mode. This is achieved by defining a PWM wave at a 50 percent duty cycle so that the period of the resulting square wave (from rising edge to rising edge) matches the period of the TIM_W timer.
To generate pwm signal the following field must be active
Examples of periodic signals that can be generated by this module are shown below:
The PWM signal can be configured by the Period and the Duty Cycle Percent options.
The PWM output signal is high at the beginning of the cycle and low at the end of the cycle.
To generate pwm signal the following field must be active
Examples of PWM signals that can be generated by this module are shown below:
Event counting can be done by selecting edge detect mode. The selection of sources can be GPIO pins and ELC events. In Edge detect mode, the TIM_W counter is not affected by TIM_W source clock.
To configure TIM_W to Count-Up:
Pulse measurement can be achieved by configuring at least two TIM_W Capture operation channels with the available sources (GPIO or ELC) and triggers (Rising and falling edges for GPIO sources only). The pulse width can then be calculated by subtracting the two measurements.
The TIM_W timer can be configured to stop, start, clear, count up, Capture, trigger oneshot, pause/resume or disable when an ELC event occurs.
To configure ELC Triggers:
Configure TIM_W to the desired mode to generate events for the ELC. When the TIM_W configuration is done, set up an ELC link over the Event Links tab.
To use external events from ELC or GPIO, R_TIM_W_Enable() must be called first.
This is a basic example of minimal use of the TIM_W in an application.
This is an example of a timer callback.
To use the TIM_W as a free running counter, select periodic mode and set the free_run extended configuration to true.
This is an example of using the TIM_W to capture pulse width or pulse period measurements.
This is an example of updating the period.
This is an example of updating the duty cycle.
This example demonstrates the configuration and use of compare match with TIM_W timer.
This example demonstrates the sequential capturing and compare match configuration of 2 TIM_W channels, utilizing the ELC to trigger events between them.
This example demonstrates the external triggering of One-shot from the ELC.
This example demonstrates the TIM_W configuration required to count up using the ELC as count source.
This example demonstrates the TIM_W configuration required to count up using the ELC as count source.
Data Structures | |
| struct | tim_w_instance_ctrl_t |
| struct | tim_w_operation_channel_cfg |
| struct | tim_w_extended_ccm_cfg |
| struct | tim_w_extended_cfg_t |
Enumerations | |
| enum | tim_w_clock_t |
| enum | tim_w_gpio_trigger_t |
| enum | tim_w_elc_task_t |
| struct tim_w_instance_ctrl_t |
Channel control block. DO NOT INITIALIZE. Initialization occurs when timer_api_t::open is called.
Data Fields | |
| uint32_t | open |
| Whether or not channel is open. | |
| const timer_cfg_t * | p_cfg |
| Pointer to initial configurations. | |
| TIMER_Type * | p_reg |
| Base register for this channel. | |
| void(* | p_callback )(timer_callback_args_t *) |
| Pointer to callback. | |
| timer_callback_args_t * | p_callback_memory |
| Pointer to optional callback argument memory. | |
| void * | p_context |
| Pointer to context to be passed into callback function. | |
| struct tim_w_operation_channel_cfg |
Configuration structure for non-periodic Capture/CompareMatch channels.
| Data Fields | ||
|---|---|---|
| bsp_io_port_pin_t | capture_source | Configuration for GPIOs used as a source for capture operation. |
| tim_w_gpio_trigger_t | capture_trigger | |
| uint8_t | ccm_operation_ipl | |
| IRQn_Type | ccm_operation_irq | |
| struct tim_w_extended_ccm_cfg |
Extended Configuration for Capture/Compare-Match Operations.
| Data Fields | ||
|---|---|---|
| bool | single_capture_mode |
When set, first capture value is persistant, next captures on the same register will not overwrite the first value. |
| uint8_t | elc_channel | Channel used for ELC Capture. |
| tim_w_operation_channel_cfg * | p_ccm_channel_cfg | Configuration Array of Operation Channels. |
| uint8_t | ccm_channel_size | Number of Operation Channels used for Capture or Compare-Match operations. |
| struct tim_w_extended_cfg_t |
TIM_W extension configures the output pins for TIM_W.
| Data Fields | ||
|---|---|---|
| bool | free_run | Free-running mode (up-count only) |
| tim_w_clock_t | count_source | Clock source supplied to timer. |
| timer_direction_t | direction | Counter direction. |
| uint16_t | pwm_sync_map | Channels to be synchronously started with TIM on PWM mode. |
| tim_w_elc_task_t | elc_task | |
| bsp_io_port_pin_t | gpio_source | |
| tim_w_gpio_trigger_t | gpio_trigger | |
| bool | oneshot_switch_to_periodic | Enable auto mode switch from oneshot to periodic when oneshot elapses. |
| uint32_t | oneshot_delay | |
| tim_w_extended_ccm_cfg * | p_ccm_cfg | |
| enum tim_w_clock_t |
| enum tim_w_gpio_trigger_t |
Trigger edge for pulse period measurement mode and event counting mode.
| enum tim_w_elc_task_t |
Tasks available for elc
| fsp_err_t R_TIM_W_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 TIM_W implementation of the general timer can accept a tim_w_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 source divider is invalid. |
| FSP_ERR_ALREADY_OPEN | Module is already open. |
| FSP_ERR_IRQ_BSP_DISABLED | timer_cfg_t::p_callback is not NULL, but ISR is not enabled. |
| FSP_ERR_INVALID_MODE | PWM mode cant be accessed without TIM_W_CFG_OUTPUT_SUPPORT_ENABLE == 1 |
| FSP_ERR_INVALID_CHANNEL | PWM sync supports only TIM as master. |
| FSP_ERR_INVALID_ARGUMENT | Invalid argument passed for one-shot mode, capture/compare as well as count down are not supported. Capture/compare channel size is out of limit. PWM period or duty cycle values are not within valid limits. PWM sync can not be set without the PWM mode active. CCM Channel configuration is empty while channel size is not zero. Elc_channel exceeds the CCM channel size. |
| FSP_ERR_IP_CHANNEL_NOT_PRESENT | The channel requested in the p_cfg parameter is not available on this device. |
| fsp_err_t R_TIM_W_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_TIM_W_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_TIM_W_Reset | ( | timer_ctrl_t *const | p_ctrl | ) |
Resets the counter to the initial value. Implements timer_api_t::reset.
| FSP_SUCCESS | Counter value written successfully. |
| FSP_ERR_ASSERTION | p_ctrl was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| fsp_err_t R_TIM_W_Enable | ( | timer_ctrl_t *const | p_ctrl | ) |
Enables external event triggers that capture the counter and sets the elc task. 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_TIM_W_Disable | ( | timer_ctrl_t *const | p_ctrl | ) |
Disables external event triggers that start, stop, capture or compare. 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_TIM_W_PeriodSet | ( | timer_ctrl_t *const | p_ctrl, |
| uint32_t const | period_counts | ||
| ) |
Sets period value provided.
Implements timer_api_t::periodSet.
Example:
| FSP_SUCCESS | Period value written successfully. |
| FSP_ERR_ASSERTION | p_ctrl was NULL, or selected value exceeds HW specifications. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| FSP_ERR_INVALID_ARGUMENT | Selected value exceeds the maximum register value. |
| fsp_err_t R_TIM_W_PeriodSet_light | ( | timer_ctrl_t *const | p_ctrl, |
| uint32_t const | period_counts | ||
| ) |
Sets period value provided.
Implements timer_api_t::periodSet.
| FSP_SUCCESS | Period value written successfully. |
| fsp_err_t R_TIM_W_DutyCycleSet | ( | timer_ctrl_t *const | p_ctrl, |
| uint32_t const | duty_cycle_counts, | ||
| uint32_t const | pin | ||
| ) |
Sets duty cycle. Implements timer_api_t::dutyCycleSet.
Example:
| [in] | p_ctrl | Pointer to instance control block. |
| [in] | duty_cycle_counts | Duty cycle to set in counts. |
| [in] | pin | Use tim_w_io_pin_t to select TIM_W_IO_PIN_GTIOCA or TIM_W_IO_PIN_GTIOCB |
| FSP_SUCCESS | Duty cycle updated successfully. |
| FSP_ERR_ASSERTION | p_ctrl was NULL or the pin is not one of tim_w_io_pin_t |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| FSP_ERR_INVALID_ARGUMENT | Duty cycle is larger than period. |
| FSP_ERR_INVALID_MODE | Duty cycle can only be configured in PWM mode. |
| FSP_ERR_UNSUPPORTED | TIM_W_CFG_OUTPUT_SUPPORT_ENABLE is 0. |
| fsp_err_t R_TIM_W_CompareMatchSet | ( | timer_ctrl_t *const | p_ctrl, |
| uint32_t const | compare_match_value, | ||
| timer_compare_match_t const | match_channel | ||
| ) |
Set value for compare match feature. Implements timer_api_t::compareMatchSet.
Example:
| FSP_SUCCESS | Set the compare match value successfully. |
| FSP_ERR_ASSERTION | p_ctrl was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| FSP_ERR_NOT_ENABLED | Requested compare channel is disabled. CCM channel configuration is NULL. |
| FSP_ERR_INVALID_MODE | Compare match operation is only available on periodic mode. |
| fsp_err_t R_TIM_W_SequentialCapturesGet | ( | timer_ctrl_t *const | p_ctrl, |
| uint32_t *const | p_captures | ||
| ) |
Get captured values for all configured capturing channels when sequential capturing is enabled.
Example:
| [in] | p_ctrl | Pointer to instance control block. |
| [in] | p_captures | Pointer to the captured snapshot values. |
| FSP_SUCCESS | Captured values stored successfully. |
| FSP_ERR_ASSERTION | p_ctrl or p_captures was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| FSP_ERR_INVALID_MODE | Capture operation is only available on periodic mode. |
| fsp_err_t R_TIM_W_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_TIM_W_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_TIM_W_CallbackSet | ( | timer_ctrl_t *const | p_api_ctrl, |
| void(*)(timer_callback_args_t *) | p_callback, | ||
| void *const | p_context, | ||
| timer_callback_args_t *const | p_callback_memory | ||
| ) |
Updates the user callback with the option to provide memory for the callback argument structure. 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_NO_CALLBACK_MEMORY | p_callback is non-secure and p_callback_memory is either secure or NULL. |
| fsp_err_t R_TIM_W_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. |