stm32 Crossseries Timer Overview
stm32 Crossseries Timer Overview
Application note
STM32 cross-series timer overview
Introduction
The purpose of this document is to:
• Present an overview of the timer peripherals for the STM32 product series listed in Table 1.
• Describe the various modes and specific timer features, such as clock sources.
• Explain how to use the available modes and features.
• Explain how to compute the time base in each configuration.
• Describe the timer synchronization sequences and the advanced features for motor
control applications, in addition to the general-purpose timer modes.
For each mode, the document provides typical configurations and implementation
examples.
In the rest of this document (unless otherwise specified), the term STM32xx Series is used
to refer to the product series listed in Table 1.
Contents
1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3 Timer synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.1 Timer system link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.2 Master configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.3 Slave configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
6 Low-power timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
7 Specific applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
7.1 Infrared application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
7.2 3-phase AC and PMSM control motor . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
7.3 Six-step mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
8 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
List of tables
1 Overview
The STM32xx Series devices, based on the Arm® cores(a), have various built-in timers
outlined as follows;
• General-purpose timers are used with any application for: output comparison (timing
and delay generation), one-pulse mode, input capture (for external signal frequency
measurement), sensor interface (encoder, hall sensor).
• Advanced timers: these timers have the most features. In addition to general purpose
functions, they include several features related to motor control and digital power
conversion applications: three complementary signals with deadtime insertion and
emergency shut-down input.
• One or two channel timers: used as general-purpose timers with a limited number of
channels.
• One or two channel timers with complementary output: same as the previous timer
type with an additional deadtime generator on one channel. In some situations, this
feature allows a general purpose timer to be used where an additional advanced timer
would be necessary.
• Basic timers are used either as timebase timers or for triggering the DAC peripheral.
These timers do not have any input or output capabilities.
• Low-power timers are simple general purpose timers and are able to operate in low-
power modes. They are used to generate a wake-up event for example.
• High-resolution timers are specialized timer peripherals designed to drive power
conversion in lighting and power source applications. They can also be used in other
fields that require very fine timing resolution. AN4885, AN4539, and AN4449 are
practical examples of high-resolution timer use.
Table 2, Table 3 and Table 4 summarize the STM32 family timers.
Table 5 presents a general overview of timer features.
Timers are enhanced with more advanced features in newer devices. Besides minor
changes not in scope of this overview, a significant update divides the STM32 family
advanced motor control and general purpose timers. In this document STM32F0/F1/F2/F4
Series and STM32F37x devices are referred to as the “original series”. Some of the features
are not available for them and are identified as such.
a. Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
TIM1
TIM1(1) TIM1(1) TIM1 TIM1 TIM1
Advanced TIM1 TIM1 TIM1 TIM1 TIM8(1) - TIM1
TIM8(1) TIM8(1) TIM8 TIM8(1) TIM8
TIM20(1)
TIM6
TIM6 TIM6 TIM6(1) TIM6 TIM6 TIM6 TIM6 TIM6 TIM6
Basic - TIM6(1) TIM7
TIM7(1) TIM7 TIM7(1) TIM7 TIM7 TIM7(1) TIM7 TIM7(1) TIM7
TIM18
2-channel with
complementary - TIM15 - - TIM15 - - TIM15 TIM15 TIM15 TIM15 -
output
1-channel with
TIM16 TIM16 TIM16 TIM16 TIM16 TIM16 TIM16
complementary - - - - -
TIM17 TIM17 TIM17 TIM17 TIM17 TIM17 TIM17
output
LPTIM1(
Low-power timer - - - - - - 1) - - - - LPTIM1
High-resolution
- - - - - - - - - HRTIM - -
timer
1. Not available on all products in the line. Check the datasheet for details.
More recent versions of advanced timers present several new modes: asymmetric mode, combined mode, one retriggerable mode, combined three PWM mode
and a second break input. These modes are not available in the STM32F0/F1/F2/F4 Series and STM32F37x device advanced control timers
also known as the original series.
TIM1 TIM1
Advanced - - - -
TIM8(1) TIM8
TIM2 TIM2
32-bit - - - TIM5(1)
TIM5(1) TIM5
General
purpose TIM2
TIM2 TIM3(1) TIM3
16-bit TIM2 TIM2 TIM3
TIM3(1) TIM4(1) TIM4
TIM4
TIM6 TIM6 TIM6 TIM6
Basic - -
TIM7(1) TIM7 TIM7(1) TIM7
TIM10
1 channel - - - - -
TIM11
TIM21 TIM21
2-channel TIM21 TIM9 - -
TIM22 TIM22(1)
2-channel with
- - - - TIM15 TIM15
complementary output
1-channel with TIM16 TIM16
- - - -
complementary output TIM17(1) TIM17
LPTIM1
LPTIM1
Low-power timer LPTIM1 LPTIM1 LPTIM1 - LPTIM2
LPTIM2
LPTIM3
High-resolution timer - - - - -
1. Not available on all products in the line. Check the datasheet for details.
TIM1
TIM1 TIM1 TIM1
Advanced TIM1 TIM1 TIM8 TIM1 TIM1 TIM1
TIM8 TIM8 TIM8
TIM20(1)
TIM2 TIM2
TIM2 TIM2 TIM5 TIM3
32-bit TIM2 TIM2 TIM2 TIM2
General TIM5(1) TIM5 TIM23(1) TIM4
purpose TIM24(1) TIM5
TIM3 TIM3 TIM3
16-bit TIM3 TIM3 TIM3 - - -
TIM4 TIM4 TIM4
TIM6 TIM6 TIM6 TIM6 TIM6 TIM6
Basic - -
TIM7 TIM7 TIM7 TIM7 TIM7 TIM7
TIM13 TIM13
1 channel TIM14 TIM14 - - - -
TIM14 TIM14
2-channel - - TIM12 TIM12 - - -
2-channel with
TIM15 TIM15 TIM15 TIM15 TIM15 - -
complementary output
1-channel with TIM16 TIM16 TIM16 TIM 16 TIM16 TIM16 TIM16 TIM16
complementary output TIM17 TIM17 TIM17 TIM 17 TIM17 TIM17 TIM17 TIM17
LPTIM1
LPTIM1
LPTIM2 LPTIM1
LPTIM2 LPTIM1
LPTIM1(1) LPTIM1 LPTIM1 LPTIM3 LPTIM2 LPTIM1
Low-power timer LPTIM3 LPTIM2
LPTIM2(1) LPTIM2 LPTIM2 LPTIM4 LPTIM3 LPTIM2
LPTIM4(1) LPTIM3
LPTIM5 LPTIM4
LPTIM5(1)
LPTIM6
High-resolution timer - HRTIM1(1) HRTIM1(1) - - -
1. Not available on all products in the line. Check the datasheet for details.
1-channel with
one
16 bit Up Yes 1 1 Yes (OC signal) No
complementary
output
2-channel with
one
16 bit Up Yes 2 1 Yes Yes
complementary
output
Low-power
16 bit Up No 1(4) 0 Yes (OC signal) No
timer
High-resolution
16 bit Up Yes Up to 12(4) Up to 6 Yes Yes
timer
1. With STM32L4/G4/F7,WB,L5, U5, H5, H7 Series and STM32F30x/F3x8 lines, the advanced timers have 6 channels. The two extra
channels are however not connected to GPIO (not available externally).
2. General purpose timers are 32-bit counter resolution on some products and 16-bit on others. See Table 2, Table 3 and Table 4 or product
datasheet as reference.
3. On some devices, the counter type also supports Up, Down, Up/Down as exception (STM32L0 Series). Those are numbered differently.
4. Low-power timer and high-resolution timer do not have channels directly comparable with channels on regular timer peripherals. Indicated
number is a practical “channel equivalent”.
a. For the STM32F100/101/102/103/105/107 lines, polarity selection for both edges can be achieved by using
TI1F_ED, but only for TI1 input.
TIM_CLK = 72 MHz
Prescaler = 1
Auto reload = 65535
No repetition counter RCR = 0
Update_event = 72*(10^6)/((1 + 1)*(65535 + 1)*(1))
Update_event = 549.3 Hz
Repetition counter = 1
Update_event = 8000/((1+ 1)*((255 + 1)*(1 + 1))
Update_event = 7.8 Hz
Depending on the counter mode, the update event is generated each:
• Overflow, if up counting mode is used: the DIR bit is reset in TIMx_CR1 register
• Underflow, if down counting mode is used: the DIR bit is set in TIMx_CR1 register
• Overflow and underflow, if center aligned mode is used: the CMS bits are different from
zero.
The update event is generated also by:
• Software, if the UG (update generation) bit is set in TIM_EGR register
• Update generation through the slave mode controller.
As the buffered registers (ARR, PSC, CCRx) need an update event to be loaded with their
preload values, set the URS (update request source) to 1 to avoid the update flag each time
these values are loaded. In this case, the update event is only generated if the counter
overflow/underflow occurs.
The update event can also be disabled by setting the bit UDIS (update disable) in the CR1
register. In this case, the update event is not generated, and shadow registers (ARR, PSC,
CCRx) keep their values. The counter and the prescaler are reinitialized if the UG bit is set,
or if a hardware reset is received from the slave mode controller.
An interrupt or/and a DMA request can be generated when the UIE bit or/and UDE bit are
set in the DIER register.
Most STM32Cube firmware packages include examples in Examples\TIM\TIM_TimeBase
sub folders.
Particular case
To facilitate the input capture measurement, the timer counter is reset after each rising edge
detected on the timer input channel by:
• Selecting TIxFPx as the input trigger by setting the TS bits in the SMCR register
• Selecting the reset mode as the slave mode by configuring the SMS bits in the SMCR
register.
Using this configuration, when an edge is detected, the counter is reset and the period of the
external signal is automatically given by the value on the CCRx register. This method is
used only with channel 1 or channel 2.
In this case, the input capture prescaler (ICPSC) is not considered in the period
computation.
The period is computed as follows:
Period = CCRx /(TIMx_CLK *(PSC+1)* polarity_index(1))
The polarity index is 1 if rising or falling edge is used, and 2 if both edges are used.
Many STM32Cube firmware packages include examples in
Examples\TIM\TIM_InputCapture sub folder.
PWM mode 1
• In up-counting, channelx is active as long as CNT< CCRx, otherwise it is inactive
• In down-counting, channelx is inactive as long as CNT> CCRx, otherwise it is active.
PWM mode 2
• In up-counting, channelx is inactive as long as CNT < CCRx, otherwise it is active
• In down-counting, channelx is active as long as CNT > CCRx, otherwise it is inactive.
Note: Active when OCREF = 1, inactive when OCREF = 0.
For more details on using the timer in this mode, refer to the examples provided in the
STM32Cube package in the Examples\TIM\TIM_OnePulse sub folder.
01 2 3 4 5 6 7 8 76 5 4 3 2 1 0 1 2 3 4 5 6 7 8 76 5 4 3 2 1 0 1 2 3 4 5 6 7 8 76 5 4 3 2 1 0
MS31264V1
OC1Ref PWM2
OC2Ref PWM1
OC1CRef
Combined PWM2
OC1Ref PWM1
OC2Ref PWM2
OC1CRef
Combined PWM1
MS31265V1
Trigger
OCx
MS31266V2
3 Timer synchronization
TIMx
TIMx_CLK
ITR0
ITR1 TRC
Trigger inputs ITR
ITR2
ITR3 TRGI TRGO Trigger
Trigger
output
control
TI 1F ED
TI1FP1
TI1FP2
MS30121V2
1
x 1 0 0 Output disabled Output disabled
OCxREF +
x 1 1 0 Off-state
polarity
OCxREF (not OCxREF)
Motor control
x 1 1 1 + polarity + polarity
(sinewave)
+ deadtime + deadtime
0 x 0 0
0 x 0 1 Outputs
Output disable disconnected
0 x 1 0 from I/O ports
0 x 1 1
0
1 x 0 0
Off-state
1 x 0 1 All PWMs OFF
(outputs are first forced with their (low Z for safe
1 x 1 0 inactive level then forced to their stop)
idle level after the deadtime.)
1 x 1 1
Note: 1 Deadtime insertion is enabled by setting both CCxE and CCxNE bits, and the MOE bit.
2 When only OCxN is enabled (CCxE=0, CCxNE=1), it is not complemented and becomes
active as soon as OCxREF is high. For example, if CCxNP=0 then OCxN=OCxRef. On the
other hand, when both OCx and OCxN are enabled (CCxE=CCxNE=1) OCx becomes
active when OCxREF is high, whereas OCxN is complemented and becomes active when
OCxREF is low.
OC1Ref
OC2Ref
OC3Ref
OC5Ref
OC1Ref Comb
OC2Ref Comb
OC3Ref Comb
MS31267V1
OC1REF
CH1
Delay
CH1N
Delay
MS30125V3
Note: The deadtime parameter is computed using the DTG[7:0] bits and the deadtime clock
(Tdtg).
ON after deadtime
Active Inactive OFF
insertion
Inactive Active OFF OFF
ON after deadtime
Active - OFF
insertion
Note: The LOCK bits can only be written once after the reset. Once the BDTR register has been
written, its content is frozen until the next reset.
TI1
TI2
Counter +1 +1 +1 +1 +1 +1 +1 +1 -1 -1 -1 -1 -1 -1 -1 -1 +1 +1 +1 +1 +1 +1 +1 +1
Up Down Up
DIR bit 0 1 0
MS30129V4
The timer's counter is incremented or decremented for each transition on the selected input
TI1 or TI2.
TI1
TI2
Counter +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1
Up Down Up
DIR bit 0 1 0
MS30128V4
Note: In case of X2 resolution, the counter can also be incremented on the TI1 edge.
In STM32 timer encoder interface mode, the encoder mode3 corresponds to the X4
resolution. In this mode, the counter counts up/down on both TI1 and TI2 edges.
The X2 resolution is selected when encoder mode 1 or mode 2 is selected, that is, the
counter counts up/down on TI2 edge depending on the TI1 level, or the counter counts
up/down on TI1 edge depending on TI2 level.
Hall sensor
The Hall sensor is a type of sensor based on the Hall effect: when a conductor is placed in a
magnetic field, a voltage is generated perpendicular to both the current and the magnetic
field.
There are four types of Hall sensor IC devices that provide a digital output: unipolar
switches, bipolar switches, omnipolar switches, and latches. The main difference between
them is the output waveforms (pulse duration).
The digital hall sensor provides a digital output in relation to the magnetic field that it is
exposed. When the magnetic field increases and is greater than the BRP (magnetic field
release point value), the output is set to ON. When the magnetic field decreases and is
lower than the BOP (magnetic field operate point value) the output is set to OFF.
Figure 9 presents the output waveform of a typical Hall sensor.
BRF
Sensor output
MS30127V2
Generally, the Hall sensor is used in the three-phase motor control. Figure 10 presents the
commutation sequence.
Hall 1
Hall 2
Hall 3
Motor position
0 60 120 180 240 300 360 420 480 540 600 660
MS30126V2
The high-resolution timer was designed specifically to control power conversion systems in
the lighting systems switch mode power supply. Even though it really excels in this role, it
can of course be used in other applications with high-resolution timer requirements.
The HRTIM features up to 10 outputs that can be configured in various coupled and
autonomous modes using five timing units tied to a common master for synchronization
purposes. The synchronization with other timers is also facilitated. The HRTIM is strongly
tied to ADCs and fault inputs for feedback purposes.
For more information about the high-resolution timer, read the reference manual of the
particular MCU line.
Application related information can be found in the following documents:
• “High brightness LED dimming using the STM32F334 discovery kit” (AN4885)
• “Buck-boost converter using the STM32F334 discovery kit” (AN4449)
• “HRTIM cookbook” (AN4539)
Numerous examples are available in the STM32Cube packages of families featuring the
high-resolution timer (STM32F3, STM32G4, STM32H7).
6 Low-power timer
The main difference and advantage of the LPTIM compared to any other timer peripheral in
the STM32 microcontroller family is the ability to continue working even in Stop mode and
trigger events that wake the MCU up from the Stop mode. For a list of Stop modes
supported by each LPTIM instance, refer to the product datasheet. Depending on the
selected clock source, the runtime power consumption can be substantially lower compared
to a general purpose timer. While it can perform a similar job to the general purpose timer,
the focus is put on the task for which it is designed for.
7 Specific applications
8 Revision history
Added:
– STM32U5 Series and STM32WL Series to the document’s scope
– Table 4: Simplified overview of timer availability in
STM32Gx/Hx/Ux/Wx products
Updated:
– Table 1: Applicable products
01-Jun-2021 9
– Table 3: Simplified overview of timer availability in STM32Lx
products
– Notes 2 and 3 on Table 5: Timer features overview
– Section 6: Low-power timer
– Figure 7: Position at X4 resolution and Figure 8: Position at X2
resolution
Updated:
– Table 1: Applicable products
12-Jan-2023 10 – Table 5: Timer features overview
Added:
– Section 2.10: PWM analysis mode
STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and
improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on
ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order
acknowledgement.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or
the design of Purchasers’ products.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. For additional information about ST trademarks, please refer to www.st.com/trademarks. All other
product or service names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.