RZ/A Flexible Software Package Documentation
Release v3.3.0
|
|
Driver for the MTU3 peripherals on RZ microprocessor. This module implements the Timer Interface.
The MTU3 module can be used to measure external input signals, generate a periodic interrupt, or output a periodic or PWM signal to a MTIOC pin.
This module supports the MTU3 peripherals are 16-bit timers. The 16-bit timers are all treated the same in this module from the API perspective.
The MTU3 module has the following features:
The following functions are not supported in RZ/A3UL.
RZ MPUs have two timer peripherals: the Multi-Function Timer Pulse Unit 3 (MTU3) and the General Timer (GTM). When selecting between them, consider these factors:
MTU3 | GTM | |
---|---|---|
Available Channels | The number of MTU3 channels is device specific. All currently supported MPUs have at least 8 MTU3 channels. | All MPUs have 3 GTM channels. |
Timer Resolution | All MPUs have at least one 16-bit MTU3 timer. | The GTM timers are 32-bit timers. |
Clock Source | The MTU3 runs off P0 clock with a configurable divider up to 1024. | The GTM runs off P0 clock. |
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Pin Output Support |
| Disabled | If selected code for outputting a waveform to a pin is included in the build. |
Configuration | Options | Default | Description |
---|---|---|---|
General > Name | Name must be a valid C symbol | g_timer0 | Module name. |
General > Channel | Channel number must exist on this MPU | 0 | Specify the hardware channel. |
General > Mode |
| Periodic | Mode selection. Periodic: Generates periodic interrupts or square waves. One-shot: Generate a single interrupt or a pulse wave. Note: One-shot mode is implemented in software. ISRs must be enabled for one-shot even if callback is unused. PWM: Generates basic PWM waveforms. Triangle-Wave Symmetric PWM: Generates symmetric PWM waveforms with duty cycle determined by compare match set during a crest interrupt and updated at the next trough. Triangle-Wave Asymmetric PWM: Generates asymmetric PWM waveforms with duty cycle determined by compare match set during a crest/trough interrupt and updated at the next trough/crest. |
General > TGRA(Output Compare or Input Capture Value) | Value must be an integer between 1 and 65536 (0x10000). | 0x10000 | Capture/Compare match A value. |
General > TGRB(Output Compare or Input Capture Value) | Value must be an integer between 1 and 65536 (0x10000). | 0x10000 | Capture/Compare match B value. |
General > TGRC(Output Compare or Input Capture Value) | Value must be an integer between 1 and 65536 (0x10000). | 0x10000 | Capture/Compare match C value. |
General > TGRD(Output Compare or Input Capture Value) | Value must be an integer between 1 and 65536 (0x10000). | 0x10000 | Capture/Compare match D value. |
General > Time Prescaler | Refer to the RZA Configuration tool for available options. | P0CLK divided by 1 (common ch) | Select time prescaler. |
General > Clock Edge |
| Rising | Select clock edge. |
General > Counter Clear Source |
| Disabled | Select counter clear source. |
Noise Filter > External Clock > Enable |
| Sets the noise filter for the external clock. Since it is a setting common to all channels, it may be overwritten by other Stacks settings. | |
Noise Filter > External Clock > Clock Select |
| P0CLK divided by 1 | Select noise filter clock. |
Noise Filter > Input Capture > Enable |
| Select whether to enable extra features on this channel. | |
Noise Filter > Input Capture > Clock Select |
| P0CLK divided by 1 | Select noise filter clock. |
I/O Control > MTIOCnA Pin Function |
| No Output | Select TGRA initial output. |
I/O Control > MTIOCnB Pin Function |
| No Output | Select TGRB initial output. |
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 |
Interrupts > Overflow/Crest Interrupt Enable | MCU Specific Options | Enable the overflow interrupt. | |
Interrupts > Overflow/Crest Interrupt Priority | Value must be an integer between 0 and 31 | 24 | Select the overflow interrupt priority. This is the crest interrupt for triangle-wave PWM. |
Interrupts > Capture/Compare Match A Interrupt Enable | MCU Specific Options | Enable the capture/compare match A interrupt. | |
Interrupts > Capture/Compare Match A Interrupt Priority | Value must be an integer between 0 and 31 | 24 | Select the interrupt priority for capture/compare match A. |
Interrupts > Capture/Compare Match B Interrupt Enable | MCU Specific Options | Enable the capture/compare match B interrupt. | |
Interrupts > Capture/Compare Match B Interrupt Priority | Value must be an integer between 0 and 31 | 24 | Select the interrupt priority for capture/compare match B. |
Extra Features > ADC Trigger > Start request cycle A (Start Request Delaying Function) | Must be a valid non-negative integer with a maximum configurable value of 65535 (0xffff). | 0 | Timer A/D Converter start request cycle A (MTU4 or MTU7). |
Extra Features > ADC Trigger > Start request cycle B (Start Request Delaying Function) | Must be a valid non-negative integer with a maximum configurable value of 65535 (0xffff). | 0 | Timer A/D Converter start request cycle B (MTU4 or MTU7). |
Extra Features > ADC Trigger > A/D Converter Activation by TGRA Input Capture/Compare Match Enable |
| Disabled | Select whether to enable A/D Converter Activation by TGRA Input Capture/Compare Match. |
Extra Features > Interrupt Skipping > Group A > Mode |
| Mode 1 | Selects interrupt skipping function 1 or 2(TIMTRA). |
Extra Features > Interrupt Skipping > Group A > TCIV4 Interrupt Skip Count |
| Not skip | Select the number of TCIV4 interrupts to skip. |
Extra Features > Interrupt Skipping > Group A > TCIV3 Interrupt Skip Count |
| Not skip | Select the number of TCIV3 interrupts to skip. |
Extra Features > Interrupt Skipping > Group A > TRG4AN/TRG4BN Interrupt Skip Count |
| Not skip | Select the number of TRG4AN/TRG4BN interrupts to skip. |
Extra Features > Interrupt Skipping > Group B > Mode |
| Mode 1 | Selects interrupt skipping function 1 or 2(TIMTRB). |
Extra Features > Interrupt Skipping > Group B > TCIV7 Interrupt Skip Count |
| Not skip | Select the number of TCIV7 interrupts to skip. |
Extra Features > Interrupt Skipping > Group B > TGIA6 Interrupt Skip Count |
| Not skip | Select the number of TGIA6 interrupts to skip. |
Extra Features > Interrupt Skipping > Group B > TRG7AN/TRG7BN Interrupt Skip Count |
| Not skip | Select the number of TRG7AN/TRG7BN interrupts to skip. |
Extra Features > Extra Features Enable |
| Disabled | Select whether to enable extra features on this channel. |
The MTU3 clock is based on the P0 clock frequency. You can set the P0 clock frequency using the Clocks tab of the Configuration editor.
This module can use MTIOCA and MTIOCB pins as output pins for periodic or PWM signals.
This module can use MTIOCA and MTIOCB as input pins to measure input signals.
The period is updated after the next counter compare match after calling R_MTU3_PeriodSet().
The duty cycle is updated after the next counter compare match after calling R_MTU3_DutyCycleSet().
The MTIOC pin toggles twice each time the timer 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 MTU3 timer. Since the periodic output is actually a PWM output, the time at the stop level is one cycle shorter than the time opposite the stop level for odd period values.
For the PWM output signal, the signal level at the start of the cycle and at the end of the cycle can be selected arbitrarily.
When an interrupt skipping source is selected a hardware counter will increment each time the selected event occurs. Each interrupt past the first (up to the specified skip count) will be suppressed.
This is a basic example of minimal use of the MTU3 in an application.
This is an example of a timer callback.
To use the MTU3 as a free running counter, select periodic mode and set the the Period to 0xFFFF for a 16-bit timer.
This an example of updating the period.
This an example of updating the duty cycle.
This example demonstrates the configuration and use of compare match with MTU3 timer.
Data Structures | |
struct | mtu3_output_pin_t |
struct | mtu3_instance_ctrl_t |
struct | mtu3_extended_pwm_cfg_t |
struct | mtu3_extended_cfg_t |
Enumerations | |
enum | mtu3_io_pin_level_t |
enum | mtu3_clock_edge_t |
enum | mtu3_clock_div_t |
enum | mtu3_tcnt_clear_t |
enum | mtu3_io_pin_t |
enum | mtu3_noise_filter_t |
enum | mtu3_noise_filter_mtclk_t |
enum | mtu3_noise_filter_clock_t |
enum | mtu3_noise_filter_external_clock_t |
enum | mtu3_interrupt_skip_mode_t |
enum | mtu3_interrupt_skip_count_t |
enum | mtu3_adc_compare_match_t |
enum | mtu3_adc_activation_tgra_compare_match_t |
struct mtu3_output_pin_t |
Configurations for output pins.
Data Fields | ||
---|---|---|
mtu3_io_pin_level_t | output_pin_level_a | I/O Control A. |
mtu3_io_pin_level_t | output_pin_level_b | I/O Control B. |
struct mtu3_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. | |
void * | p_reg |
Base register for this channel. | |
R_MTU_Type * | p_reg_com |
Base register for this channel(common ch) | |
void * | p_reg_nf |
Base register for this channel(noise fileter) | |
uint32_t | channel_mask |
Channel bitmask. | |
void(* | p_callback )(timer_callback_args_t *) |
Pointer to callback. | |
timer_callback_args_t * | p_callback_memory |
Pointer to optional callback argument memory. | |
void const * | p_context |
Pointer to context to be passed into callback function. | |
struct mtu3_extended_pwm_cfg_t |
MTU3 extension for advanced PWM features.
Data Fields | ||
---|---|---|
mtu3_interrupt_skip_mode_t | interrupt_skip_mode_a | Selects interrupt skipping function 1 or 2(TIMTRA) |
mtu3_interrupt_skip_mode_t | interrupt_skip_mode_b | Selects interrupt skipping function 1 or 2(TIMTRB) |
uint16_t | adc_a_compare_match | Timer A/D Converter Start Request Cycle A (MTU4 or MTU7) |
uint16_t | adc_b_compare_match | Timer A/D Converter Start Request Cycle B (MTU4 or MTU7) |
mtu3_interrupt_skip_count_t | interrupt_skip_count_tciv4 | TCIV4 Interrupt Skipping Count Setting(TITCR1A) |
mtu3_interrupt_skip_count_t | interrupt_skip_count_tgia3 | TGIA3 Interrupt Skipping Count Setting(TITCR1A) |
mtu3_interrupt_skip_count_t | interrupt_skip_count_tciv7 | TCIV7 Interrupt Skipping Count Setting(TITCR1B) |
mtu3_interrupt_skip_count_t | interrupt_skip_count_tgia6 | TGIA6 Interrupt Skipping Count Setting(TITCR1B) |
mtu3_interrupt_skip_count_t | interrupt_skip_count_tgr4an_bn | TRG4AN/TRG4BN Interrupt Skipping Count Setting(TITCR2A) |
mtu3_interrupt_skip_count_t | interrupt_skip_count_tgr7an_bn | TRG7AN/TRG7BN Interrupt Skipping Count Setting(TITCR2B) |
struct mtu3_extended_cfg_t |
The MTU3 extension constitutes a unique feature of MTU3.
Data Fields | ||
---|---|---|
uint32_t | tgra_val | Capture/Compare match A register. |
uint32_t | tgrb_val | Capture/Compare match B register. |
uint32_t | tgrc_val | Capture/Compare match C register (Does not exist in MTU ch1-2) |
uint32_t | tgrd_val | Capture/Compare match D register (Does not exist in MTU ch1-2) |
mtu3_clock_div_t | mtu3_clk_div | Time Prescaler Select. |
mtu3_clock_edge_t | clk_edge | Clock Edge Select. |
mtu3_tcnt_clear_t | mtu3_clear | Counter Clear Source Select. |
mtu3_output_pin_t | mtioc_ctrl_setting | I/O Control A, B. |
mtu3_noise_filter_t | noise_filter_mtioc_setting | |
mtu3_noise_filter_clock_t | noise_filter_mtioc_clk | |
mtu3_noise_filter_mtclk_t | noise_filter_mtclk_setting | |
mtu3_noise_filter_external_clock_t | noise_filter_mtclk_clk | |
mtu3_adc_activation_tgra_compare_match_t | adc_activation_setting | |
uint8_t | capture_a_ipl | Capture/Compare match A interrupt priority. |
uint8_t | capture_b_ipl | Capture/Compare match B interrupt priority. |
IRQn_Type | capture_a_irq | Capture/Compare match A interrupt. |
IRQn_Type | capture_b_irq | Capture/Compare match B interrupt. |
mtu3_extended_pwm_cfg_t const * | p_pwm_cfg | Advanced PWM features, optional. |
enum mtu3_io_pin_level_t |
I/O Level Select
enum mtu3_clock_edge_t |
enum mtu3_clock_div_t |
Time Prescaler Select
enum mtu3_tcnt_clear_t |
enum mtu3_io_pin_t |
enum mtu3_noise_filter_t |
Disables or enables the noise filter for input from the MTIOCnA pin
Disables or enables the noise filter for the external clock input pins of the MTU
Number of interrupts to skip between events
fsp_err_t R_MTU3_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 MTU3 implementation of the general timer can accept a mtu3_extended_cfg_t extension parameter.
Example:
FSP_SUCCESS | Initialization was successful and timer has started. |
FSP_ERR_ASSERTION | A required input pointer is NULL. |
FSP_ERR_ALREADY_OPEN | Module is already open. |
FSP_ERR_INVALID_MODE | Only PERIODIC and PWM are supported. |
FSP_ERR_IP_CHANNEL_NOT_PRESENT | The channel requested in the p_cfg parameter is not available on this device. |
fsp_err_t R_MTU3_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_MTU3_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_MTU3_Reset | ( | timer_ctrl_t *const | p_ctrl | ) |
Resets the counter value to 0. 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_MTU3_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 compare match. 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 | A required pointer was NULL, or the period was not in the valid range of 1 to 0xFFFF. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
fsp_err_t R_MTU3_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.
Duty cycle is updated in the TGRx register.
[in] | p_ctrl | Pointer to instance control block. |
[in] | duty_cycle_counts | Duty cycle to set in counts. When the initial output setting of the period register is LOW, entering a value greater than the period register will result in a 0% duty cycle. |
[in] | pin | Not Used. |
FSP_SUCCESS | Duty cycle updated successfully. |
FSP_ERR_ASSERTION | A required pointer was NULL, or the period was not in the valid range of 1 to 0xFFFF. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
FSP_ERR_UNSUPPORTED | MTU3_CFG_OUTPUT_SUPPORT_ENABLE is 0. |
fsp_err_t R_MTU3_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_t R_MTU3_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.
FSP_SUCCESS | TGRx, count direction, frequency, 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_MTU3_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_MTU3_CounterSet | ( | timer_ctrl_t *const | p_ctrl, |
uint32_t | counter | ||
) |
Set counter value.
FSP_SUCCESS | Counter value updated. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
FSP_ERR_IN_USE | The timer is running. Stop the timer before calling this function. |
fsp_err_t R_MTU3_OutputEnable | ( | timer_ctrl_t *const | p_ctrl, |
mtu3_output_pin_t | pin_level | ||
) |
Enable output for MTIOCA and/or MTIOCB.
FSP_SUCCESS | Output is enabled. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
fsp_err_t R_MTU3_OutputDisable | ( | timer_ctrl_t *const | p_ctrl, |
mtu3_io_pin_t | pin | ||
) |
Disable output for MTIOCA and/or MTIOCB.
FSP_SUCCESS | Output is disabled. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
fsp_err_t R_MTU3_Enable | ( | timer_ctrl_t *const | p_ctrl | ) |
timer_api_t::enable is not supported.
FSP_ERR_UNSUPPORTED | Enable not supported on this MPU. |
fsp_err_t R_MTU3_Disable | ( | timer_ctrl_t *const | p_ctrl | ) |
timer_api_t::disable is not supported.
FSP_ERR_UNSUPPORTED | Disable not supported on this MPU. |
fsp_err_t R_MTU3_AdcTriggerSet | ( | timer_ctrl_t *const | p_ctrl, |
mtu3_adc_compare_match_t | which_compare_match, | ||
uint16_t | compare_match_value | ||
) |
Set A/D converter start request compare match value.
FSP_SUCCESS | Counter value updated. |
FSP_ERR_ASSERTION | p_ctrl was NULL. |
FSP_ERR_NOT_OPEN | The instance is not opened. |
fsp_err_t R_MTU3_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 | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
fsp_err_t R_MTU3_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. |