RA Flexible Software Package Documentation
Release v5.7.0
|
|
Driver for the TAU_PWM peripheral on RA MCUs. This module implements the Timer Interface.
The TAU_PWM module has the following features:
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
One-shot Pulse Output Mode Support |
| Disabled | Controls whether one-shot pulse output mode support is included in the build. This setting applies globally to all r_tau_pwm_instances. If one shot mode is not used by any instance, disable this setting to reduce ROM usage. |
PWM Output Mode Support |
| Enabled | Controls whether PWM mode support is included in the build. This setting applies globally to all r_tau_pwm_instances. If PWM mode is not used by any instance, disable this setting to reduce ROM usage. |
Multi-Slave |
| Disabled | Enable support for multiple slaves |
Configuration | Options | Default | Description |
---|---|---|---|
General | |||
Name | Name must be a valid C symbol | g_timer0 | Module name. |
Operation Clock |
| CK00 | Select the operation clock |
Mode |
| PWM output | Mode selection. |
Master Channel | Channel number must be even. | 0 | Select the TAU master channel. When two or more master channels are to be used, slave channels with a master channel between them may not be set. |
Period | Value must be a non-negative integer | 0x10000 | Specify the timer period based on the selected unit. In One-shot pulse output mode this value corresponds to the delay time. When the unit is set to 'Raw Counts', setting the period to 0x10000/0x10001 results in the maximum period for PWM Output function/One-shot pulse output function at the lowest divisor (fastest timer tick). 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 |
Input (One-shot pulse) | |||
Trigger Source | MCU Specific Options | Select the trigger source for master channel. | |
Detect Edge |
| Falling Edge | Select the detect edge. |
Interrupts | |||
Callback | Name must be a valid C symbol | NULL | A user callback function can be provided. If provided, the callback function is called from the interrupt service routine (ISR) each time the timer period elapses in PWM mode, and when the timer delay elapses in one-shot mode. If the optional slave channel interrupt is enabled, the callback is also called when the signal switches state during the PWM cycle in PWM mode, and when the pulse output is complete in one-shot mode. |
Interrupt Priority | MCU Specific Options | Timer interrupt priority. |
Configuration | Options | Default | Description |
---|---|---|---|
General | |||
Channel | Value must be between 0 and 7. | 1 | Specify the slave channel. |
Output | |||
Output Level |
| Start Level Low | Output level of TAU slave channel. |
Output Polarity |
| Active-high | Output polarity of TAU slave channel. |
One-Shot Pulse Width | Value must be a non-negative integer | 0xffff | Specify the pulse width based on the selected unit. When the unit is set to 'Raw Counts', setting the period to 0xffff results in the maximum period at the lowest divisor (fastest timer tick). |
One-Shot Pulse Width Unit |
| Raw Counts | Unit of the period specified above |
PWM Duty Cycle Percent | Value must be a non-negative integer between 0 and 100 | 50 | Specify the duty cycle percent for output pulse of slave channel. |
Interrupts | |||
Interrupt Priority | MCU Specific Options | Timer interrupt priority. |
The TAU PWM clock is based on the peripheral module clock (PCLKB) which is equal to the system clock (ICLK).
Each TAU PWM 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, or CK01, the TAU_PWM 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 PWM and TAU channels that use that CK0x clock as an input. Adjusting these settings determines the frequency range achievable by a TAU_PWM 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 can use the TOmn pins as output pins for One-shot and PWM signals.
This module can use the TImn pin as the input pin for One-shot signals.
The RA Configuration editor will automatically calculate the period/pulse width/duty cycle percent based on the selected period time, units, clock source, clock divider and mode.
When the selected unit is "Raw counts", the maximum and minimum allowed period/pulse width/duty cycle setting are presented by the following tables:
In One-shot pulse output mode:
Clock divider | Minimum period (counts) | Maximum period (counts) | Minimum pulse width (counts) | Maximum pulse width (counts) |
---|---|---|---|---|
PCLK/1 | 0x00003 | 0x10001 | 0x0001 | 0xffff |
PCLK/2 to PCLK/32768 | 0x00002 | 0x10000 | 0x0000 | 0xffff |
In PWM output mode:
Clock divider | Minimum period (counts) | Maximum period (counts) | Minimum duty cycle (%) | Maximum duty cycle (%) |
---|---|---|---|---|
PCLK/1 | 0x00002 | 0x10001 | 0 | 100 |
PCLK/2 to PCLK/32768 | 0x00001 | 0x10000 | 0 | 100 |
The period and duty cycle are updated after the next counter underflow after calling R_TAU_PWM_PeriodSet() or R_TAU_PWM_DutyCycleSet().
By using two channels as a set, a one-shot pulse having any delay pulse width can be generated from the signal input to the TI0n pin.
The delay time is counted by the master channel, and the pulse width is counted by the slave channel.
Two channels can be used as a set to generate a pulse of any period and duty factor (duty cycle). By extending the PWM function and using multiple slave channels, many PWM waveforms with different duty values can be output.
When multiple slaves are to be connected to a single master, the build time option for multiple slaves needs to be set.
The period is counted by the master channel, and the duty cycle is counted by the slave channel.
The TAU_PWM timer can be configured to trigger the timer counter when an ELC event occurs.
The TAU_PWM 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 PWM (in PWM Output mode) in an application.
This is an example of a timer callback.
This example demonstrates the configuration and use of One-shot pulse output mode with TAU_PWM timer when using the software trigger.
This example demonstrates the configuration and use of One-shot pulse output mode with TAU_PWM timer when using an external pin input trigger.
This example demonstrates the configuration and use of PWM output mode with TAU_PWM timer.
This an example of updating the period.
This an example of updating the duty cycle.
This is an example of using TAU_PWM with ELC events.
Data Structures | |
struct | tau_pwm_channel_cfg_t |
struct | tau_pwm_extended_cfg_t |
struct | tau_pwm_instance_ctrl_t |
Enumerations | |
enum | tau_pwm_operation_clock_t |
enum | tau_pwm_source_t |
enum | tau_pwm_detect_edge_t |
enum | tau_pwm_output_level_t |
enum | tau_pwm_output_polarity_t |
enum | tau_pwm_io_pin_t |
struct tau_pwm_channel_cfg_t |
TAU_PWM per channel configuration.
Data Fields | ||
---|---|---|
uint8_t | channel | Slave Channel Number (1..7) |
uint16_t | duty_cycle_counts | One-shot: Pulse_width_counts; PWM: Duty_cycle_counts. |
tau_pwm_output_level_t | output_level | Setting of output level for TAU. |
tau_pwm_output_polarity_t | output_polarity | Setting of output polarity for TAU. |
uint8_t | cycle_end_ipl | TAU slave channel IPL. |
IRQn_Type | cycle_end_irq | TAU slave channel IRQ. |
struct tau_pwm_extended_cfg_t |
Extended configuration structure for TAU_PWM
Data Fields | ||
---|---|---|
tau_pwm_operation_clock_t | operation_clock | Setting of operation clock for master and slave channels. |
tau_pwm_source_t | trigger_source | Trigger source for master channel. |
tau_pwm_detect_edge_t | detect_edge | Trigger edge to start pulse period measurement. |
tau_pwm_channel_cfg_t const * | p_slave_channel_cfgs[TAU_PWM_MAX_NUM_SLAVE_CHANNELS] | Configuration for each slave channel, at least 1 slave channel is required. |
struct tau_pwm_instance_ctrl_t |
Channel control block. DO NOT INITIALIZE. Initialization occurs when timer_api_t::open is called.
enum tau_pwm_source_t |
enum tau_pwm_io_pin_t |
Input/Output pins, used to select which duty cycle to update in R_TAU_PWM_DutyCycleSet().
fsp_err_t R_TAU_PWM_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_PWM implementation of the timer requires a tau_pwm_extended_cfg_t extension parameter.
Example:
FSP_SUCCESS | Initialization was successful |
FSP_ERR_ASSERTION | A required input pointer is NULL, the source divider/period/duty cycle counts or number of slave channels is invalid. |
FSP_ERR_ALREADY_OPEN | Module is already open. |
FSP_ERR_IRQ_BSP_DISABLED | ISR of master channel must be enabled |
FSP_ERR_INVALID_MODE | Invalid configuration option provided for selected timer mode |
FSP_ERR_INVALID_CHANNEL | The master/slave channel selected is not available on this device, slave channel number must be greater than master channel number. |
fsp_err_t R_TAU_PWM_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_PWM_Start | ( | timer_ctrl_t *const | p_ctrl | ) |
Starts timer (pwm mode) or triggers the one-shot pulse output by software (one-shot mode). 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_NOT_ENABLED | In One-shot mode, timer must be enabled first. |
fsp_err_t R_TAU_PWM_Reset | ( | timer_ctrl_t *const | p_ctrl | ) |
Resets the counter value to the current period and duty cycle. 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_TAU_PWM_Enable | ( | timer_ctrl_t *const | p_ctrl | ) |
Enables external event inputs that can start the counter and enables the software trigger. After a successful call to this function, the timer is placed into the trigger detection wait state. 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_INVALID_MODE | The mode is invalid, only called in TIMER_MODE_ONE_SHOT mode. |
FSP_ERR_UNSUPPORTED | Unsupported when one shot mode support is disabled |
fsp_err_t R_TAU_PWM_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. Implements timer_api_t::periodSet.
Example:
FSP_SUCCESS | Period value written successfully. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
FSP_ERR_INVALID_ARGUMENT | Period counts is out of range. |
fsp_err_t R_TAU_PWM_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 PWM compare match is not supported. |
fsp_err_t R_TAU_PWM_DutyCycleSet | ( | timer_ctrl_t *const | p_ctrl, |
uint32_t const | duty_cycle_counts, | ||
uint32_t const | pin | ||
) |
Sets duty cycle on requested pin. Implements timer_api_t::dutyCycleSet.
Duty cycle is updated in the timer data register. The updated duty cycle is reflected after the next cycle end (counter underflow).
Example:
[in] | p_ctrl | Pointer to instance control block. |
[in] | duty_cycle_counts | Duty cycle to set in counts. |
[in] | pin | Use tau_pwm_io_pin_t to select the target slave channel |
FSP_SUCCESS | Duty cycle updated successfully. |
FSP_ERR_ASSERTION | p_ctrl was NULL or the pin is not one of tau_pwm_io_pin_t. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
FSP_ERR_INVALID_ARGUMENT | Duty cycle is out of range or larger than period. |
fsp_err_t R_TAU_PWM_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 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_PWM_StatusGet | ( | timer_ctrl_t *const | p_ctrl, |
timer_status_t *const | p_status | ||
) |
Retrieves the current timer state and master channel counter value and stores them in provided pointer p_status. Implements timer_api_t::statusGet.
Example:
FSP_SUCCESS | Current timer state and counter value retrieved 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_PWM_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 with the option to provide memory for the callback argument structure. Implements timer_api_t::callbackSet.
FSP_SUCCESS | Callback updated successfully. |
FSP_ERR_ASSERTION | p_ctrl or p_callback was NULL. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
fsp_err_t R_TAU_PWM_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. |