RA Flexible Software Package Documentation  Release v5.6.0

 
Timer, Simultaneous Channel (r_tau_pwm)

Functions

fsp_err_t R_TAU_PWM_Open (timer_ctrl_t *const p_ctrl, timer_cfg_t const *const p_cfg)
 
fsp_err_t R_TAU_PWM_Stop (timer_ctrl_t *const p_ctrl)
 
fsp_err_t R_TAU_PWM_Start (timer_ctrl_t *const p_ctrl)
 
fsp_err_t R_TAU_PWM_Reset (timer_ctrl_t *const p_ctrl)
 
fsp_err_t R_TAU_PWM_Enable (timer_ctrl_t *const p_ctrl)
 
fsp_err_t R_TAU_PWM_PeriodSet (timer_ctrl_t *const p_ctrl, uint32_t const period_counts)
 
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)
 
fsp_err_t R_TAU_PWM_DutyCycleSet (timer_ctrl_t *const p_ctrl, uint32_t const duty_cycle_counts, uint32_t const pin)
 
fsp_err_t R_TAU_PWM_InfoGet (timer_ctrl_t *const p_ctrl, timer_info_t *const p_info)
 
fsp_err_t R_TAU_PWM_StatusGet (timer_ctrl_t *const p_ctrl, timer_status_t *const p_status)
 
fsp_err_t R_TAU_PWM_CallbackSet (timer_ctrl_t *const p_api_ctrl, void(*p_callback)(timer_callback_args_t *), void const *const p_context, timer_callback_args_t *const p_callback_memory)
 
fsp_err_t R_TAU_PWM_Close (timer_ctrl_t *const p_ctrl)
 

Detailed Description

Driver for the TAU_PWM peripheral on RA MCUs. This module implements the Timer Interface.

Overview

Features

The TAU_PWM module has the following features:

Configuration

Build Time Configurations for r_tau_pwm

The following build time configurations are defined in fsp_cfg/r_tau_pwm_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.
One-shot Pulse Output Mode Support
  • Disabled
  • Enabled
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
  • Disabled
  • Enabled
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
  • Enabled
Disabled Enable support for multiple slaves

Configurations for Timers > Timer, Simultaneous Channel Operation (r_tau_pwm)

This module can be added to the Stacks tab via New Stack > Timers > Timer, Simultaneous Channel Operation (r_tau_pwm).

ConfigurationOptionsDefaultDescription
General
NameName must be a valid C symbolg_timer0 Module name.
Operation Clock
  • CK00
  • CK01
CK00 Select the operation clock
Mode
  • One-shot pulse output
  • PWM output
PWM output Mode selection.
Master ChannelChannel 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.
PeriodValue must be a non-negative integer0x10000 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
  • Nanoseconds
  • Microseconds
  • Milliseconds
  • Seconds
  • Hertz
  • Kilohertz
Raw Counts Unit of the period specified above
Input (One-shot pulse)
Trigger SourceMCU Specific OptionsSelect the trigger source for master channel.
Detect Edge
  • Falling Edge
  • Rising Edge
  • Both Edges
Falling Edge Select the detect edge.
Interrupts
CallbackName must be a valid C symbolNULL 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 PriorityMCU Specific OptionsTimer interrupt priority.

Configurations for Timers > TAU PWM Channel Configuration (r_tau_pwm)

ConfigurationOptionsDefaultDescription
General
ChannelValue must be between 0 and 7.1 Specify the slave channel.
Output
Output Level
  • Start Level Low
  • Start Level High
Start Level Low Output level of TAU slave channel.
Output Polarity
  • Active-high
  • Active-low
Active-high Output polarity of TAU slave channel.
One-Shot Pulse WidthValue must be a non-negative integer0xffff 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
  • Nanoseconds
  • Microseconds
  • Milliseconds
  • Seconds
  • Hertz
  • Kilohertz
Raw Counts Unit of the period specified above
PWM Duty Cycle PercentValue must be a non-negative integer between 0 and 10050 Specify the duty cycle percent for output pulse of slave channel.
Interrupts
Interrupt PriorityMCU Specific OptionsTimer interrupt priority.

Clock Configuration

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.

Pin Configuration

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.

Timer Period And Duty Cycle

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
Note
If PCLK (undivided) is selected as the operation clock (CK00, CK01) and TDR0n is set to 0x0000 (n = 0 to 7), interrupt requests output from timer array units cannot be used. So, when PCLK is undivided, the minimum period must be plus one.
Because the period interrupt occurs when the counter underflows, setting the period register to 0 results in an effective period of 1 count. For this reason, all user-provided raw count values reflect the actual number of period counts (not the raw register values).

Usage Notes

Updating Period and Duty Cycle

The period and duty cycle are updated after the next counter underflow after calling R_TAU_PWM_PeriodSet() or R_TAU_PWM_DutyCycleSet().

One-Shot Pulse Output Mode

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.

PWM Output

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.

Note
When two or more master channels are to be used, slave channels with a master channel between them may not be set. For example, if channels 0 and 4 are set as master channels, channels 1 to 3 can be set as the slave channels of master channel 0, channels 5 to 7 cannot be set as the slave channels of master channel 0.

The period is counted by the master channel, and the duty cycle is counted by the slave channel.

Controlling TAU_PWM with ELC Events

The TAU_PWM timer can be configured to trigger the timer counter when an ELC event occurs.

Note
Triggering the timer using ELC events is supported only when master channel is set to 0 and mode is set to One-shot pulse output.
The event links for the ELC must be configured outside this module.

Triggering ELC Events with TAU_PWM

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.

Note
Only event signals from channel 00 to 03 are available.

Limitations

Examples

TAU_PWM Basic Example

This is a basic example of minimal use of the TAU PWM (in PWM Output mode) in an application.

void tau_pwm_basic_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = R_TAU_PWM_Open(&g_timer0_ctrl, &g_timer0_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Start the timer. */
(void) R_TAU_PWM_Start(&g_timer0_ctrl);
}

TAU_PWM Callback Example

This is an example of a timer callback.

Note
The callback function always called after the period time (in PWM output mode) or delay time (in One-shot pulse output mode) has expired. Additionally, it can be optionally called after the duty cycle (in PWM output mode) or pulse width (in One-shot pulse output mode) has expired by enabling the slave channel's interrupt.

uint32_t g_timer_master_cycle_end_counter = 0;
uint32_t g_timer_slave_cycle_end_counter = 0;
/* Example callback called when timer expires. */
void timer_callback (timer_callback_args_t * p_args)
{
{
g_timer_master_cycle_end_counter++;
}
{
g_timer_slave_cycle_end_counter++;
}
}

TAU_PWM One-Shot Pulse Output Mode Example

TAU_PWM One-Shot Pulse Output Mode Example - Software Trigger

This example demonstrates the configuration and use of One-shot pulse output mode with TAU_PWM timer when using the software trigger.

void tau_pwm_one_shot_software_trigger_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = R_TAU_PWM_Open(&g_timer0_ctrl, &g_timer0_one_shot_software_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Enable triggering (including by software). */
(void) R_TAU_PWM_Enable(&g_timer0_ctrl);
g_timer_master_cycle_end_counter = 0;
g_timer_slave_cycle_end_counter = 0;
(void) R_TAU_PWM_Start(&g_timer0_ctrl);
uint32_t timeout = TIMER_TEST_WAVEFORM_TIMEOUT;
while (((timeout--) > 0) && (0 == g_timer_slave_cycle_end_counter))
{
/* Wait for one shot pulse output to complete */
}
/* Ensure exactly one slave interrupt and one master interrupt have occurred. */
assert(1 == g_timer_master_cycle_end_counter);
assert(1 == g_timer_slave_cycle_end_counter);
g_timer_master_cycle_end_counter = 0;
g_timer_slave_cycle_end_counter = 0;
/* Start trigger by software. */
(void) R_TAU_PWM_Start(&g_timer0_ctrl);
timeout = TIMER_TEST_WAVEFORM_TIMEOUT;
while (((timeout--) > 0) && (0 == g_timer_slave_cycle_end_counter))
{
/* Wait for one shot pulse output to complete */
}
/* Ensure exactly one slave interrupt and one master interrupt have occurred. */
assert(1 == g_timer_master_cycle_end_counter);
assert(1 == g_timer_slave_cycle_end_counter);
/* Stop timer and disable the software trigger. */
(void) R_TAU_PWM_Stop(&g_timer0_ctrl);
/* Read the current counter value. Counter value is in status.counter. */
(void) R_TAU_PWM_StatusGet(&g_timer0_ctrl, &status);
}

TAU_PWM One-Shot Pulse Output Mode Example - Pin Input 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.

void tau_pwm_one_shot_pin_input_trigger_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = R_TAU_PWM_Open(&g_timer0_ctrl, &g_timer0_one_shot_input_pin_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Enable the input trigger. */
(void) R_TAU_PWM_Enable(&g_timer0_ctrl);
(void) R_TAU_PWM_Start(&g_timer0_ctrl);
/* Wait for trigger source from the input pin */
/* Disable the input trigger. */
(void) R_TAU_PWM_Stop(&g_timer0_ctrl);
/* Read the current counter value. Counter value is in status.counter. */
(void) R_TAU_PWM_StatusGet(&g_timer0_ctrl, &status);
}

TAU_PWM PWM Output Mode Example

This example demonstrates the configuration and use of PWM output mode with TAU_PWM timer.

void tau_pwm_multiple_pwm_output_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = R_TAU_PWM_Open(&g_timer0_ctrl, &g_timer0_pwm_output_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Start the timer. */
(void) R_TAU_PWM_Start(&g_timer0_ctrl);
/* (Optional) Stop the timer. */
(void) R_TAU_PWM_Stop(&g_timer0_ctrl);
/* Read the current counter value. Counter value is in status.counter. */
(void) R_TAU_PWM_StatusGet(&g_timer0_ctrl, &status);
}

TAU_PWM Period Update Example

This an example of updating the period.

#define TAU_PWM_EXAMPLE_MSEC_PER_SEC (1000)
#define TAU_PWM_EXAMPLE_DESIRED_PERIOD_MSEC (20)
/* This example shows how to calculate a new period value at runtime. */
void tau_pwm_period_calculation_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = R_TAU_PWM_Open(&g_timer0_ctrl, &g_timer0_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Start the timer. */
(void) R_TAU_PWM_Start(&g_timer0_ctrl);
/* Get the source clock frequency (in Hz) */
(void) R_TAU_PWM_InfoGet(&g_timer0_ctrl, &info);
uint32_t timer_freq_hz = info.clock_frequency;
/* Calculate the desired period based on the current clock. Note that this calculation could overflow if the
* desired period is larger than UINT32_MAX. A cast to uint32_t is used to prevent this. */
uint32_t period_counts =
(uint32_t) ((timer_freq_hz * TAU_PWM_EXAMPLE_DESIRED_PERIOD_MSEC) / TAU_PWM_EXAMPLE_MSEC_PER_SEC);
/* Set the calculated period. This will return an error if parameter checking is enabled and the calculated
* period is larger than UINT16_MAX. */
err = R_TAU_PWM_PeriodSet(&g_timer0_ctrl, period_counts);
assert(FSP_SUCCESS == err);
}

TAU_PWM Duty Cycle Update Example

This an example of updating the duty cycle.

#define TAU_PWM_EXAMPLE_MSEC_PER_SEC (1000)
#define TAU_PWM_EXAMPLE_DESIRED_PERIOD_MSEC (20)
/* This example shows how to calculate a new period value at runtime. */
void tau_pwm_period_calculation_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = R_TAU_PWM_Open(&g_timer0_ctrl, &g_timer0_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Start the timer. */
(void) R_TAU_PWM_Start(&g_timer0_ctrl);
/* Get the source clock frequency (in Hz) */
(void) R_TAU_PWM_InfoGet(&g_timer0_ctrl, &info);
uint32_t timer_freq_hz = info.clock_frequency;
/* Calculate the desired period based on the current clock. Note that this calculation could overflow if the
* desired period is larger than UINT32_MAX. A cast to uint32_t is used to prevent this. */
uint32_t period_counts =
(uint32_t) ((timer_freq_hz * TAU_PWM_EXAMPLE_DESIRED_PERIOD_MSEC) / TAU_PWM_EXAMPLE_MSEC_PER_SEC);
/* Set the calculated period. This will return an error if parameter checking is enabled and the calculated
* period is larger than UINT16_MAX. */
err = R_TAU_PWM_PeriodSet(&g_timer0_ctrl, period_counts);
assert(FSP_SUCCESS == err);
}

ELC Example

This is an example of using TAU_PWM with ELC events.

/* This example shows how to use ELC event to trigger the timer counters. */
void tau_pwm_elc_event_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = R_TAU_PWM_Open(&g_timer0_ctrl, &g_timer0_elc_event_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Enable the elc event trigger. */
(void) R_TAU_PWM_Enable(&g_timer0_ctrl);
(void) R_TAU_PWM_Start(&g_timer0_ctrl);
/* Wait for ELC event */
/* Disable the elc event trigger. */
(void) R_TAU_PWM_Stop(&g_timer0_ctrl);
/* Read the current counter value. Counter value is in status.counter. */
(void) R_TAU_PWM_StatusGet(&g_timer0_ctrl, &status);
}

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
 

Data Structure Documentation

◆ tau_pwm_channel_cfg_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.

◆ tau_pwm_extended_cfg_t

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.

◆ tau_pwm_instance_ctrl_t

struct tau_pwm_instance_ctrl_t

Channel control block. DO NOT INITIALIZE. Initialization occurs when timer_api_t::open is called.

Enumeration Type Documentation

◆ tau_pwm_operation_clock_t

Operation clock.

Enumerator
TAU_PWM_OPERATION_CLOCK_CK00 

Operation Clock CK00.

TAU_PWM_OPERATION_CLOCK_CK01 

Operation CLock CK01.

◆ tau_pwm_source_t

Trigger Source

Enumerator
TAU_PWM_SOURCE_PIN_INPUT 

Use TI0n pin input as trigger source.

TAU_PWM_SOURCE_ELC_EVENT 

Use ELC events as trigger source.

◆ tau_pwm_detect_edge_t

TI0n pin input edge

Enumerator
TAU_PWM_DETECT_EDGE_FALLING 

Detects falling edge.

TAU_PWM_DETECT_EDGE_RISING 

Detects rising edge.

TAU_PWM_DETECT_EDGES_BOTH 

Detects both edges.

◆ tau_pwm_output_level_t

Level of TAU pin

Enumerator
TAU_PWM_OUTPUT_LEVEL_LOW 

Pin level low.

TAU_PWM_OUTPUT_LEVEL_HIGH 

Pin level high.

◆ tau_pwm_output_polarity_t

Timer output polarity

Enumerator
TAU_PWM_OUTPUT_POLARITY_ACTIVE_HIGH 

Positive logic output (active-high)

TAU_PWM_OUTPUT_POLARITY_ACTIVE_LOW 

Negative logic output (active-low)

◆ tau_pwm_io_pin_t

Input/Output pins, used to select which duty cycle to update in R_TAU_PWM_DutyCycleSet().

Enumerator
TAU_PWM_IO_PIN_CHANNEL_0 

I/O pin of channel 0.

TAU_PWM_IO_PIN_CHANNEL_1 

I/O pin of channel 1.

TAU_PWM_IO_PIN_CHANNEL_2 

I/O pin of channel 2.

TAU_PWM_IO_PIN_CHANNEL_3 

I/O pin of channel 3.

TAU_PWM_IO_PIN_CHANNEL_4 

I/O pin of channel 4.

TAU_PWM_IO_PIN_CHANNEL_5 

I/O pin of channel 5.

TAU_PWM_IO_PIN_CHANNEL_6 

I/O pin of channel 6.

TAU_PWM_IO_PIN_CHANNEL_7 

I/O pin of channel 7.

Function Documentation

◆ R_TAU_PWM_Open()

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:

/* Initializes the module. */
err = R_TAU_PWM_Open(&g_timer0_ctrl, &g_timer0_cfg);
Return values
FSP_SUCCESSInitialization was successful
FSP_ERR_ASSERTIONA required input pointer is NULL, the source divider/period/duty cycle counts or number of slave channels is invalid.
FSP_ERR_ALREADY_OPENModule is already open.
FSP_ERR_IRQ_BSP_DISABLEDISR of master channel must be enabled
FSP_ERR_INVALID_MODEInvalid configuration option provided for selected timer mode
FSP_ERR_INVALID_CHANNELThe master/slave channel selected is not available on this device, slave channel number must be greater than master channel number.

◆ R_TAU_PWM_Stop()

fsp_err_t R_TAU_PWM_Stop ( timer_ctrl_t *const  p_ctrl)

Stops timer. Implements timer_api_t::stop.

Example:

/* (Optional) Stop the timer. */
(void) R_TAU_PWM_Stop(&g_timer0_ctrl);
Return values
FSP_SUCCESSTimer successfully stopped.
FSP_ERR_ASSERTIONp_ctrl was NULL.
FSP_ERR_NOT_OPENThe instance is not opened.

◆ R_TAU_PWM_Start()

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.

Note
In one-shot mode, this function is supported only after the timer has been placed into the start trigger detection wait state by calling timer_api_t::enable

Example:

/* Start the timer. */
(void) R_TAU_PWM_Start(&g_timer0_ctrl);
Return values
FSP_SUCCESSTimer successfully started.
FSP_ERR_ASSERTIONp_ctrl was NULL.
FSP_ERR_NOT_OPENThe instance is not opened.
FSP_ERR_NOT_ENABLEDIn One-shot mode, timer must be enabled first.

◆ R_TAU_PWM_Reset()

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.

Note
If the timer is stopped when calling this function, the timer counter is not reset. The counter will be reset one cycle after the timer is next started (or restarted), since it takes one cycle to reload the initial count when starting the timer.
Return values
FSP_SUCCESSCounter value written successfully.
FSP_ERR_ASSERTIONp_ctrl was NULL.
FSP_ERR_NOT_OPENThe instance is not opened.

◆ R_TAU_PWM_Enable()

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:

/* Enable triggering (including by software). */
(void) R_TAU_PWM_Enable(&g_timer0_ctrl);
Return values
FSP_SUCCESSExternal events successfully enabled.
FSP_ERR_ASSERTIONp_ctrl was NULL.
FSP_ERR_NOT_OPENThe instance is not opened.
FSP_ERR_INVALID_MODEThe mode is invalid, only called in TIMER_MODE_ONE_SHOT mode.
FSP_ERR_UNSUPPORTEDUnsupported when one shot mode support is disabled

◆ R_TAU_PWM_PeriodSet()

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:

/* Get the source clock frequency (in Hz) */
(void) R_TAU_PWM_InfoGet(&g_timer0_ctrl, &info);
uint32_t timer_freq_hz = info.clock_frequency;
/* Calculate the desired period based on the current clock. Note that this calculation could overflow if the
* desired period is larger than UINT32_MAX. A cast to uint32_t is used to prevent this. */
uint32_t period_counts =
(uint32_t) ((timer_freq_hz * TAU_PWM_EXAMPLE_DESIRED_PERIOD_MSEC) / TAU_PWM_EXAMPLE_MSEC_PER_SEC);
/* Set the calculated period. This will return an error if parameter checking is enabled and the calculated
* period is larger than UINT16_MAX. */
err = R_TAU_PWM_PeriodSet(&g_timer0_ctrl, period_counts);
assert(FSP_SUCCESS == err);
Return values
FSP_SUCCESSPeriod value written successfully.
FSP_ERR_ASSERTIONp_ctrl was NULL.
FSP_ERR_NOT_OPENThe instance is not opened.
FSP_ERR_INVALID_ARGUMENTPeriod counts is out of range.

◆ R_TAU_PWM_CompareMatchSet()

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.

Return values
FSP_ERR_UNSUPPORTEDTAU PWM compare match is not supported.

◆ R_TAU_PWM_DutyCycleSet()

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:

/* Get the current period setting. */
(void) R_TAU_PWM_InfoGet(&g_timer0_ctrl, &info);
uint32_t current_period_counts = info.period_counts;
/* Calculate the desired duty cycle based on the current period. */
uint16_t duty_cycle_counts = (uint16_t) ((current_period_counts * TAU_PWM_EXAMPLE_DESIRED_DUTY_CYCLE_PERCENT) /
TAU_PWM_EXAMPLE_MAX_PERCENT);
/* Set the calculated duty cycle. */
err = R_TAU_PWM_DutyCycleSet(&g_timer0_ctrl, duty_cycle_counts, 1);
assert(FSP_SUCCESS == err);
Parameters
[in]p_ctrlPointer to instance control block.
[in]duty_cycle_countsDuty cycle to set in counts.
[in]pinUse tau_pwm_io_pin_t to select the target slave channel
Return values
FSP_SUCCESSDuty cycle updated successfully.
FSP_ERR_ASSERTIONp_ctrl was NULL or the pin is not one of tau_pwm_io_pin_t.
FSP_ERR_NOT_OPENThe instance is not opened.
FSP_ERR_INVALID_ARGUMENTDuty cycle is out of range or larger than period.

◆ R_TAU_PWM_InfoGet()

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:

/* Get the current period setting. */
(void) R_TAU_PWM_InfoGet(&g_timer0_ctrl, &info);
uint32_t current_period_counts = info.period_counts;
Return values
FSP_SUCCESSPeriod, count direction, frequency written to caller's structure successfully
FSP_ERR_ASSERTIONp_ctrl or p_info was NULL.
FSP_ERR_NOT_OPENThe instance is not opened.

◆ R_TAU_PWM_StatusGet()

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:

/* Read the current counter value. Counter value is in status.counter. */
(void) R_TAU_PWM_StatusGet(&g_timer0_ctrl, &status);
Return values
FSP_SUCCESSCurrent timer state and counter value retrieved successfully.
FSP_ERR_ASSERTIONp_ctrl or p_status was NULL.
FSP_ERR_NOT_OPENThe instance is not opened.

◆ R_TAU_PWM_CallbackSet()

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.

Return values
FSP_SUCCESSCallback updated successfully.
FSP_ERR_ASSERTIONp_ctrl or p_callback was NULL.
FSP_ERR_NOT_OPENThe instance is not opened.

◆ R_TAU_PWM_Close()

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.

Return values
FSP_SUCCESSSuccessful close.
FSP_ERR_ASSERTIONp_ctrl was NULL.
FSP_ERR_NOT_OPENThe instance is not opened.