Timer
R2026bImplement timer functionality using General Purpose Timer (GPT) or Asynchronous General-Purpose Timer (AGT) peripherals
Since R2026b
Timer block

To add a block to a model, double-click the canvas and start typing the block name. Then, select the block from the list.
Libraries:
Embedded Coder Support Package for Renesas RA
Microcontrollers /
Renesas RA6 Based
Description
The Timer block implements timer functionality using the General PWM Timer (GPT) or Asynchronous General-Purpose Timer (AGT) peripherals on Renesas RA microcontrollers. The block uses configurable timer instances defined in the RA Smart Configurator project and provides access to timer count values through the FSP (Flexible Software Package) APIs.
The block provides the following capabilities:
Read the current timer count value.
Dynamically control the timer period during execution.
Start or stop the timer counter during execution.
Reset the timer counter on demand.
Monitor the FSP API status of timer operations.
The timer starts automatically after initialization and continues counting based on the configured clock source and period settings.
Examples
Update Timer Period and Measure Encoder Counts on Renesas RA Microcontrollers
Use timer blocks in the Embedded Coder® Support Package for Renesas RA Microcontrollers to dynamically update the timer period, enable or disable the timer during execution, and reset the timer counter by using the AGT peripheral. It also shows how to update the timer period for the GPT peripheral and observe the counter waveform behavior when period values change at different time instants. Additionally, the example demonstrates how to perform phase counting using an encoder. In this example, you emulate the encoder pulses using two phase-shifted GPIO pulses with the GPT peripheral.
Ports
Input
Input value to set the timer period. The interpretation depends on the Specify period as parameter:
Seconds — The input value specifies the timer period in seconds. The block converts this value to raw counts based on the timer clock frequency.
Raw counts — The input value specifies the timer period directly in counter ticks.
Note
For AGT, period updates take effect immediately. For GPT, period updates take effect after the next timer overflow event. As a result, period changes can take effect at different times depending on the selected timer peripheral.
Dependencies
To enable this port, select the Add an input port to set period parameter.
Data Types: single | double | uint8 | uint16 | uint32
Level-triggered logical signal to start or stop the timer counter during execution. The block evaluates the signal level at each time step.
1(true) — Timer counter is started.0(false) — Timer counter is stopped.
Dependencies
To enable this port, select the Add an input port to enable timer counter parameter.
Data Types: Boolean
Edge-triggered logical signal to reset the timer counter to its initial
value. The block resets the counter on the rising edge (transition from
0 to 1).
1(true) — Timer counter is reset.0(false) — No action is performed.
Dependencies
To enable this port, select the Add an input port to reset counter parameter.
Data Types: Boolean
Output
Outputs the current timer counter value as a uint32 value.
The count value increments or decrements based on the configured count direction
and clock source.
Data Types: uint32
Outputs the status of the timer FSP API operations as an
int32 value.
0(FSP_SUCCESS) — The operation completed successfully.>0— An error occurred. The value represents the specific FSP error code.
Dependencies
To enable this port, select the Output status parameter.
Data Types: int32
Parameters
Specify the name of the timer stack instance (GPT or AGT) as configured in the RA Smart Configurator (RASC) project. Click Browse to select from available timer stack instances defined in the project.
Programmatic Use
Block Parameter:
TimerModule
|
When you select this parameter, the block adds a Period input port that allows you to dynamically set the timer period during execution.
Programmatic Use
Block Parameter:
EnablePeriodInput
|
Select the unit for the period input value.
Seconds— The period input value is specified in seconds. The block converts this value to raw counts based on the timer clock frequency.Raw counts— The period input value is specified directly in counter ticks.
Note
When using Seconds with the r_gpt timer stack, the
block uses the GPT source clock frequency configured in RASC to convert the
period value to raw counts. Ensure that the source clock divider configured in
RASC matches the intended timer resolution.
Dependencies
To enable this parameter, select the Add an input port to set period parameter.
Programmatic Use
Block Parameter:
SpecifyPeriodAs
|
When you select this parameter, the block adds an Enable input port that allows you to start or stop the timer counter during execution.
Programmatic Use
Block Parameter:
EnableTimerCounterInput
|
When you select this parameter, the block adds a Reset input port that allows you to reset the timer counter to its initial value on demand.
Programmatic Use
Block Parameter:
EnableResetCounterInput
|
When you select this parameter, the block adds a Status
output port that reports the status of timer FSP API operations as an
int32 value.
Programmatic Use
Block Parameter:
OutputStatus
|
Specify how often (in seconds) the block reads the timer count value. Enter a value greater than zero. When you specify this parameter as -1, Simulink® determines the best sample time for the block based on the block context within the model.
Programmatic Use
Block Parameter:
SampleTime
|
Version History
Introduced in R2026b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
