31. Advanced-control timers (TIM1/TIM8)
31.1 TIM1/TIM8 introduction
The advanced-control timers (TIM1/TIM8) consist of a 16-bit autoreload counter driven by a programmable prescaler.
It may be used for a variety of purposes, including measuring the pulse lengths of input signals (input capture) or generating output waveforms (output compare, PWM, complementary PWM with dead-time insertion).
Pulse lengths and waveform periods can be modulated from a few microseconds to several milliseconds using the timer prescaler and the RCC clock controller prescalers.
The advanced-control (TIM1/TIM8) and general-purpose (TIMy) timers are completely independent, and do not share any resources. They can be synchronized together as described in Section 31.3.35: Timer synchronization.
31.2 TIM1/TIM8 main features
TIM1/TIM8 timer features include:
- • 16-bit up, down, up/down autoreload counter.
- • 16-bit programmable prescaler allowing dividing (also “on the fly”) the counter clock frequency by any factor from 1 to 65536.
- • Seven independent channels for:
- – Input capture (but channels 5, 6 and 7)
- – Output compare
- – PWM generation (edge and center-aligned mode)
- – One-pulse mode output
- • Complementary outputs with programmable dead-time
- • Synchronization circuit to control the timer with external signals and to interconnect several timers together.
- • Repetition counter to update the timer registers only after a given number of cycles of the counter.
- • 2 break inputs to put the timer’s output signals in a safe user selectable configuration.
- • Interrupt/DMA generation on the following events:
- – Update: counter overflow/underflow, counter initialization (by software or internal/external trigger)
- – Trigger event (counter start, stop, initialization, or count by internal/external trigger)
- – Input capture
- – Output compare
- • Incremental encoders, quadrature encoders and hall-sensors support
- • Trigger input for external clock or cycle-by-cycle current management
- • ADC synchronization for jitter-free sampling points
31.3 TIM1/TIM8 functional description
31.3.1 Block diagram
Figure 218. Advanced-control timer block diagram

Notes:
- Reg Preload registers transferred to active registers on UEV event according to control bit
- Interrupt & DMA output
- Event
MSv74194V2
- This feature is not available on all timers, refer to Section 31.3.2: TIM1/TIM8 pins and internal signals.
- See Figure 269: Break and Break2 circuitry overview for details.
31.3.2 TIM1/TIM8 pins and internal signals
The tables in this section summarize the TIM inputs and outputs
Table 281. TIM input/output pins
| Pin name | Signal type | Description |
|---|---|---|
| TIM_CH1 TIM_CH2 TIM_CH3 TIM_CH4 | Input/Output | Timer multi-purpose channels. Each channel can be used for capture, compare or PWM. TIM_CH1 and TIM_CH2 can also be used as external clock (below 1/4 of the tim_ker_ck clock), external trigger and quadrature encoder inputs. TIM_CH1, TIM_CH2 and TIM_CH3 can be used to interface with digital hall effect sensors. |
| TIM_CH1N TIM_CH2N TIM_CH3N TIM_CH4N | Output | Timer complementary outputs, derived from TIM_CHx outputs with the possibility to have deadtime insertion. |
| TIM_ETR | Input | External trigger input. This input can be used as external trigger or as external clock source. This input can receive a clock with a frequency higher than the tim_ker_ck if the tim_etr_in prescaler is used. |
| TIM_BKIN TIM_BKIN2 | Input / Output | Break and Break2 inputs. These inputs can also be configured in bidirectional mode. |
Table 282. TIM internal input/output signals
| Internal signal name | Signal type | Description |
|---|---|---|
| tim_ti1_in[15:0] tim_ti2_in[15:0] tim_ti3_in[15:0] tim_ti4_in[15:0] | Input | Internal timer inputs bus. The tim_ti1_in[15:0] and tim_ti2_in[15:0] inputs can be used for capture or as external clock (below 1/4 of the tim_ker_ck clock) and for quadrature encoder signals. |
| tim_etr[31:0] | Input | External trigger internal input bus. These inputs can be used as trigger, external clock or for hardware cycle-by-cycle pulsewidth control. These inputs can receive clock with a frequency higher than the tim_ker_ck if the tim_etr_in prescaler is used. |
| tim_itr[27:0] | Input | Internal trigger input bus. These inputs can be used for the slave mode controller or as a input clock (below 1/4 of the tim_ker_ck clock). |
| tim_trgo/tim_trgo2 | Output | Internal trigger outputs. These triggers are used by other timers and /or other peripherals. |
Table 282. TIM internal input/output signals (continued)
| Internal signal name | Signal type | Description |
|---|---|---|
| tim_ocx (x = 1 to 4) | Output | Internal output compare signals of channels 1 to 4. These outputs can be used for triggering/synchronizing other internal peripherals. |
| tim_ocxn (x = 1 to 4) | Output | Internal timer complementary outputs, derived from tim_ocx internal outputs with the possibility to have deadtime insertion. |
| tim_ocx (x = 5 to 7) | Output | Internal output compare signals of channels 5 to 7. These outputs can be used for triggering/synchronizing other internal peripherals. |
| tim_ocref_clr[15:0] | Input | Timer tim_ocref_clr input bus. These inputs can be used to clear the tim_ocxref signals, typically for hardware cycle-by-cycle pulsewidth control. |
| tim_brk_cmp[20:1] | Input | Break input for internal signals |
| tim_brk2_cmp[20:1] | Input | Break2 input for internal signals |
| tim_sys_brk[n:0] | Input | System break input. This input gathers the MCU's system level errors. |
| tim_pclk | Input | Timer APB clock |
| tim_ker_ck | Input | Timer kernel clock |
| tim_cc_it | Output | Timer capture/compare interrupt |
| tim_upd_it | Output | Timer update event interrupt |
| tim_brk_terr_ierr_it | Output | Timer break, break2, transition error and index error interrupt |
| tim_trgi_com_dir_idx_it | Output | Timer trigger, commutation, direction and index interrupt |
| tim_cc1_dma tim_cc2_dma tim_cc3_dma tim_cc4_dma | Output | Timer capture / compare 1..4 dma requests |
| tim_upd_dma | Output | Timer update dma request |
| tim_trgi_dma | Output | Timer trigger dma request |
| tim_com_dma | Output | Timer commutation dma request |
Table 283, Table 284, Table 285, and Table 286 list the sources connected to the tim_ti[4:1] input multiplexers.
Table 283. Interconnect to the tim_ti1 input multiplexer| tim_ti1 inputs | Sources | |
|---|---|---|
| TIM1 | TIM8 | |
| tim_ti1_in0 | TIM1_CH1 | TIM8_CH1 |
| tim_ti1_in1 | comp1_out | |
| tim_ti1_in2 | comp2_out | |
| tim_ti1_in[15:2] | Reserved | |
| tim_ti2 inputs | Sources | |
|---|---|---|
| TIM1 | TIM8 | |
| tim_ti2_in0 | TIM1_CH2 | TIM8_CH2 |
| tim_ti2_in[15:1] | Reserved | |
| tim_ti3 inputs | Sources | |
|---|---|---|
| TIM1 | TIM8 | |
| tim_ti3_in0 | TIM1_CH3 | TIM8_CH3 |
| tim_ti3_in[15:1] | Reserved | |
| tim_ti4 inputs | Sources | |
|---|---|---|
| TIM1 | TIM8 | |
| tim_ti4_in0 | TIM1_CH4 | TIM8_CH4 |
| tim_ti4_in[15:1] | Reserved | |
Table 287 lists the internal sources connected to the tim_itr input multiplexer.
Table 287. Internal trigger connection| Timer internal trigger input signal | TIM1 | TIM8 |
|---|---|---|
| tim_itr0 | Reserved | tim1_trgo |
| tim_itr1 | tim1_trgo2 | |
| tim_itr2 | tim2_trgo | |
| tim_itr3 | tim3_trgo | |
| tim_itr4 | tim4_trgo | |
Table 287. Internal trigger connection (continued)
| Timer internal trigger input signal | TIM1 | TIM8 |
|---|---|---|
| tim_itr5 | tim5_trgo | |
| tim_itr6 | tim8_trgo | Reserved |
| tim_itr7 | tim8_trgo2 | |
| tim_itr8 | tim12_trgo | |
| tim_itr9 | tim15_trgo | |
| tim_itr10 | tim16_oc1 | |
| tim_itr11 | tim17_oc1 | |
| tim_itr[27:12] | Reserved | |
Table 288 lists the internal sources connected to the tim_etr input multiplexer.
Table 288. Interconnect to the tim_etr input multiplexer
| Timer external trigger input signal | Timer external trigger signals assignment | |
|---|---|---|
| TIM1 | TIM8 | |
| tim_etr0 | TIM1_ETR | TIM8_ETR |
| tim_etr1 | comp1_out | |
| tim_etr2 | Reserved | |
| tim_etr3 | adc1_awd1 | adc2_awd1 |
| tim_etr4 | adc1_awd2 | adc2_awd2 |
| tim_etr5 | adc1_awd3 | adc2_awd3 |
| tim_etr6 | Reserved | adc3_awd1 |
| tim_etr7 | Reserved | adc3_awd2 |
| tim_etr8 | Reserved | adc3_awd3 |
| tim_etr[15:9] | Reserved | |
Table 289. Interconnect to the tim_bkr_cmp multiplexer
| tim_brk inputs | TIM1 | TIM8 |
|---|---|---|
| TIM_BKIN | TIM1_BKIN pin | TIM8_BKIN pin |
| tim_brk_cmp1 | comp1_out | |
| tim_brk_cmp2 | comp2_out | |
| tim_brk_cmp[4:3] | Reserved | |
| tim_brk_cmp5 | Reserved | TIM1_BKIN |
| tim_brk_cmp6 | TIM8_BKIN | Reserved |
| tim_brk_cmp7 | Reserved | |
| tim_brk inputs | TIM1 | TIM8 |
|---|---|---|
| tim_brk_cmp8 | TIM15_BKIN | |
| tim_brk_cmp9 | TIM16_BKIN | |
| tim_brk_cmp10 | TIM17_BKIN | |
| tim_brk2 inputs | TIM1 | TIM8 |
|---|---|---|
| TIM_BKIN2 | TIM1_BKIN2 pin | TIM8_BKIN2 pin |
| tim_brk2_cmp1 | comp1_out | |
| tim_brk2_cmp2 | comp2_out | |
| tim_brk2_cmp[4:3] | Reserved | |
| tim_brk2_cmp5 | Reserved | TIM1_BKIN2 |
| tim_brk2_cmp6 | TIM8_BKIN2 | Reserved |
| tim_brk2_cmp[10:7] | Reserved | |
Table 291 list the sources connected to the tim_oref_clr multiplexer.
Table 291. Interconnect to tim_oref_clr multiplexer| tim_oref_clr inputs | TIM1 | TIM8 |
|---|---|---|
| tim_oref_clr0 | comp1_out | |
| tim_oref_clr1 | comp2_out | |
| tim_oref_clr[7:2] | Reserved | |
| tim_sys_brk inputs | TIM1/TIM8 | Enable bit in SBS_CFGR2 register |
|---|---|---|
| tim_sys_brk0 | Cortex-M33 LOCKUP | CLL |
| tim_sys_brk1 | SRAM double ECC error | SEL |
| tim_sys_brk2 | Programmable Voltage Detector (PVD) | PVDL |
| tim_sys_brk3 | Non-Volatile memory double ECC error | ECCL |
| tim_sys_brk4 | Clock Security System (CSS) | None (always enabled) |
31.3.3 Time-base unit
The main block of the programmable advanced-control timer is a 16-bit counter with its related autoreload register. The counter can count up, down or both up and down. The counter clock can be divided by a prescaler.
The counter, the autoreload register and the prescaler register can be written or read by software, even when the counter is running.
The time-base unit includes:
- • Counter register (TIM_CNT)
- • Prescaler register (TIM_PSC)
- • Autoreload register (TIM_ARR)
- • Repetition counter register (TIM_RCR)
The autoreload register is preloaded. Writing to or reading from the autoreload register accesses the preload register. The content of the preload register are transferred into the shadow register permanently or at each update event (UEV), depending on the autoreload preload enable bit (ARPE) in TIM_CR1 register. The update event is sent when the counter reaches the overflow (or underflow when downcounting) and if the UDIS bit equals 0 in the TIM_CR1 register. It can also be generated by software. The generation of the update event is described in detail for each configuration.
Note: An update overrun status bit (UIOVRF in TIM_SR register) indicates that an update request occurred while an update interrupt is pending (update interrupt flag set). This bit is useful when debugging closed loop applications, to indicate that:
- - the update interrupt service routine is too long with respect to the interval between consecutive update events
- - the update interrupt service routine was served too late with respect to the subsequent update event
The counter is clocked by the prescaler output tim_cnt_ck, which is enabled only when the counter enable bit (CEN) in TIM_CR1 register is set (refer also to the slave mode controller description to get more details on counter enabling).
Note: The counter starts counting 1 clock cycle after setting the CEN bit in the TIM_CR1 register.
Prescaler description
The prescaler divides the counter clock frequency by any factor from 1 to 65536. It is based on a 16-bit counter controlled through a 16-bit register (in the TIM_PSC register). It can be changed on the fly as this control register is buffered. The new prescaler ratio is taken into account at the next update event.
Figure 219 and Figure 220 give some examples of the counter behavior when the prescaler ratio is changed on the fly.
Figure 219. Counter timing diagram with prescaler division change from 1 to 2

MSv80085V1
Figure 220. Counter timing diagram with prescaler division change from 1 to 4

MSv80086V1
31.3.4 Counter modes
Upcounting mode
In upcounting mode, the counter counts from 0 to the autoreload value (content of the TIM_ARR register), then restarts from 0 and generates a counter overflow event.
If the repetition counter is used, the update event (UEV) is generated after upcounting is repeated for the number of times programmed in the repetition counter register (TIM_RCR) + 1. Else the update event is generated at each counter overflow.
Setting the UG bit in the TIM_EGR register (by software or by using the slave mode controller) also generates an update event.
The UEV event can be disabled by software by setting the UDIS bit in the TIM_CR1 register. This is to avoid updating the shadow registers while writing new values in the preload registers. Then no update event occurs until the UDIS bit has been written to 0. However, the counter restarts from 0, as well as the counter of the prescaler (but the prescale rate does not change). In addition, if the URS bit (update request selection) in TIM_CR1 register is set, setting the UG bit generates an update event UEV but without setting the UIF flag (thus no interrupt or DMA request is sent). This is to avoid generating both update and capture interrupts when clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in TIM_SR register) is set (depending on the URS bit):
- • The repetition counter is reloaded with the content of TIM_RCR register,
- • The autoreload shadow register is updated with the preload value (TIM_ARR),
- • The buffer of the prescaler is reloaded with the preload value (content of the TIM_PSC register).
The following figures show some examples of the counter behavior for different clock frequencies when TIM_ARR = 0x36.
Figure 221. Counter timing diagram, internal clock divided by 1

This timing diagram illustrates the operation of a counter when the internal clock is divided by 1. The tim_psc_ck signal is a continuous clock. The CEN signal is an enable signal that starts high and then goes low. The tim_cnt_ck signal is a clock derived from tim_psc_ck with a division factor of 1, meaning it has the same frequency. The Counter register shows the count values: 31, 32, 33, 34, 35, 36, 00, 01, 02, 03, 04, 05, 06, 07. The Counter overflow signal is a pulse that occurs when the counter reaches 00. The Update event (UEV) signal is a pulse that occurs when the counter reaches 00. The Update interrupt flag (UIF) signal is a pulse that occurs when the counter reaches 00.
MSv50997V1
Figure 222. Counter timing diagram, internal clock divided by 2

This timing diagram illustrates the operation of a counter when the internal clock is divided by 2. The tim_psc_ck signal is a continuous clock. The CEN signal is an enable signal that starts high and then goes low. The tim_cnt_ck signal is a clock derived from tim_psc_ck with a division factor of 2, meaning its frequency is half of tim_psc_ck. The Counter register shows the count values: 0034, 0035, 0036, 0000, 0001, 0002, 0003. The Counter overflow signal is a pulse that occurs when the counter reaches 00. The Update event (UEV) signal is a pulse that occurs when the counter reaches 00. The Update interrupt flag (UIF) signal is a pulse that occurs when the counter reaches 00.
MSv62300V1
Figure 223. Counter timing diagram, internal clock divided by 4

The diagram illustrates the timing of a counter when the internal clock is divided by 4. The tim_psc_ck signal is a continuous square wave. The CEN signal is a low-to-high transition that enables the counter. The tim_cnt_ck signal is a square wave with a period four times that of tim_psc_ck. The Counter register shows the count values: 0035, 0036, 0000, and 0001. The Counter overflow signal is a high pulse when the counter reaches its maximum value (0035) and rolls over to 0000. The Update event (UEV) signal is a high pulse at the same time as the overflow. The Update interrupt flag (UIF) signal is a high pulse that remains high until cleared.
MSv62301V1
Figure 224. Counter timing diagram, internal clock divided by N

The diagram illustrates the timing of a counter when the internal clock is divided by N. The tim_psc_ck signal is a continuous square wave. The tim_cnt_ck signal is a square wave with a period N times that of tim_psc_ck. The Counter register shows the count values: 1F, 20, and 00. The Counter overflow signal is a high pulse when the counter reaches its maximum value (1F) and rolls over to 00. The Update event (UEV) signal is a high pulse at the same time as the overflow. The Update interrupt flag (UIF) signal is a high pulse that remains high until cleared.
MSv62302V1
Figure 225. Counter timing diagram, update event when ARPE = 0
(TIM_ARR not preloaded)

The diagram illustrates the timing of an update event in a timer when the auto-reload preload enable (ARPE) is 0 and the auto-reload register (TIM_ARR) is not preloaded. The counter register is 32 bits wide, with bits 31 down to 00 shown. The counter overflow occurs when the counter reaches 36 (0x24), which is the auto-reload value. The update event (UEV) is generated on the rising edge of the counter overflow. The update interrupt flag (UIF) is set on the rising edge of the UEV. The auto-reload preload register is shown as FF (0xFF), which is the value loaded into the counter register when it reaches 36.
| Signal | Value / State |
|---|---|
| tim_psc_ck | Periodic clock signal |
| CEN | Counter enable signal |
| tim_cnt_ck | Counter clock signal |
| Counter register | 31 32 33 34 35 36 00 01 02 03 04 05 06 07 |
| Counter overflow | High pulse at counter value 36 |
| Update event (UEV) | High pulse on rising edge of counter overflow |
| Update interrupt flag (UIF) | High pulse on rising edge of UEV |
| Auto-reload preload register | FF 36 |
Write a new value in TIM_ARR
MSv80087V1
Figure 226. Counter timing diagram, update event when ARPE = 1
(TIM_ARR preloaded)

The diagram illustrates the timing of various signals during a counter update event when ARPE = 1 and TIM_ARR is preloaded. The signals shown are:
- tim_psc_ck: Prescaler clock signal.
- CEN: Counter enable signal, which starts the counter.
- tim_cnt_ck: Counter clock signal, derived from the prescaler clock.
- Counter register: Shows the counter value decreasing from F0 to F5, then wrapping around to 00 and continuing to 07. A vertical dashed line marks the update event at the transition from F5 to 00.
- Counter overflow: A pulse occurs at the update event.
- Update event (UEV): A pulse occurs at the update event.
- Update interrupt flag (UIF): A pulse occurs at the update event.
- Auto-reload preload register: Shows the value F5 being loaded into the register, which then updates to 36.
- Auto-reload shadow register: Shows the value F5 being loaded into the register, which then updates to 36.
A note at the bottom left indicates "Write a new value in TIM_ARR". The diagram is labeled "MSv80088V1" in the bottom right corner.
Downcounting mode
In downcounting mode, the counter counts from the autoreload value (content of the TIM_ARR register) down to 0, then restarts from the autoreload value and generates a counter underflow event.
If the repetition counter is used, the update event (UEV) is generated after downcounting is repeated for the number of times programmed in the repetition counter register (TIM_RCR) + 1. Else the update event is generated at each counter underflow.
Setting the UG bit in the TIM_EGR register (by software or by using the slave mode controller) also generates an update event.
The UEV update event can be disabled by software by setting the UDIS bit in TIM_CR1 register. This is to avoid updating the shadow registers while writing new values in the preload registers. Then no update event occurs until UDIS bit has been written to 0. However, the counter restarts from the current autoreload value, whereas the counter of the prescaler restarts from 0 (but the prescale rate doesn't change).
In addition, if the URS bit (update request selection) in TIM_CR1 register is set, setting the UG bit generates an update event UEV but without setting the UIF flag (thus no interrupt or DMA request is sent). This is to avoid generating both update and capture interrupts when clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in TIM_SR register) is set (depending on the URS bit):
- • The repetition counter is reloaded with the content of TIM_RCR register.
- • The buffer of the prescaler is reloaded with the preload value (content of the TIM_PSC register).
- • The autoreload active register is updated with the preload value (content of the TIM_ARR register). Note that the autoreload is updated before the counter is reloaded, so that the next period is the expected one.
The following figures show some examples of the counter behavior for different clock frequencies when TIM_ARR = 0x36.
Figure 227. Counter timing diagram, internal clock divided by 1

The diagram illustrates the timing of a counter with an internal clock divided by 1. The signals shown are:
- tim_psc_ck: Prescaler clock signal.
- CEN: Counter enable signal, which is high for the duration of the counter operation.
- tim_cnt_ck: Counter clock signal, derived from the prescaler clock.
- Counter register: Shows the sequence of values in the counter register. It starts at 05, decrements to 00, and then reloads with 36. The values are: 05, 04, 03, 02, 01, 00, 36, 35, 34, 33, 32, 31, 30, 2F.
- Counter underflow (cnt_udf): A pulse that occurs when the counter reaches 00 and reloads.
- Update event (UEV): A pulse that occurs when the counter reaches 00 and reloads.
- Update interrupt flag (UIF): A pulse that occurs when the update event occurs.
The diagram shows that the counter register is updated before the counter is reloaded, ensuring that the next period is the expected one. The update event (UEV) and update interrupt flag (UIF) are generated when the counter reaches 00 and reloads.
MSv62305V1
Figure 228. Counter timing diagram, internal clock divided by 2

This timing diagram illustrates the operation of a counter when the internal clock is divided by 2. The prescaler clock (tim_psc_ck) is a continuous square wave. The counter enable signal (CEN) is active low, starting low and then going high. The counter clock (tim_cnt_ck) is derived from tim_psc_ck and is active low, with a period twice that of tim_psc_ck. The counter register shows a sequence of values: 0002, 0001, 0000, 0036, 0035, 0034, and 0033. A counter underflow occurs when the register reaches 0000. The update event (UEV) is a pulse that occurs on the falling edge of the counter clock following the underflow. The update interrupt flag (UIF) is set high on the falling edge of the counter clock following the underflow.
MSv62306V1
Figure 229. Counter timing diagram, internal clock divided by 4

This timing diagram illustrates the operation of a counter when the internal clock is divided by 4. The prescaler clock (tim_psc_ck) is a continuous square wave. The counter enable signal (CEN) is active low, starting low and then going high. The counter clock (tim_cnt_ck) is derived from tim_psc_ck and is active low, with a period four times that of tim_psc_ck. The counter register shows a sequence of values: 0001, 0000, 0000, and 0001. A counter underflow occurs when the register reaches 0000. The update event (UEV) is a pulse that occurs on the falling edge of the counter clock following the underflow. The update interrupt flag (UIF) is set high on the falling edge of the counter clock following the underflow.
MSv62307V1
Figure 230. Counter timing diagram, internal clock divided by N

The diagram illustrates the timing of a counter when the internal clock is divided by N. It shows two cycles of operation. In the first cycle, the counter register starts at 20 and counts up to 1F. In the second cycle, it starts at 00 and counts up to 36. The counter underflow signal is active low, indicating the start of a new cycle. The Update event (UEV) and Update interrupt flag (UIF) are generated at the end of each cycle.
MSv62308V1
Figure 231. Counter timing diagram, update event when repetition counter is not used

The diagram illustrates the timing of a counter when the repetition counter is not used. It shows the counter register counting from 05 to 00, then wrapping around to 36 and continuing up to 2F. The counter underflow signal is active low, indicating the start of a new cycle. The Update event (UEV) and Update interrupt flag (UIF) are generated at the end of each cycle. The Auto-reload preload register is shown with a value of FF, which is written to the counter register.
MSv80089V1
Center-aligned mode (up/down counting)
In center-aligned mode, the counter counts from 0 to the autoreload value (content of the TIM_ARR register) – 1, generates a counter overflow event, then counts from the
autoreload value down to 1 and generates a counter underflow event. Then it restarts counting from 0.
Center-aligned mode is active when the CMS bits in TIM_CR1 register are not equal to 00. The Output compare interrupt flag of channels configured in output is set when: the counter counts down (Center aligned mode 1, CMS = 01), the counter counts up (Center aligned mode 2, CMS = 10) the counter counts up and down (Center aligned mode 3, CMS = 11).
In this mode, the DIR direction bit in the TIM_CR1 register cannot be written. It is updated by hardware and gives the current direction of the counter.
The update event can be generated at each counter overflow and at each counter underflow or by setting the UG bit in the TIM_EGR register (by software or by using the slave mode controller) also generates an update event. In this case, the counter restarts counting from 0, as well as the counter of the prescaler.
The UEV update event can be disabled by software by setting the UDIS bit in the TIM_CR1 register. This is to avoid updating the shadow registers while writing new values in the preload registers. Then no update event occurs until UDIS bit has been written to 0. However, the counter continues counting up and down, based on the current autoreload value.
In addition, if the URS bit (update request selection) in TIM_CR1 register is set, setting the UG bit generates an UEV update event but without setting the UIF flag (thus no interrupt or DMA request is sent). This is to avoid generating both update and capture interrupts when clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in TIM_SR register) is set (depending on the URS bit):
- • The repetition counter is reloaded with the content of TIM_RCR register
- • The buffer of the prescaler is reloaded with the preload value (content of the TIM_PSC register)
- • The autoreload active register is updated with the preload value (content of the TIM_ARR register). Note that if the update source is a counter overflow, the autoreload is updated before the counter is reloaded, so that the next period is the expected one (the counter is loaded with the new value).
The following figures show some examples of the counter behavior for different clock frequencies.
Figure 232. Counter timing diagram, internal clock divided by 1, TIM_ARR = 0x6

This timing diagram illustrates the operation of a counter when the internal clock is divided by 1 and the auto-reload register (TIM_ARR) is set to 0x6. The diagram shows the following signals over time:
- tim_psc_ck: The prescaler clock, shown as a continuous square wave.
- CEN: The counter enable signal, which is high for the duration of the counter operation.
- tim_cnt_ck: The counter clock, which is derived from the prescaler clock. In this mode (division by 1), it has the same frequency as the prescaler clock.
- Counter register: Shows the sequence of values in the counter register. It starts at 04, counts down to 00, then wraps around and counts up to 06, then counts down again to 03. The values are: 04, 03, 02, 01, 00, 01, 02, 03, 04, 05, 06, 05, 04, 03.
- Counter underflow: A pulse occurs when the counter reaches 00.
- Counter overflow: A pulse occurs when the counter reaches 06.
- Update event (UEV): Pulses occur at the end of each counter cycle, triggered by either an underflow or an overflow.
- Update interrupt flag (UIF): A pulse occurs when an update event is detected.
MSv62310V1
- 1. Here, center-aligned mode 1 is used (for more details refer to Section 31.6: TIM1/TIM8 registers).
Figure 233. Counter timing diagram, internal clock divided by 2

This timing diagram illustrates the operation of a counter when the internal clock is divided by 2. The diagram shows the following signals over time:
- tim_psc_ck: The prescaler clock, shown as a continuous square wave.
- CEN: The counter enable signal, which is high for the duration of the counter operation.
- tim_cnt_ck: The counter clock, which is derived from the prescaler clock. In this mode (division by 2), its frequency is half that of the prescaler clock.
- Counter register: Shows the sequence of values in the counter register. It starts at 0003, counts down to 0000, then wraps around and counts up to 0003. The values are: 0003, 0002, 0001, 0000, 0001, 0002, 0003.
- Counter underflow: A pulse occurs when the counter reaches 0000.
- Update event (UEV): A pulse occurs at the end of each counter cycle, triggered by an underflow.
- Update interrupt flag (UIF): A pulse occurs when an update event is detected.
MSv62311V1
Figure 234. Counter timing diagram, internal clock divided by 4, TIM_ARR = 0x36

The diagram shows the following signals over time:
- tim_psc_ck: A continuous square wave.
- CEN: A low-to-high transition that enables the counter.
- tim_cnt_ck: A clock signal derived from tim_psc_ck, with a period four times longer.
- Counter register: Shows the counter value increasing from 0034 to 0035, then 0036, and finally wrapping back to 0035.
- Counter overflow: A pulse occurs when the counter reaches its limit (0036) and wraps.
- Update event (UEV): A pulse occurs on the rising edge of the counter overflow.
- Update interrupt flag (UIF): A pulse occurs on the rising edge of the update event.
Note: Here, center_aligned mode 2 or 3 is updated with an UIF on overflow
MSv62312V1
Figure 235. Counter timing diagram, internal clock divided by N

The diagram shows the following signals over time:
- tim_psc_ck: A continuous square wave.
- tim_cnt_ck: A clock signal derived from tim_psc_ck, with a period N times longer.
- Counter register: Shows the counter value decreasing from 20 to 1F, then wrapping back to 01 and reaching 00.
- Counter underflow: A pulse occurs when the counter reaches 00 and wraps.
- Update event (UEV): A pulse occurs on the rising edge of the counter underflow.
- Update interrupt flag (UIF): A pulse occurs on the rising edge of the update event.
MSv62313V1
Figure 236. Counter timing diagram, update event with ARPE = 1 (counter underflow)

The diagram illustrates the timing of a counter underflow event when ARPE is set to 1. It shows the following signals and registers over time:
- tim_psc_ck: The prescaler clock, shown as a continuous square wave.
- CEN: The counter enable signal, which is high during the active period.
- tim_cnt_ck: The counter clock, derived from tim_psc_ck when CEN is high.
- Counter register: Shows the counter value decreasing from 06 to 00, then wrapping to 01. The values are shown in boxes: 06, 05, 04, 03, 02, 01, 00, 01, 02, 03, 04, 05, 06, 07.
- Counter underflow: A pulse occurs when the counter reaches 00.
- Update event (UEV): A pulse occurs immediately after the counter underflow.
- Update interrupt flag (UIF): A pulse occurs immediately after the update event.
- Auto-reload preload register: Shows a value 'FD' being written to the register. The value '36' is shown after the write.
- Auto-reload active register: Shows the value 'FD' being loaded into the active register. The value '36' is shown after the load.
A vertical dashed line indicates the point where a new value is written to the TIM_ARR register. The counter register value is 05 at this point. The auto-reload preload register is updated to 36, and the auto-reload active register is updated to 36.
MSv80090V1
Figure 237. Counter timing diagram, Update event with ARPE = 1 (counter overflow)

The diagram illustrates the timing of an update event (UEV) caused by a counter overflow when ARPE = 1. The signals shown are:
- tim_psc_ck: Prescaler clock signal.
- CEN: Counter enable signal, which is high during the active period.
- tim_cnt_ck: Counter clock signal, derived from the prescaler clock.
- Counter register: Shows the counter value rolling over from F7 to F8, F9, FA, FB, FC, and then overflowing to 36. The values are shown in a sequence of boxes.
- Counter overflow: A pulse that occurs when the counter overflows from FC to 36.
- Update event (UEV): A pulse that occurs immediately after the counter overflow.
- Update interrupt flag (UIF): A pulse that occurs immediately after the update event.
- Auto-reload preload register: Shows the preload value (FD) being loaded into the register. A note indicates "Write a new value in TIM_ARR" at this point.
- Auto-reload active register: Shows the active reload value (FD) being loaded into the register.
MSv80091V1
31.3.5 Repetition counter
Section 31.3.3: Time-base unit describes how the update event (UEV) is generated with respect to the counter overflows/underflows. It is actually generated only when the repetition counter has reached zero. This can be useful when generating PWM signals.
This means that data are transferred from the preload registers to the shadow registers (TIM_ARR autoreload register, TIM_PSC prescaler register, but also TIM_CCRx capture/compare registers in compare mode) every N+1 counter overflows or underflows, where N is the value in the TIM_RCR repetition counter register.
The repetition counter is decremented:
- • At each counter overflow in upcounting mode,
- • At each counter underflow in downcounting mode,
- • At each counter overflow and at each counter underflow in center-aligned mode. Although this limits the maximum number of repetition to 32768 PWM cycles, it makes it possible to update the duty cycle twice per PWM period. When refreshing compare registers only once per PWM period in center-aligned mode, maximum resolution is \(2xT_{ck}\), due to the symmetry of the pattern.
The repetition counter is an autoreload type; the repetition rate is maintained as defined by the TIM_RCR register value (refer to Figure 238). When the update event is generated by software (by setting the UG bit in TIM_EGR register) or by hardware through the slave mode controller, it occurs immediately whatever the value of the repetition counter is and the repetition counter is reloaded with the content of the TIM_RCR register.
For example, for RCR = 3, the UEV is generated each 4th overflow or underflow event depending on when the RCR was written.
Figure 238. Update rate examples depending on mode and TIM_RCR register settings

Counter-aligned mode
Edge-aligned mode
Upcounting
Downcounting
TIM_CNT
TIM_RCR = 0
TIM_RCR = 1
TIM_RCR = 2
TIM_RCR = 3
TIM_RCR = 3 and re-synchronization
UEV
(by SW)
UEV → Update event: Preload registers transferred to active registers and update interrupt generated
Update Event if the repetition counter underflow occurs when the counter is equal to the auto-reload value
MSv80092V1
31.3.6 External trigger input
The timer features an external trigger input tim_etr_in. It can be used as:
- external clock (external clock mode 2, see Section 31.3.7)
- trigger for the slave mode (see Section 31.3.35)
- PWM reset input for cycle-by-cycle current regulation (see Section 31.3.9)
Figure 239 below describes the tim_etr_in input conditioning. The input polarity is defined with the ETP bit in TIM_SMCR register. The trigger frequency can be decreased with the prescalers programmed by the ETPS[1:0] and SETPS[3:0] bitfields and digitally filtered as per the ETF[3:0] bitfield. The resulting signal (tim_etrf) is available for three purposes: as an
In Center aligned mode, for odd values of RCR, the update event occurs either on the overflow or on the underflow depending on when the RCR register was written and when the counter was launched: if the RCR was written before launching the counter, the UEV occurs on the underflow. If the RCR was written after launching the counter, the UEV occurs on the overflow.
RM0522 Advanced-control timers (TIM1/TIM8)
RM0522 Rev 1 977/2572
external clock, to condition the output (typically to reset a PWM output for a current limitation), and as a trigger for the Slave mode controller.
Figure 239. External trigger input block
![Block diagram of the External trigger input block. The diagram shows the flow from external inputs through various registers and prescalers to the final output. Inputs include TIM_ETR (tim_etr0) and tim_etr[31:1]. These pass through a multiplexer controlled by TIM_AF1[18:14] to produce tim_etr_in. This signal is then split: one path goes through an inverter to the Asynchronous prescaler (division by 1, 2, 4, or 8), controlled by TIM_SMCR[ETP] and TIM_SMCR[ETPS[1:0]]. The output is tim_etrp. The other path goes through a Digital filter (controlled by TIM_SMCR[ETF[3:0]]) and then a Synchronous prescaler (division by 1, 2, 3, ..., 15), controlled by TIM_SMCR[SETPS[3:0]]. The final output is tim_etr, which is sent to the Output mode controller, CK_PSC circuitry, and Slave mode controller. A feedback signal f_DTS2 is also shown.](/RM0522-STM32C5/ee963e19a2d944e48e795c8e0a2d76b3_img.jpg)
The external trigger input block features 2 prescalers with different functionalities:
- – An asynchronous prescaler (division by 1, 2, 4 or 8), able to process tim_etr_in signals with frequencies above tim_ker_ck
- – A linear synchronous prescaler (division by 1,2,3,...15), only able to operate with tim_etrp signal frequencies below tim_ker_ck/3
Note: When tim_etr is used as PWM reset input for cycle-by-cycle current regulation (see Section 31.3.23), SETPS[3:0] must be set to 0 (no prescaling).
Note: The SETPS[3:0] bitfield is always preloaded: a new value will become active only once an update event has occurred.
The tim_etr_in input comes from multiple sources: input pins (default configuration), or internal sources. The selection is done with the ETRSEL[4:0] bitfield in the TIM_AF1 register.
Refer to Section 31.3.2: TIM1/TIM8 pins and internal signals for the list of sources connected to the etr_in input in the product.
31.3.7 Clock selection
The counter clock can be provided by the following clock sources:
- • Internal clock (tim_ker_ck)
- • External clock mode1: external input pin (tim_ti1 or tim_ti2)
- • External clock mode2: external trigger input (tim_etr_in)
- • Encoder mode
Internal clock source (tim_ker_ck)
If the slave mode controller is disabled (SMS = 000), then the CEN, DIR (in the TIM_CR1 register) and UG bits (in the TIM_EGR register) are actual control bits and can be changed only by software (except UG which remains cleared automatically). As soon as the CEN bit is written to 1, the prescaler is clocked by the internal clock tim_ker_ck.
Figure 240 shows the behavior of the control circuit and the upcounter in normal mode, without prescaler.
Figure 240. Control circuit in normal mode, internal clock divided by 1

MSv62317V2
External clock source mode 1
This mode is selected when SMS = 00111 in the TIM_SMCR register. The counter can count at each rising or falling edge on a selected input.
Figure 241. tim_ti2 external clock connection example
![Block diagram of tim_ti2 external clock connection showing inputs tim_ti2_in0 and tim_ti2_in[15:1] selected by TI2SEL[3:0], filtered by Filter ICF[3:0], detected by Edge detector, selected by CC2P (0 for tim_ti2_rising, 1 for tim_ti2_falling) into multiplexer TS[4:0] in TIM_SMCR, which routes to mode selection (Encoder mode, External clock mode 1 via tim_trgi, External clock mode 2 via tim_etrf, Internal clock mode via tim_ker_ck) controlled by ECE and SMS[2:0] to produce tim_psc_ck.](/RM0522-STM32C5/912b1c5e43b99ef68aeb3ce6438796bc_img.jpg)
MSv80094V1
1. Codes ranging from 01000 to 11111 are reserved.
For example, to configure the upcounter to count in response to a rising edge on the tim_ti2 input, use the following procedure:
- 1. Configure channel 2 to detect rising edges on the
tim_ti2input by writingCC2S = 01in theTIM_CCMR1register. - 2. Configure the input filter duration by writing the
IC2F[3:0]bits in theTIM_CCMR1register (if no filter is needed, keepIC2F = 0000). - 3. Select rising edge polarity by writing
CC2P = 0andCC2NP = 0in theTIM_CCERregister. - 4. Configure the timer in external clock mode 1 by writing
SMS = 111in theTIM_SMCRregister. - 5. Select
tim_ti2as the trigger input source by writingTS = 00110in theTIM_SMCRregister. - 6. Enable the counter by writing
CEN = 1in theTIM_CR1register.
Note: The capture prescaler is not used for triggering, it is not necessary to configure it.
When a rising edge occurs on tim_ti2, the counter counts once and the TIF flag is set.
The delay between the rising edge on tim_ti2 and the actual clock of the counter is due to the resynchronization circuit on tim_ti2 input.
Figure 242. Control circuit in external clock mode 1

The diagram illustrates the control circuit in external clock mode 1. It shows the following signals over time:
- tim_ti2: A square wave input signal.
- CEN: A control signal that is high, enabling the counter.
- tim_cnt_ck, tim_psc_ck: The counter clock signal, which is a pulse generated on the rising edge of
tim_ti2. - Counter register: Shows the counter value increasing from 34 to 35 to 36 at each rising edge of
tim_ti2. - TIF: The Timer Interrupt Flag, which is set high on each rising edge of
tim_ti2.
Arrows indicate that writing TIF=0 clears the flag. The diagram is labeled MSv62319V1 in the bottom right corner.
External clock source mode 2
This mode is selected by writing ECE = 1 in the TIM_SMCR register.
The counter counts at each rising or falling edge on the external trigger input tim_etr_in.
The Figure 243 gives an overview of the external trigger input block.
Figure 243. External trigger input block
![Block diagram of the External trigger input block for TIM1/TIM8 showing inputs TIM_ETR and tim_etr[31:1], multiplexed by TIM_AF1[18:14] into tim_etr_in, with polarity ETP, Asynchronous Prescaler (/1, /2, /4, /8 controlled by ETPS[1:0]), Digital filter (fDTS, ETF[3:0]), Synchronous prescaler (SETPS[3:0]), and clock multiplexer selecting Encoder mode, External clock mode 1, External clock mode 2, or Internal clock mode outputting tim_psc_ck.](/RM0522-STM32C5/3728f719589a5593ec0ae1a51b64eb62_img.jpg)
MSv80095V1
- 1. Refer to Section 31.3.2: TIM1/TIM8 pins and internal signals.
For example, to configure the upcounter to count each 2 rising edges on tim_etr_in, use the following procedure:
- 1. As no filter is needed in this example, write ETF[3:0] = 0000 in the TIM_SMCR register.
- 2. Set the prescaler by writing ETPS[1:0] = 01 and SETPS[3:0] = 0 in the TIM_SMCR register
- 3. Select rising edge detection on the tim_etr_in input by writing ETP = 0 in the TIM_SMCR register
- 4. Enable external clock mode 2 by writing ECE = 1 in the TIM_SMCR register.
- 5. Enable the counter by writing CEN = 1 in the TIM_CR1 register.
The counter counts once each 2 tim_etr_in rising edges.
The delay between the rising edge on tim_etr_in and the actual clock of the counter is due to the resynchronization circuit on the tim_etrp signal. As a consequence, the maximum frequency which can be correctly captured by the counter is at most \(\frac{1}{4}\) of tim_ker_ck frequency. When the ETRP signal is faster, the user must apply a division of the external signal by a proper ETPS prescaler setting.
Figure 244. Control circuit in external clock mode 2

31.3.8 Capture/compare channels
Each capture/compare channel is built around a capture/compare register (including a shadow register), an input stage for capture (with digital filter, multiplexing, and prescaler, except for channels 5 and 6) and an output stage (with comparator and output control).
Figure 245 to Figure 248 give an overview of one capture/compare channel.
The input stage samples the corresponding tim_tix input to generate a filtered signal tim_tixf. Then, an edge detector with polarity selection generates a signal (tim_tixfpy) which can be used as trigger input by the slave mode controller or as the capture command. It is prescaled before the capture register (ICxPS).
Figure 245. Capture/compare channel (example: channel 1 input stage)
![Figure 245: Block diagram of capture/compare channel (example: channel 1 input stage). Shows TIM_TISEL selecting tim_ti1_in inputs to the filter downcounter, edge detector, polarity selection multiplexer, XOR gate for tim_ti1f_ed, channel 2 inputs, trigger controller inputs, multiplexer controlled by CC1S[1:0], and Divider (/1, /2, /4, /8) controlled by ICPS[1:0] and CC1E, yielding tim_ic1f. Reference: MSv80096V1.](/RM0522-STM32C5/885fbca0f7a0892c1c9782b69f4b723a_img.jpg)
The output stage generates an intermediate waveform which is then used for reference: tim_ocxref (active high). The polarity acts at the end of the chain.
Figure 246. Capture/compare channel 1 main circuit

The diagram illustrates the main circuit for Capture/compare channel 1. It is divided into three main sections: Input mode, Output mode, and a central control section.
Input mode: This section shows the logic for capturing input signals. It includes inputs CC1S[1], CC1S[0], IC1PS, CC1E, and CC1G (from TIM_EGR). These inputs pass through a series of OR and AND gates to trigger a 'Capture' event, which transfers data from the 'compare shadow register' to the 'Capture/compare preload register'.
Output mode: This section shows the logic for generating output signals. It includes outputs CC1S[1], CC1S[0], OC1PE (from TIM_CCMR1), and UEV (from the time base unit). These signals pass through a series of OR and AND gates to trigger a 'Compare transfer' event, which transfers data from the 'Capture/compare preload register' to the 'compare shadow register'.
Central control section: This section contains the 'APB Bus', 'MCU-peripheral interface', 'Capture/compare preload register', 'compare shadow register', and 'Counter'. The 'APB Bus' and 'MCU-peripheral interface' are connected via a 16/32-bit bus. The 'Capture/compare preload register' and 'compare shadow register' are connected to the 'Counter'. The 'Counter' output is fed into a 'Comparator' block, which produces two signals: CNT > CCR1 and CNT = CCR1.
MSv80097V1
Figure 247. Output stage of capture/compare channel (channel 1, idem ch. 2, 3 and 4)

1. tim_ocxref, where x is the rank of the complementary channel
Figure 248. Output stage of capture/compare channel (channel 5, idem ch. 6 and 7)

1. Not available externally.
The capture/compare block is made of one preload register and one shadow register. Write and read always access the preload register.
In capture mode, captures are actually done in the shadow register, which is copied into the preload register.
In compare mode, the content of the preload register is copied into the shadow register which is compared to the counter.
31.3.9 Input capture mode
In Input capture mode, the capture/compare registers (TIM_CCRx) are used to latch the value of the counter after a transition detected by the corresponding ICx signal. When a capture occurs, the corresponding CCXIF flag (TIM_SR register) is set and an interrupt or a DMA request can be sent if they are enabled. If a capture occurs while the CCxIF flag was already high, then the overcapture flag CCxOF (TIM_SR register) is set. CCxIF can be cleared by software by writing it to 0 or by reading the captured data stored in the TIM_CCRx register. CCxOF is cleared when it is written with 0.
The following example shows how to capture the counter value in TIM_CCR1 when tim_ti1 input rises. To do this, use the following procedure:
- • Select the active input: TIM_CCR1 must be linked to the tim_ti1 input, so write the CC1S bits to 01 in the TIM_CCMR1 register. As soon as CC1S becomes different from 00, the channel is configured in input, and the TIM_CCR1 register becomes read-only.
- • Program the appropriate input filter duration in relation with the signal connected to the timer (when the input is one of the tim_tix (ICxF bits in the TIM_CCMRx register). Let's imagine that, when toggling, the input signal is not stable during at most five internal clock cycles. We must program a filter duration longer than these five clock cycles. We can validate a transition on tim_ti1 when eight consecutive samples with the new level have been detected (sampled at \(f_{DTS2}\) frequency). Then write IC1F bits to 0011 in the TIM_CCMR1 register.
- • Select the edge of the active transition on the tim_ti1 channel by writing CC1P and CC1NP bits to 0 in the TIM_CCER register (rising edge in this case).
- • Program the input prescaler. In our example, we wish the capture to be performed at each valid transition, so the prescaler is disabled (write IC1PS bits to 00 in the TIM_CCMR1 register).
- • Enable capture from the counter into the capture register by setting the CC1E bit in the TIM_CCER register.
- • If needed, enable the related interrupt request by setting the CC1IE bit in the TIM_DIER register, and/or the DMA request by setting the CC1DE bit in the TIM_DIER register.
When an input capture occurs:
- • The TIM_CCR1 register gets the value of the counter on the active transition.
- • CC1IF flag is set (interrupt flag). CC1OF is also set if at least two consecutive captures occurred whereas the flag was not cleared.
- • An interrupt is generated depending on the CC1IE bit.
- • A DMA request is generated depending on the CC1DE bit.
In order to handle the overcapture, it is recommended to read the data before the overcapture flag. This is to avoid missing an overcapture which may happen after reading the flag and before reading the data.
Note: IC interrupt and/or DMA requests can be generated by software by setting the corresponding CCxG bit in the TIM_EGR register.
31.3.10 PWM input mode
This mode is used to measure both the period and the duty cycle of a PWM signal connected to single tim_tix input:
- • The TIM_CCR1 register holds the period value (interval between two consecutive rising edges).
- • The TIM_CCR2 register holds the pulsewidth (interval between two consecutive rising and falling edges).
This mode is a particular case of input capture mode. The set-up procedure is similar with the following differences:
- • Two ICx signals are mapped on the same tim_tixfp1 input.
- • These two ICx signals are active on edges with opposite polarity.
- • One of the two tim_tixfp signals is selected as trigger input and the slave mode controller is configured in reset mode.
The period and the pulsewidth of a PWM signal applied on tim_ti1 can be measured using the following procedure:
- • Select the active input for TIM_CCR1: write the CC1S bits to 01 in the TIM_CCMR1 register (tim_ti1 selected).
- • Select the active polarity for tim_ti1fp1 (used both for capture in TIM_CCR1 and counter clear): write the CC1P and CC1NP bits to 0 (active on rising edge).
- • Select the active input for TIM_CCR2: write the CC2S bits to 10 in the TIM_CCMR1 register (tim_ti1 selected).
- • Select the active polarity for tim_ti1fp2 (used for capture in TIM_CCR2): write the CC2P and CC2NP bits to CC2P/CC2NP = 10 (active on falling edge).
- • Select the valid trigger input: write the TS bits to 00101 in the TIM_SMCR register (tim_ti1fp1 selected).
- • Configure the slave mode controller in reset mode: write the SMS bits to 0100 in the TIM_SMCR register.
- • Enable the captures: write the CC1E and CC2E bits to 1 in the TIM_CCER register.
Figure 249. PWM input mode timing

The diagram illustrates the timing of PWM input mode captures. It shows four horizontal lines: tim_ti1 (PWM signal), TIM_CNT (counter), TIM_CCR1 (period register), and TIM_CCR2 (pulsewidth register). tim_ti1 starts high, then goes low at TIM_CNT = 0000, then high again at TIM_CNT = 0001. It goes low again at TIM_CNT = 0002 and high again at TIM_CNT = 0003. TIM_CCR1 is constant at 0004, and TIM_CCR2 is constant at 0002. Three capture events are marked with arrows: 1) At the first rising edge of tim_ti1 (when TIM_CNT transitions from 0000 to 0001), it triggers 'IC1 capture', 'IC2 capture', and 'reset counter'. 2) At the first falling edge of tim_ti1 (when TIM_CNT transitions from 0001 to 0002), it triggers 'IC2 capture' and 'pulse width measurement'. 3) At the second rising edge of tim_ti1 (when TIM_CNT transitions from 0002 to 0003), it triggers 'IC1 capture' and 'pulse width measurement'. The counter TIM_CNT wraps from 0004 back to 0000 after the second rising edge.
MSv80502V1
31.3.11 Forced output mode
In output mode (CCxS bits = 00 in the TIM_CCMRx register), each output compare signal (tim_ocxref and then tim_ocx/tim_ocxn) can be forced to active or inactive level directly by software, independently of any comparison between the output compare register and the counter.
To force an output compare signal (tim_ocxref/tim_ocx) to its active level, user just needs to write 00101 in the OCxM bits in the corresponding TIM_CCMRx register. Thus tim_ocxref is forced high (tim_ocxref is always active high) and tim_ocx get opposite value to CCxP polarity bit.
For example: CCxP = 0 (tim_ocx active high) => tim_ocx is forced to high level.
The tim_ocxref signal can be forced low by writing the OCxM bits to 00100 in the TIM_CCMRx register.
Anyway, the comparison between the TIM_CCRx shadow register and the counter is still performed and allows the flag to be set. Interrupt and DMA requests can be sent accordingly. This is described in the output compare mode section below.
31.3.12 Output compare mode
This function is used to control an output waveform or indicate when a period of time has elapsed. Channels 1 to 4 can be output, while channel 5 to 7 are only available inside the microcontroller (for instance, for compound waveform generation or for ADC triggering).
When a match is found between the capture/compare register and the counter, the output compare function:
- • Assigns the corresponding output pin to a programmable value defined by the output compare mode (OCxM bits in the TIM_CCMRx register) and the output polarity (CCxP bit in the TIM_CCER register). The output pin can keep its level (OCxM = 00000), be set active (OCxM = 00001), be set inactive (OCxM = 00010) or can toggle (OCxM = 00011) on match.
- • Sets a flag in the interrupt status register (CCxIF bit in the TIM_SR register).
- • Generates an interrupt if the corresponding interrupt mask is set (CCXIE bit in the TIM_DIER register).
- • Sends a DMA request if the corresponding enable bit is set (CCxDE bit in the TIM_DIER register, CCDS bit in the TIM_CR2 register for the DMA request selection).
The TIM_CCRx registers can be programmed with or without preload registers using the OCxPE bit in the TIM_CCMRx register.
In output compare mode, the update event UEV has no effect on tim_ocxref and tim_ocx output. The timing resolution is one count of the counter. Output compare mode can also be used to output a single pulse (in One-pulse mode).
Procedure
- 1. Select the counter clock (internal, external, prescaler).
- 2. Write the desired data in the TIM_ARR and TIM_CCRx registers.
- 3. Set the CCxIE bit if an interrupt request is to be generated.
- 4. Select the output mode. For example:
- – Write OCxM = 00011 to toggle tim_ocx output pin when CNT matches CCRx
- – Write OCxPE = 0 to disable preload register
- – Write CCxP = 0 to select active high polarity
- – Write CCxE = 1 to enable the output
- 5. Enable the counter by setting the CEN bit in the TIM_CR1 register.
The TIM_CCRx register can be updated at any time by software to control the output waveform, provided that the preload register is not enabled (OCxPE = 0, else TIM_CCRx shadow register is updated only at the next update event UEV). An example is given in Figure 250.
Figure 250. Output compare mode, toggle on tim_oc1

Write B201h in the CC1R register
CNT: 0039, 003A, 003B, ..., B200, B201
CCR1: 003A, ..., B201
tim_oc1ref = tim_oc1: High until match at B201, then Low
Match detected on CCR1
Interrupt generated if enabled
MSv62326V1
31.3.13 PWM mode
Pulse width modulation mode is used to generate a signal with a frequency determined by the value of the TIM_ARR register and a duty cycle determined by the value of the TIM_CCRx register.
The PWM mode can be selected independently on each channel (one PWM per tim_ocx output) by writing 00110 (PWM mode 1) or 00111 (PWM mode 2) in the OCxM bits in the TIM_CCMRx register. The corresponding preload register must be enabled by setting the OCxPE bit in the TIM_CCMRx register, and eventually the autoreload preload register (in upcounting or center-aligned modes) by setting the ARPE bit in the TIM_CR1 register.
As the preload registers are transferred to the shadow registers only when an update event occurs, before starting the counter, all registers must be initialized by setting the UG bit in the TIM_EGR register.
tim_ocx polarity is software programmable using the CCxP bit in the TIM_CCER register. It can be programmed as active high or active low. tim_ocx output is enabled by a combination of the CCxE, CCxNE, MOE, OSSI, and OSSR bits (TIM_CCER and TIM_BDTR registers). Refer to the TIM_CCER register description for more details.
In PWM mode (1 or 2), TIM_CNT and TIM_CCRx are always compared to determine whether TIM_CCRx ≤ TIM_CNT or TIM_CNT ≤ TIM_CCRx (depending on the direction of the counter).
The timer is able to generate PWM in edge-aligned mode or center-aligned mode depending on the CMS bits in the TIM_CR1 register.
PWM edge-aligned mode
- • Upcounting configuration
Upcounting is active when the DIR bit in the TIM_CR1 register is low. Refer to Upcounting mode.
In the following example, the mode is PWM mode 1. The reference PWM signal tim_ocxref is high as long as TIM_CNT < TIM_CCRx else it becomes low. If the compare value in TIM_CCRx is greater than the autoreload value (in TIM_ARR) then tim_ocxref is held at 1. If the compare value is zero then tim_ocxref is held at 0.
Figure 251 shows some edge-aligned PWM waveforms in an example where TIM_ARR = 8.
Figure 251. Edge-aligned PWM waveforms (ARR = 8)

MSv62327V1
- Downcounting configuration
Downcounting is active when DIR bit in TIM_CR1 register is high. Refer to the Downcounting mode
In PWM mode 1, the reference signal tim_ocxref is low as long as TIM_CNT > TIM_CCRx else it becomes high. If the compare value in TIM_CCRx is greater than the autoreload value in TIM_ARR, then tim_ocxref is held at 1. 0% PWM is not possible in this mode.
PWM center-aligned mode
Center-aligned mode is active when the CMS bits in TIM_CR1 register are different from 00 (all the remaining configurations having the same effect on the tim_ocxref/tim_ocx signals). The compare flag is set when the counter counts up, when it counts down or both when it counts up and down depending on the CMS bits configuration. The direction bit (DIR) in the TIM_CR1 register is updated by hardware and must not be changed by software. Refer to Center-aligned mode (up/down counting).
Figure 252 shows some center-aligned PWM waveforms in an example where:
- TIM_ARR = 8
- PWM mode is the PWM mode 1
- The flag is set when the counter counts down corresponding to the center-aligned mode 1 selected for CMS = 01 in TIM_CR1 register.
Figure 252. Center-aligned PWM waveforms (ARR = 8)

The diagram illustrates the timing of center-aligned PWM waveforms for an auto-reload register (ARR) value of 8. The Counter register counts from 0 to 8 and then back down to 0. The diagram shows the behavior of the tim_ocxref and CCxIF signals for different CCRx values and CMS settings.
- Counter register: Counts from 0 to 8 and then back down to 0.
- CCRx = 4:
tim_ocxrefis high from counter value 0 to 4 and low from 4 to 8.CCxIFis high from counter value 0 to 4 and low from 4 to 8. Arrows indicate the transition at counter value 4 for CMS=01, CMS=10, and CMS=11.
- CCRx = 7:
tim_ocxrefis high from counter value 0 to 7 and low from 7 to 8.CCxIFis high from counter value 0 to 7 and low from 7 to 8. Arrows indicate the transition at counter value 7 for CMS=10 or 11.
- CCRx = 8:
tim_ocxrefis high from counter value 0 to 8 and low from 8 to 0.CCxIFis high from counter value 0 to 8 and low from 8 to 0. Arrows indicate the transition at counter value 8 for CMS=01, CMS=10, and CMS=11.
- CCRx > 8:
tim_ocxrefis high from counter value 0 to 8 and low from 8 to 0.CCxIFis high from counter value 0 to 8 and low from 8 to 0. Arrows indicate the transition at counter value 8 for CMS=01, CMS=10, and CMS=11.
- CCRx = 0:
tim_ocxrefis high from counter value 0 to 8 and low from 8 to 0.CCxIFis high from counter value 0 to 8 and low from 8 to 0. Arrows indicate the transition at counter value 8 for CMS=01, CMS=10, and CMS=11.
MSv62328V2
Hints on using center-aligned mode:
- When starting in center-aligned mode, the current up-down configuration is used. It means that the counter counts up or down depending on the value written in the DIR bit in the TIM_CR1 register. Moreover, the DIR and CMS bits must not be changed at the same time by the software.
- Writing to the counter while running in center-aligned mode is not recommended as it can lead to unexpected results. In particular:
- The direction is not updated if a value greater than the autoreload value is written in the counter (TIM_CNT > TIM_ARR). For example, if the counter was counting up, it continues to count up.
- The direction is updated if 0 or the TIM_ARR value is written in the counter but no update event UEV is generated.
- The safest way to use center-aligned mode is to generate an update by software (setting the UG bit in the TIM_EGR register) just before starting the counter and not to write the counter while it is running.
Dithering mode
The PWM mode effective resolution can be increased by enabling the dithering mode, using the DITHEN bit in the TIM_CR1 register. This applies to both the CCR (for duty cycle resolution increase) and ARR (for PWM frequency resolution increase).
The operating principle is to have the actual CCR (or ARR) value slightly changed (adding or not one timer clock period) over 16 consecutive PWM periods, with predefined patterns. This allows a 16-fold resolution increase, considering the average duty cycle or PWM period. Figure 253 presents the dithering principle applied to four consecutive PWM cycles.
Figure 253. Dithering principle

Average duty cycle
DC = 7/5
\(DC = (7+\frac{1}{4})/5\)
\(DC = (7+\frac{1}{2})/5\)
\(DC = (7+\frac{3}{4})/5\)
DC = 8/5
1 clock cycle
MSv45752V1
When the dithering mode is enabled, the register coding is changed as follows (see Figure 254 for example):
- • The four LSBs are coding for the enhanced resolution part (fractional part).
- • The MSBs are left-shifted to the bits 19:4 and are coding for the base value.
Note: The following sequence must be followed when resetting the DITHEN bit:
- 1. CEN and ARPE bits must be reset.
- 2. The DITHEN bit must be reset.
- 3. The CCIF flags must be cleared.
- 4. The CEN bit can be set (eventually with ARPE = 1).
Figure 254. Data format and register coding in dithering mode

The diagram illustrates the data format and register coding in dithering mode. It consists of two main parts: 'Register format in dithering mode' and 'Example'.
Register format in dithering mode: A 20-bit register (b19 to b0) is shown. The MSB (Most Significant Bit) is 16 bits, representing the integer part. The LSB (Least Significant Bit) is 4 bits, representing the fractional part.
Example: A 20-bit register (b19 to b0) is shown. The MSB is 16 bits, representing the integer part. The LSB is 4 bits, representing the fractional part. The example shows a base compare value of 20 during 16 periods, and additional 6 cycles are spread over the 16 periods.
MSv45753V2
The minimum frequency is given by the following formula:
Note: The maximum TIM_ARR and TIM_CCRy values are limited to 0xFFFEF in dithering mode (corresponds to 65534 for the integer part and 15 for the dithered part).
As shown on Figure 255, the dithering mode is used to increase the PWM resolution whatever the PWM frequency.
Figure 255. PWM resolution vs frequency

The graph illustrates the relationship between PWM resolution and PWM frequency. The vertical axis represents PWM resolution, with markers for 20-bit and 16-bit. The horizontal axis represents PWM frequency, with a marker for \(F_{PWM \text{ min}}\). Two curves are shown: 'Dithering' and 'No Dithering'. Both curves start at \(F_{PWM \text{ min}}\) with a resolution of 20-bit. The 'Dithering' curve decreases more gradually than the 'No Dithering' curve, which drops to 16-bit at \(F_{PWM \text{ min}}\) and continues to decrease. A dashed vertical line connects the 16-bit mark on the y-axis to the 'No Dithering' curve at \(F_{PWM \text{ min}}\). The reference code MSv47464V2 is located in the bottom right corner of the graph area.
The duty cycle and/or period changes are spread over 16 consecutive periods, as described in Figure 256.
Figure 256. PWM dithering pattern
MSv45755V1
The autoreload and compare values increments are spread following specific patterns described in Table 293. The dithering sequence is done to have increments distributed as evenly as possible and minimize the overall ripple.
Table 293. CCR and ARR register change dithering pattern| LSB value | PWM period | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | |
| 0000 | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| 0001 | +1 | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| 0010 | +1 | - | - | - | - | - | - | - | +1 | - | - | - | - | - | - | - |
| 0011 | +1 | - | - | - | +1 | - | - | - | +1 | - | - | - | - | - | - | - |
| 0100 | +1 | - | - | - | +1 | - | - | - | +1 | - | - | - | +1 | - | - | - |
| 0101 | +1 | - | +1 | - | +1 | - | - | - | +1 | - | - | - | +1 | - | - | - |
| 0110 | +1 | - | +1 | - | +1 | - | - | - | +1 | - | +1 | - | +1 | - | - | - |
Table 293. CCR and ARR register change dithering pattern (continued)
| LSB value | PWM period | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | |
| 0111 | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | - | - |
| 1000 | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - |
| 1001 | +1 | +1 | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - |
| 1010 | +1 | +1 | +1 | - | +1 | - | +1 | - | +1 | +1 | +1 | - | +1 | - | +1 | - |
| 1011 | +1 | +1 | +1 | - | +1 | +1 | +1 | - | +1 | +1 | +1 | - | +1 | - | +1 | - |
| 1100 | +1 | +1 | +1 | - | +1 | +1 | +1 | - | +1 | +1 | +1 | - | +1 | +1 | +1 | - |
| 1101 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | - | +1 | +1 | +1 | - | +1 | +1 | +1 | - |
| 1110 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | - | +1 | +1 | +1 | +1 | +1 | +1 | +1 | - |
| 1111 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | - |
The dithering mode is also available in center-aligned PWM mode (CMS bits in TIM_CR1 register are not equal to 00). In this case, the dithering pattern is applied over eight consecutive PWM periods, considering the up and down counting phases as shown in Figure 257.
Figure 257. Dithering effect on duty cycle in center-aligned PWM mode

Table 294 shows how the dithering pattern is added in center-aligned PWM mode.
Table 294. CCR register change dithering pattern in center-aligned PWM mode
| LSB value | PWM period | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |||||||||
| Up | Dn | Up | Dn | Up | Dn | Up | Dn | Up | Dn | Up | Dn | Up | Dn | Up | Dn | |
| 0000 | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| 0001 | +1 | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| 0010 | +1 | - | - | - | - | - | - | - | +1 | - | - | - | - | - | - | - |
| 0011 | +1 | - | - | - | +1 | - | - | - | +1 | - | - | - | - | - | - | - |
| 0100 | +1 | - | - | - | +1 | - | - | - | +1 | - | - | - | +1 | - | - | - |
| 0101 | +1 | - | +1 | - | +1 | - | - | - | +1 | - | - | - | +1 | - | - | - |
| 0110 | +1 | - | +1 | - | +1 | - | - | - | +1 | - | +1 | - | +1 | - | - | - |
Table 294. CCR register change dithering pattern in center-aligned PWM mode (continued)
| LSB value | PWM period | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |||||||||
| Up | Dn | Up | Dn | Up | Dn | Up | Dn | Up | Dn | Up | Dn | Up | Dn | Up | Dn | |
| 0111 | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | - | - |
| 1000 | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - |
| 1001 | +1 | +1 | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - | +1 | - |
| 1010 | +1 | +1 | +1 | - | +1 | - | +1 | - | +1 | +1 | +1 | - | +1 | - | +1 | - |
| 1011 | +1 | +1 | +1 | - | +1 | +1 | +1 | - | +1 | +1 | +1 | - | +1 | - | +1 | - |
| 1100 | +1 | +1 | +1 | - | +1 | +1 | +1 | - | +1 | +1 | +1 | - | +1 | +1 | +1 | - |
| 1101 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | - | +1 | +1 | +1 | - | +1 | +1 | +1 | - |
| 1110 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | - | +1 | +1 | +1 | +1 | +1 | +1 | +1 | - |
| 1111 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | +1 | - |
31.3.14 Asymmetric PWM mode
Asymmetric mode allows two center-aligned PWM signals to be generated with a programmable phase shift. While the frequency is determined by the value of the TIM_ARR register, the duty cycle and the phase-shift are determined by a pair of TIM_CCRx register. One register controls the PWM during up-counting, the second during down counting, so that PWM is adjusted every half PWM cycle, for instance:
- – tim_oc1refc is controlled by TIM_CCR1 and TIM_CCR2
- – tim_oc3refc is controlled by TIM_CCR3 and TIM_CCR4
- – ...
Figure 258 represents an example of signals that can be generated using asymmetric PWM mode (channels 1 to 4 are configured in asymmetric PWM mode 2). Together with the deadtime generator, this allows a full-bridge phase-shifted DC to DC converter to be controlled.
Figure 258. Generation of 2 phase-shifted PWM signals with 50% duty cycle

MSv62329V1
Multiple asymmetric PWM modes are available to combine different pairs of TIM_CCRx registers and generate the required waveform, as listed in Table 295. The selection is done
with the OCxM[4:0] bitfield in TIM_CCMRx registers. For each pair of TIM_CCRx registers, two options are given (e.g. Asymmetric PWM mode 3 and 4), one being in PWM mode 1 (channel active as long as the counter is below the TIM_CCRx value), the other one in PWM mode 2 (channel active when the counter is above the TIM_CCRx value).
For the asymmetric PWM modes 1 to 6, it is mandatory to have the same PWM mode for both channels. For instance, it is mandatory to have OC1M[4:0] = OC2M[4:0] = 00110 for the asymmetric PWM mode 1 on oc1refc.
For the asymmetric PWM modes 7 to 10, it is mandatory to have opposite PWM mode for both channels (one being in PWM mode 1 and the other in PWM mode 2). Refer to the Table 295 for configuration.
Note: The OCxM[4:0] bitfield is split into two parts for compatibility reasons, the most significant bits are not contiguous with the three least significant ones.
When a given channel is used as asymmetric PWM channel, its complementary channel can also be used. For instance, if an tim_oc1refc signal is generated on channel 1 (Asymmetric PWM mode 1), it is possible to output either the regular tim_oc2ref signal on channel 2 or a tim_oc2refc signal resulting from asymmetric PWM mode 1.
Table 295. Asymmetric PWM modes
| Output compare mode | OCxM[4:0] | oc1refc | oc2refc | oc3refc | oc4refc | oc5refc | oc6refc | oc7refc | PWM Mode (1) |
|---|---|---|---|---|---|---|---|---|---|
| Asymmetric PWM mode 1 | 01110 | oc1ref (up-counting) oc2ref (down-counting) | oc3ref (up-counting) oc4ref (down-counting) | oc5ref (up-counting) oc6ref (down-counting) | - | 1 | |||
| Asymmetric PWM mode 2 | 01111 | 2 | |||||||
| Asymmetric PWM mode 3 | 10010 | oc1ref (up-counting) | oc2ref (up-counting) | oc3ref (up-counting) | oc4ref (up-counting) | - | - | - | 1 |
| Asymmetric PWM mode 4 | 10011 | oc5ref (down-counting) | oc5ref (down-counting) | oc5ref (down-counting) | oc5ref (down-counting) | - | - | - | 2 |
| Asymmetric PWM mode 5 | 10100 | oc1ref (up-counting) | oc2ref (up-counting) | oc3ref (up-counting) | oc4ref (up-counting) | - | - | - | 1 |
| Asymmetric PWM mode 6 | 10101 | oc6ref (down-counting) | oc6ref (down-counting) | oc6ref (down-counting) | oc6ref (down-counting) | - | - | - | 2 |
| Output compare mode | OCxM[4:0] | oc1refc | oc2refc | oc3refc | oc4refc | oc5refc | oc6refc | oc7refc | PWM Mode(1) |
|---|---|---|---|---|---|---|---|---|---|
| Asymmetric PWM mode 7 | 10110 | oc1ref OR oc5ref (up-counting) oc1refc= 1 (down-counting) | oc2ref OR oc6ref (up-counting) oc2refc= 1 (down-counting) | oc3ref OR oc4ref (up-counting) oc3refc= 1 (down-counting) | oc4ref OR oc7ref (up-counting) oc4refc= 1 (down-counting) | 1(2) | |||
| Asymmetric PWM mode 8 | 10111 | oc1ref AND oc5ref (up-counting) oc1refc= 0 (down-counting) | oc2ref AND oc6ref (up-counting) oc2refc= 0 (down-counting) | oc3ref AND oc4ref (up-counting) oc3refc= 0 (down-counting) | oc4ref AND oc7ref (up-counting) oc4refc= 0 (down-counting) | - | - | - | 2(3) |
| Asymmetric PWM mode 9 | 11000 | oc1refc= 1 (up-counting) oc1ref OR oc5ref (down-counting) | oc2refc= 1 (up-counting) oc2ref OR oc6ref (down-counting) | oc3refc= 1 (up-counting) oc3ref OR oc4ref (down-counting) | oc4refc= 1 (up-counting) oc4ref OR oc7ref (down-counting) | 1(2) | |||
| Asymmetric PWM mode 10 | 11001 | oc1refc= 0 (up-counting) oc1ref AND oc5ref (down-counting) | oc2refc= 0 (up-counting) oc2ref AND oc6ref (down-counting) | oc3refc= 0 (up-counting) oc3ref AND oc4ref (down-counting) | oc4refc= 0 (up-counting) oc7ref AND oc4ref (down-counting) | - | - | - | 2(3) |
- 1. PWM mode 1: channel active as long as the counter is below the TIM_CCRx value). PWM mode 2: channel active when the counter is above the TIM_CCRx value. Unless explicitly mentioned, the PWM mode must be identical for the 2 channels used for the asymmetric mode
- 2. oc5ref, oc6ref, oc4ref and oc7ref must be programmed in PWM mode 2
- 3. oc5ref, oc6ref, oc4ref and oc7ref must be programmed in PWM mode 1
The Figure 259 represents an example suitable for single-shunt current sensing techniques requiring phase-shifted PWMs, for 3-phase motor control. This is done using asymmetric PWM mode 3 and 5:
- – Channel 1 is configured in asymmetric PWM mode 4
- – Channel 2 is configured in asymmetric PWM mode 5
- – Channel 3 is configured in regular PWM mode 2
- – Compare 4 and 7 are available for ADC triggering purpose
Figure 259. Asymmetric mode example for single-shunt current sensing

The Figure 260 represents an example of the waveforms that can be generated with asymmetric modes 7 to 10.
Figure 260. Asymmetric mode 8 example

31.3.15 Combined PWM mode
Combined PWM mode allows two edge or center-aligned PWM signals to be generated with programmable delay and phase shift between respective pulses. While the frequency is determined by the value of the TIM_ARR register, the duty cycle and delay are determined by the two TIM_CCRx registers. The resulting signals, tim_ocxrefc, are made of an OR or AND logical combination of two reference PWMs, as summarized in the below:
Table 296. Combined PWM mode overview
| Output compare mode | OCxM[4:0] | oc1refc | oc2refc | oc3refc | oc4refc | oc5refc | oc6refc | oc7refc | PWM mode(1) |
|---|---|---|---|---|---|---|---|---|---|
| Combined PWM mode 1 | 01100 | oc1ref OR oc2ref | oc3ref OR oc4ref | oc5ref OR oc6ref | - | 1 | |||
| Combined PWM mode 2 | 01101 | oc1ref AND oc2ref | oc3ref AND oc4ref | oc5ref AND oc6ref | - | 2 | |||
| Combined PWM mode 3 | 10000 | oc1ref OR oc5ref | oc2ref OR oc6ref | oc3ref OR oc5ref | oc4ref OR oc6ref | - | - | - | 1 |
| Combined PWM mode 4 | 10001 | oc1ref AND oc5ref | oc2ref AND oc6ref | oc3ref AND oc5ref | oc4ref AND oc6ref | - | - | - | 2 |
- 1. PWM mode 1: channel active as long as the counter is below the TIM_CCRx value). PWM mode 2: channel active when the counter is above the TIM_CCRx value.
When a given channel is used as combined PWM channel, its complementary channel must be configured in the opposite PWM mode (for instance, one in PWM mode 1 and the other in PWM mode 2).
Note: The OCxM[4:0] bitfield is split into two parts for compatibility reasons, the most significant bits are not contiguous with the three least significant ones.
Figure 261 represents an example of signals that can be generated using combined PWM mode, obtained with the following configuration:
- • Channel 1 is configured in Combined PWM mode 2.
- • Channel 2 is configured in PWM mode 1.
- • Channel 3 is configured in Combined PWM mode 2.
- • Channel 4 is configured in PWM mode 1.
Figure 261. Combined PWM mode examples

Combined PWM mode 1: \(tim\_oc1refc = tim\_oc1ref \text{ OR } tim\_oc2ref\)
Combined PWM mode 2: \(tim\_oc3refc = tim\_oc3ref \text{ AND } tim\_oc4ref\)
MSv74198V1
The Figure 262 represents an example suitable for a 3-phase interleaved converter requiring independent control of duty cycle and phase-shift. This is done using Combined PWM mode 2 and 4:
- – Channel 1 is configured in Combined PWM mode 4
- – Channel 2 is configured in Combined PWM mode 4
- – Channel 3 is configured in Combined PWM mode 2
Figure 262. Combined PWM 3 example

31.3.16 Combined 3-phase PWM mode
Combined 3-phase PWM mode allows one to three center-aligned PWM signals to be generated with a single programmable signal ANDed in the middle of the pulses. The tim_oc5ref signal is used to define the resulting combined signal.
The 4 bits GC5C[4:1] in the TIM_CCR5 allow selection on which reference signal the tim_oc5ref is combined. The resulting signals, tim_ocxrefc, are made of an AND logical combination of two reference PWMs:
- • If
GC5C1is set,tim_oc1refcis the logical AND oftim_oc1refandtim_oc5ref - • If
GC5C2is set,tim_oc2refcis the logical AND oftim_oc2refandtim_oc5ref - • If
GC5C3is set,tim_oc3refcis the logical AND oftim_oc3refandtim_oc5ref - • If
GC5C4is set,tim_oc4refcis the logical AND oftim_oc4refandtim_oc5ref
It is possible also to select an OR function with GC5C1O, GC5C2O, GC5C3O and GC5C4O bits, as following:
- • If
GC5C1Ois set,tim_oc1refcis the logical OR oftim_oc1refandtim_oc5ref - • If
GC5C2Ois set,tim_oc2refcis the logical OR oftim_oc2refandtim_oc5ref - • If
GC5C3Ois set,tim_oc3refcis the logical OR oftim_oc3refandtim_oc5ref - • If
GC5C4Ois set,tim_oc4refcis the logical OR oftim_oc4refandtim_oc5ref
If both GC5Cx and GC5CxO bits are set, GC5Cx bit overrides GC5CxO programming and tim_ocxrefc is equal to tim_ocxref AND tim_oc5ref.
Combined 3-phase PWM mode can be selected independently on channels 1 to 4 by setting at least one of the bits GC5C[4:1] or GC5CO[4:1].
Figure 263. 3-phase combined PWM signals with multiple trigger pulses per period
![Figure 263: 3-phase combined PWM signals with multiple trigger pulses per period. The diagram shows a triangular counter waveform and its relationship to various PWM signals and control registers. The signals include tim_oc5ref, tim_oc1refc, tim_oc2refc, tim_oc3refc, tim_oc4ref, tim_oc6ref, and tim_trgo2. The GC5C[3:0] register is shown with Preload and Active states. The Preload state is 100, and the Active state is 001. The tim_trgo2 signal is a trigger pulse that occurs at the end of each period. The diagram is labeled MSv62331V1.](/RM0522-STM32C5/7f7f28b2ba276fbba2066cc0cf51bb72_img.jpg)
The figure illustrates the timing relationship between a triangular counter and various PWM signals. The counter waveform is shown at the top, with its period divided into multiple trigger pulses. The PWM signals (tim_oc5ref, tim_oc1refc, tim_oc2refc, tim_oc3refc, tim_oc4ref, tim_oc6ref) are generated based on the counter's position relative to the CCR registers (CCR1, CCR2, CCR3, CCR4, CCR5, CCR6). The tim_trgo2 signal is a trigger pulse that occurs at the end of each period. The GC5C[3:0] register is shown with Preload and Active states. The Preload state is 100, and the Active state is 001. The diagram is labeled MSv62331V1.
The tim_trgo2 waveform shows how the ADC can be synchronized on given 3-phase PWM signals. Refer to Section 31.3.36: ADC triggers for more details.
31.3.17 Complementary outputs and dead-time insertion
The advanced-control timers (TIM1/TIM8) can output two complementary signals and manage the switching-off and the switching-on instants of the outputs.
This time is generally known as dead-time and it has to be adjusted depending on the devices that are connected to the outputs and their characteristics (such as intrinsic delays of level-shifters, or delays due to power switches).
The polarity of the outputs (main output tim_ocx or complementary tim_ocxn) can be selected independently for each output. This is done by writing to the CCxP and CCxNP bits in the TIM_CCER register.
The complementary signals tim_ocx and tim_ocxn are activated by a combination of several control bits: the CCxE and CCxNE bits in the TIM_CCER register and the MOE, OISx, OISxN, OSS1, and OSSR bits in the TIM_BDTR and TIM_CR2 registers. Refer to Table 304: Output control bits for complementary tim_ocx and tim_ocxn channels with break feature for more details. In particular, the dead-time is activated when switching to the idle state (MOE falling down to 0).
Dead-time insertion is enabled by setting both CCxE and CCxNE bits, and the MOE bit if the break circuit is present. There is one 10-bit dead-time generator for each channel. From a
reference waveform tim_ocxref, it generates two outputs tim_ocx and tim_ocxn. If tim_ocx and tim_ocxn are active high:
- • The
tim_ocxoutput signal is the same as the reference signal except for the rising edge, which is delayed relative to the reference rising edge. - • The
tim_ocxnoutput signal is the opposite of the reference signal except for the rising edge, which is delayed relative to the reference falling edge.
If the delay is greater than the width of the active output (tim_ocx or tim_ocxn) then the corresponding pulse is not generated.
The following figures show the relationships between the output signals of the dead-time generator and the reference signal tim_ocxref considering CCxP = 0, CCxNP = 0, MOE = 1, CCxE = 1 and CCxNE = 1 in these examples.
Figure 264. Complementary output with symmetrical dead-time insertion

The DTAE bit in the TIM_DTR2 is used to differentiate the deadtime values for rising and falling edges of the reference signal, as shown on Figure 265.
In asymmetrical mode (DTAE = 1), the rising edge-referred deadtime is defined by the DTG[7:0] bitfield in the TIM_BDTR register, while the falling edge-referred is defined by the DTGF[7:0] bitfield in the TIM_DTR2 register. The DTAE bit must be written before enabling the counter and must not be modified while CEN = 1.
It is possible to have the deadtime value updated on-the-fly during pwm operation, using a preload mechanism. The deadtime bitfield DTG[7:0] and DTGF[7:0] are preloaded when the DTPE bit is set, in the TIM_DTR2 register. The preload value is loaded in the active register on the next update event.
Note: If the DTPE bit is enabled while the counter is enabled, any new value written since last update is discarded and previous value is used.
Figure 265. Asymmetrical deadtime

The figure shows two sets of timing diagrams for three signals: tim_ocxref, tim_ocx, and tim_ocxn. The top set, labeled 'Symmetrical deadtime (DTAE = 0)', shows tim_ocx following tim_ocxref with a deadtime DTG[7:0] on both rising and falling edges. tim_ocxn is the inverse of tim_ocx with the same deadtime. The bottom set, labeled 'Asymmetrical deadtime (DTAE = 1)', shows tim_ocx following tim_ocxref with a deadtime DTGF[7:0] on the rising edge and DTG[7:0] on the falling edge. tim_ocxn is the inverse of tim_ocx with the same deadtimes. Vertical dashed lines indicate the timing relationships. The reference ID 'MSv62333V1' is in the bottom right corner.
Figure 266. Dead-time waveforms with delay greater than the negative pulse

The diagram shows tim_ocxref, tim_ocx, and tim_ocxn signals. tim_ocxref has a short negative pulse. tim_ocx follows tim_ocxref with a deadtime. tim_ocxn is low for a duration labeled 'delay', which is longer than the negative pulse of tim_ocxref. Vertical dashed lines mark the transitions. The reference ID 'MSv62334V1' is in the bottom right corner.
Figure 267. Dead-time waveforms with delay greater than the positive pulse

The diagram shows tim_ocxref, tim_ocx, and tim_ocxn signals. tim_ocxref has a short positive pulse. tim_ocx follows tim_ocxref with a deadtime. tim_ocxn is low for a duration labeled 'delay', which is longer than the positive pulse of tim_ocxref. Vertical dashed lines mark the transitions. The reference ID 'MSv62335V1' is in the bottom right corner.
The dead-time delay is the same for each of the channels and is programmable with the DTG bits in the TIM_BDTR register. Refer to Section 31.6.20: TIM break and dead-time register (TIM_BDTR) for delay calculation.
Redirecting tim_ocxref to tim_ocx or tim_ocxn
In output mode (forced, output compare or PWM), tim_ocxref can be redirected to the tim_ocx output or to tim_ocxn output by configuring the CCxE and CCxNE bits in the TIM_CCER register.
This is used to send a specific waveform (such as PWM or static active level) on one output while the complementary remains at its inactive level. Other alternative possibilities are to have both outputs at inactive level or both outputs active and complementary with dead-time.
Note: When only tim_ocxn is enabled (CCxE = 0, CCxNE = 1), it is not complemented and becomes active as soon as tim_ocxref is high. For example, if CCxNP = 0 then tim_ocxn = tim_ocxref. On the other hand, when both tim_ocx and tim_ocxn are enabled (CCxE = CCxNE = 1) tim_ocx becomes active when tim_ocxref is high whereas tim_ocxn is complemented and becomes active when tim_ocxref is low.
31.3.18 Clock dividers for dead-time generators and digital filters
The dead-time generators and the digital filters (for tim_etr_in, tim_tix) are using a DTS_ck clock (with a \(t_{DTS}\) period), derived from the tim_ker_ck clock.
A prescaler can decrease the frequency to extend the deadtime period programmed with the CKD[1:0] bitfield in the TIM_CR1 register. A second prescaler can decrease the resulting DTS_ck clock to extend solely the digital filters range, with the CKD2[3:0] bitfield in the TIM_CR1 register.
Figure 268. Clock prescalers for dead-time and digital filters
![Block diagram showing the clock prescalers for dead-time and digital filters. The input clock tim_ker_ck (with period t_tim_ker_ck) enters a Prescaler block. This block is controlled by the CKD[1:0] bitfield in the TIM_CR1 register. The output of the first prescaler is DTS_ck (with period t_DTS), which feeds into the Deadtime generator and break/break2 filters. DTS_ck also enters a second Prescaler block, controlled by the CKD2[3:0] bitfield in the TIM_CR1 register. The output of the second prescaler is DTS2_ck (with period t_DTS2), which feeds into the Digital filters (tim_etr_in, tim_tix).](/RM0522-STM32C5/63cfc090a779b7a8d1d2f22df0c09f3c_img.jpg)
graph LR
tim_ker_ck["tim_ker_ck
(t_tim_ker_ck)"] --> P1[Prescaler]
CKD1["CKD[1:0]
TIM_CR1"] --- P1
P1 --> DTS_ck["DTS_ck
(t_DTS)"]
DTS_ck --> DT["Deadtime generator and
break/break2 filters"]
DTS_ck --> P2[Prescaler]
CKD2["CKD2[3:0]
TIM_CR1"] --- P2
P2 --> DTS2_ck["DTS2_ck
(t_DTS2)"]
DTS2_ck --> DF["Digital filters
(tim_etr_in, tim_tix)"]
MSv80503V1
31.3.19 Using the break function
The purpose of the break function is to protect power switches driven by PWM signals generated with the timers. The two break inputs are usually connected to fault outputs of power stages and 3-phase inverters. When activated, the break circuitry shuts down the PWM outputs and forces them to a predefined safe state. A number of internal MCU events can also be selected to trigger an output shut-down.
The break features two channels. A break channel which gathers both system-level fault (clock failure, ECC/parity errors,...) and application fault (from input pins and built-in comparator), and can force the outputs to a predefined level (either active or inactive) after a deadtime duration. A break2 channel which only includes application faults and is able to force the outputs to an inactive state.
The output enable signal and output levels during break are depending on several control bits:
- • The MOE bit in TIM_BDTR register is used to enable/disable the outputs by software and is reset in case of break or break2 event.
- • The OSSI bit in the TIM_BDTR register defines whether the timer controls the output in inactive state or releases the control to the GPIO controller (typically to have it in Hi-Z mode)
- • The OISx and OISxN bits in the TIM_CR2 register which are setting the output shut-down level, either active or inactive. The tim_ocx and tim_ocxn outputs cannot be set both to active level at a given time, whatever the OISx and OISxN values. Refer to Table 304: Output control bits for complementary tim_ocx and tim_ocxn channels with break feature for more details.
When exiting from reset, the break circuit is disabled and the MOE bit is low. The break functions can be enabled by setting the BKE and BK2E bits in the TIM_BDTR register. The break input polarities can be selected by configuring the BKP and BK2P bits in the same register. BKEx and BKPx can be modified at the same time. When the BKEx and BKPx bits are written, a delay of one APB clock cycle is applied before the writing is effective. Consequently, it is necessary to wait one APB clock period to correctly read back the bit after the write operation.
Because MOE falling edge can be asynchronous, a resynchronization circuit has been inserted between the actual signal (acting on the outputs) and the synchronous control bit (accessed in the TIM_BDTR register). It results in some delays between the asynchronous and the synchronous signals. In particular, if MOE is set to 1 whereas it was low, a delay must be inserted (dummy instruction) before reading it correctly. This is because the write acts on the asynchronous signal whereas the read reflects the synchronous signal.
The sources for break (tim_brk) channel are:
- • External sources connected to one of the TIM_BKIN pin (as per selection done in the GPIO alternate function selection registers), with polarity selection and optional digital filtering
- • Internal sources:
- – coming from a tim_brk_cmpx input (refer to Section 31.3.2: TIM1/TIM8 pins and internal signals for product specific implementation)
- – coming from a system break request (refer to Section 31.3.2: TIM1/TIM8 pins and internal signals for product specific implementation)
The sources for break2 (tim_brk2) are:
- • External sources connected to one of the TIM_BKIN2 pin (as per selection done in the GPIO alternate function selection registers), with polarity selection and optional digital filtering
- • Internal sources coming from a tim_brk2_cmpx input (refer to Section 31.3.2: TIM1/TIM8 pins and internal signals for product specific implementation)
Break events can also be generated by software using BG and B2G bits in the TIM_EGR register.
All sources are ORed before entering the timer tim_brk or tim_brk2 inputs, as per Figure 269 below.
Figure 269. Break and Break2 circuitry overview
MSv80504V1
Note: An asynchronous (clockless) operation is only guaranteed when the programmable filter is disabled. If it is enabled, a fail safe clock mode (for example by using the internal PLL and/or the CSS) must be used to guarantee that break events are handled.
When one of the breaks occurs (selected level on one of the break inputs):
- • The MOE bit is cleared asynchronously, putting the outputs in inactive state, idle state, or even releasing the control to the GPIO controller (selected by the OSSI bit). This feature is enabled even if the MCU oscillator is off.
- • Each output channel is driven with the level programmed in the OISx bit in the TIM_CR2 register as soon as MOE = 0. If OSSI = 0, the timer releases the output control (taken over by the GPIO controller), otherwise the enable output remains high.
- • When complementary outputs are used:
- – The outputs are first put in inactive state (depending on the polarity). This is done asynchronously so that it works even if no clock is provided to the timer.
- – If the timer clock is still present, then the dead-time generator is reactivated in order to drive the outputs with the level programmed in the OISx and OISxN bits after a dead-time. Even in this case, tim_ocx and tim_ocxn cannot be driven to
their active level together. Note that because of the resynchronization on MOE, the dead-time duration is slightly longer than usual (around 2 tim_ker_ck clock cycles).
- – If
OSSI = 0, the timer releases the output control (taken over by the GPIO controller which forces a Hi-Z state), otherwise the enable outputs remain or become high as soon as one of theCCxEorCCxNEbits is high. - • The break status flags (
B2GF,BGF,SBIF,BIF, andB2IFbits in theTIM_SRregister) are set. An interrupt is generated if theBIEbit in theTIM_DIERregister is set. - • An output disable status flag (
ODSin theTIM_SRregister) indicates the status of the outputs:- –
ODS = 0: Idle state. Break was triggered (orMOEwas written to 0) andOISstates are forced ontim_ocxandtim_ocxnoutputs - –
ODS = 1: Disabled state. Break2 was triggered,tim_ocxandtim_ocxnoutputs are inactive
- –
- • If the
AOEbit in theTIM_BDTRregister is set, theMOEbit is automatically set again at the next update event (UEV). As an example, this can be used to perform a regulation. Otherwise,MOEremains low until the application sets it to 1 again. In this case, it can be used for security and the break input can be connected to an alarm from power drivers, thermal sensors, or any security components.
Note: If the MOE is reset by the CPU while the AOE bit is set, the outputs are in idle state and forced to inactive level or Hi-Z depending on OSSI value. If both the MOE and AOE bits are reset by the CPU, the outputs are in disabled state and driven with the level programmed in the OISx bit in the TIM_CR2 register.
The break inputs are active on level. Thus, the MOE cannot be set while the break input is active (neither automatically nor by software). In the meantime, the status flag BIF and B2IF cannot be cleared.
In addition to the break input and the output management, a write protection has been implemented inside the break circuit to safeguard the application. It is used to freeze the configuration of several parameters (dead-time duration, tim_ocx/tim_ocxn polarities and state when disabled, OCxM configurations, break enable, and polarity). The application can choose from three levels of protection selected by the LOCK bits in the TIM_BDTR register. Refer to Section 31.6.20: TIM break and dead-time register (TIM_BDTR). The LOCK bits can be written only once after an MCU reset.
Figure 270 shows an example of behavior of the outputs in response to a break.
Figure 270. Various output behavior in response to a break event on tim_brk (OSSI = 1)

The diagram illustrates the response of various timer outputs to a BREAK (MOE) event when OSSI = 1. The signals shown are:
- tim_ocxref: The reference signal that triggers the break event.
- tim_ocx (tim_ocxn not implemented, CCxP=0, OISx=1): Output remains high after the break event.
- tim_ocx (tim_ocxn not implemented, CCxP=0, OISx=0): Output transitions to low after the break event.
- tim_ocx (tim_ocxn not implemented, CCxP=1, OISx=1): Output transitions to low after the break event.
- tim_ocx (tim_ocxn not implemented, CCxP=1, OISx=0): Output remains high after the break event.
- tim_ocx and tim_ocxn (CCxE=1, CCxP=0, OISx=0, CCxNE=1, CCxNP=0, OISxN=1): tim_ocx transitions to low, and tim_ocxn transitions to high after a delay.
- tim_ocx and tim_ocxn (CCxE=1, CCxP=0, OISx=1, CCxNE=1, CCxNP=1, OISxN=1): tim_ocx transitions to high, and tim_ocxn transitions to low after a delay.
- tim_ocx and tim_ocxn (CCxE=1, CCxP=0, OISx=0, CCxNE=0, CCxNP=0, OISxN=1): tim_ocx transitions to low, and tim_ocxn transitions to high after a delay.
- tim_ocx and tim_ocxn (CCxE=1, CCxP=0, OISx=1, CCxNE=0, CCxNP=0, OISxN=0): tim_ocx transitions to high, and tim_ocxn transitions to low after a delay.
- tim_ocx and tim_ocxn (CCxE=1, CCxP=0, CCxNE=0, CCxNP=0, OISx=OISxN=0 or OISx=OISxN=1): Both outputs transition to the same state (low or high) after a delay.
MSv62337V1
The two break inputs have different behaviors on timer outputs:
- • The tim_brk input can either disable (inactive state) or force the PWM outputs to a predefined safe state.
- • tim_brk2 can only disable (inactive state) the PWM outputs.
The tim_brk has a higher priority than tim_brk2 input, as described in Table 297.
The output disable status flag (ODS in the TIM_SR register) indicates the status of the outputs after a break event and is useful to distinguish break and break2 safe states.
Note: tim_brk2 must only be used with OSSR = OSSI = 1.
Table 297. Behavior of timer outputs versus tim_brk/tim_brk2 inputs
tim_brk | tim_brk2 | Timer outputs state | Typical use case | |
|---|---|---|---|---|
tim_ocxn output(low side switches) | tim_ocx output(high side switches) | |||
| Active | X |
| ON after deadtime insertion | OFF |
| Inactive | Active | Inactive | OFF | OFF |
Figure 271 gives an example of tim_ocx and tim_ocxn output behavior in case of active signals on tim_brk and tim_brk2 inputs. In this case, both outputs have active high polarities (CCxP = CCxNP = 0 in TIM_CCER register).
Figure 271. PWM output state following tim_brk and tim_brk2 assertion (OSSI = 1)

The diagram illustrates the timing relationship between the tim_brk2, tim_brk, tim_ocx, and tim_ocxn signals. tim_brk2 is high, then transitions low. tim_brk is high, then transitions low. tim_ocx and tim_ocxn are high, then transition low after a deadtime delay following the assertion of tim_brk and tim_brk2. The I/O state is Active, then Inactive, then Idle. The deadtime is indicated by a double-headed arrow between the assertion of tim_brk and tim_brk2 and the assertion of tim_ocx and tim_ocxn. The I/O state is labeled as Active, Inactive, and Idle. The diagram is labeled MSv62338V1.
Figure 272. PWM output state following tim_brk assertion (OSSI = 0)

31.3.20 Delayed break
In Neutral-Point Clamped (NPC) multilevel converter topology, a break strategy with immediate outputs shut-down is not suitable, as it may damage the power switches with excessive voltage levels.
The delayed break features provide 2 options delaying the response to a break event, and implement a safe shut-down sequence.
BKMx[1:0] and BKMxN[1:0] bitfields in TIM_MPR1 provides 3 options for each complementary outputs (tim_oc1/tim_oc1n to tim_oc4/tim_oc4n), as show on Figure 273 below:
- – BKM[1:0] = 00: the break response is immediate
- – BKM[1:0] = 01: Delayed 1 break. The break response is delayed with a delay defined in the DBK1[7:0] bitfield of the TIM_MPR2 register
- – BKM[1:0] = 10: Delayed 2 break. The break response is delayed with a delay defined in the DBK2[7:0] bitfield of the TIM_MPR2 register
Figure 273. Immediate break and Delayed 1/2 break modes
![Timing diagram for Figure 273 illustrating three break modes: Immediate break, Delayed 1 break, and Delayed 2 break. The diagram shows the signals tim_brk, tim_ocx (for BKMx[1:0] = 00, 01, and 10), MOE, and the overall I/O state. The I/O state transitions from Active to Disabled when MOE falls.](/RM0522-STM32C5/562e4f22dd69751af2f2189ba32ec3c2_img.jpg)
The delayed break mode is triggered when:
- • A break event occurs
- • The MOE bit is reset
- • When the microcontroller enters debug mode with DBG_TIM_STOP=1
Warning: The break2 feature must be disabled when the delayed mode is enabled.
When delayed break mode is triggered, the MOE bit is immediately cleared, and cannot be set during the delayed break duration. In bidirectional break mode, the break output is reset immediately to indicate the delayed break start to external components. Once the longest of the 2 delays is over, the deadtime generator is enabled to prevent any deadtime violation if OISx/OISxN bits are set.
If the tim_ocx/tim_ocxn signal is reset before the end of the delayed break (due to a compare match in PWM mode, typically), the signal is not maintained during the full delayed break period, to maintain the duty cycle, as shown on Figure 274 below. Still, the Delayed break circuitry guarantees that the tim_ocx/tim_ocxn signals cannot be set again once the break event occurred.
Figure 274. Pulse termination during delayed break

MSv75803V1
The Figure 563 depicts the behavior when the deadtime generator is enabled, for the 3 cases:
- – Delayed break triggered when tim_ocx is set
- – Delayed break triggered when tim_ocxn is set
- – Delayed break triggered during deadtime interval
Figure 275. Delayed break with deadtime insertion

The diagram illustrates the timing of a delayed break with deadtime insertion. It consists of three horizontal sections, each showing the relationship between three signals: tim_brk, tim_ocx, and tim_ocxn.
- Top section: Delayed break when high-side is on. The
tim_ocxsignal is high. Thetim_ocxnsignal is low. A vertical dashed line indicates the start of the delayed break. Thetim_ocxnsignal transitions to high after a delay, labeled "Delayed break". - Middle section: Delayed break when low-side is on. The
tim_ocxsignal is low. Thetim_ocxnsignal is high. A vertical dashed line indicates the start of the delayed break. Thetim_ocxnsignal transitions to low after a delay, labeled "Delayed break". - Bottom section: Delayed break during deadtime. The
tim_ocxsignal is high. Thetim_ocxnsignal is low. A vertical dashed line indicates the start of the delayed break. Thetim_ocxnsignal transitions to high after a delay, labeled "Delayed break".
The diagram is labeled MSv75804V1.
The delay programming is identical to deadtime generator's, with 2 user-programmable durations in the TIM_MPR2 register: DBK1[7:0] bitfield for the Delayed 1 break and DBK2[7:0] bitfield for the Delayed 2 break.
DBK1[7:0] and DBK2[7:0] bitfields are preloaded: they can be changed during timer operation, and the new value is transferred to the active register when an update event occurs.
DBK1[7:0] and DBK2[7:0] bitfields are partially preloaded: they can be changed during timer operation, and the new value is transferred to the active register when an update event occurs.
The bits coding for \(t_{DTG}\) selection are not preloaded.
It is thus recommended to update only the least significant bits to have the expected duration value:
- • DBKx[6:0] if DBKx[7] = 0
- • DBKx[5:0] if DBKx[7:6] = 10
- • DBKx[4:0] if DBKx[7:5] = 110 or 111
The BKMx[1:0] and BKMxN[1:0] bits are static, they can only be modified when the counter is stopped (CEN=0 in TIM_CR1).
The content of the TIM_MPR1 and TIM_MPR2 register can be write protected using the LOCK[1:0] bits in the TIM_BDTR register.
31.3.21 Bidirectional break inputs
The TIM1/TIM8 feature bidirectional break I/Os, as represented on Figure 276.
This provides support for:
- • A board-level global break signal available for signaling faults to external MCUs or gate drivers, with a unique pin being both an input and an output status pin.
- • Internal break sources and multiple external open drain sources ORed together to trigger a unique break event, when multiple internal and external break sources must be merged.
The tim_brk and tim_brk2 inputs are configured in bidirectional mode using the BKBID and BK2BID bits in the TIM_BDTR register. The BKBID programming bits can be locked in read-only mode using the LOCK bits in the TIM_BDTR register (in LOCK level 1 or above).
The bidirectional mode is available for both the tim_brk and tim_brk2 inputs, and require the I/O to be configured in open-drain mode with active low polarity (using BKINP, BKP, BK2INP and BK2P bits). Any break request coming either from system (for example CSS), from on-chip peripherals, or from break inputs forces a low level on the break input to signal the fault event. The bidirectional mode is inhibited if the polarity bits are not correctly set (active high polarity), for safety purposes.
The break software events (BG and B2G) also cause the break I/O to be forced to 0 to indicate to the external components that the timer is entered in break state. However, this is valid only if the break is enabled (BKE or B2KE= 1). When a software break event is generated with BKE or B2KE= 0), the outputs are put in safe state and the break flag is set, but there is no effect on the TIM_BKIN and TIM_BKIN2 I/Os.
A safe disarming mechanism prevents the system to be definitively locked-up (a low level on the break input triggers a break which enforces a low level on the same input).
When the BKDSRM(BK2DSRM) bit is set to 1, this releases the break output to clear a fault signal and to give the possibility to re-arm the system.
At no point the break protection circuitry can be disabled:
- • The break input path is always active: a break event is active even if the
BKDSRM(BK2DSRM) bit is set and the open drain control is released. This prevents the PWM output to be restarted as long as the break condition is present. - • The
BKDSRM(BK2DSRM) bit cannot disarm the break protection as long as the outputs are enabled (MOEbit is set) (see Table 298).
Table 298. Break protection disarming conditions
| MOE | BKBID (BK2BID) | BKDSRM (BK2DSRM) | Break protection state |
|---|---|---|---|
| 0 | 0 | X | Armed |
| 0 | 1 | 0 | Armed |
| 0 | 1 | 1 | Disarmed |
| 1 | X | X | Armed |
Arming and rearming break circuitry
The break circuitry (in input or bidirectional mode) is armed by default (peripheral reset configuration).
The following procedure must be followed to re-arm the protection after a break (break2) event:
- • The BKDSRM (BK2DSRM) bit must be set to release the output control.
- • The software must wait until the system break condition disappears (if any) and clear the SBIF status flag (or clear it systematically before rearming).
- • The software must poll the BKDSRM (BK2DSRM) bit until it is cleared by hardware (when the application break condition disappears).
From this point, the break circuitry is armed and active, and the MOE bit can be set to re-enable the PWM outputs.
Figure 276. Output redirection (tim_brk2 request not represented)
![Block diagram of output redirection circuitry. It shows inputs from 'Other break inputs' and 'AF input (active low)' (via a Schmitt trigger) entering an 'AF controller'. The AF controller outputs 'tim_brk_cmp[8:1]' to a 4-input OR gate and 'BKIN inputs from AF controller' to a 'Filter'. The OR gate output goes to 'BKF[3:0]'. The 'Filter' output goes to 'BKP'. 'BKF[3:0]' and 'BKP' are inputs to a 2-input OR gate. The output of this OR gate goes to 'BKE'. 'tim_sys_brk' is an input to an OR gate that produces the 'SBIF flag'. 'BKE' and 'Software break requests: BG' are inputs to an OR gate that produces the 'BIF flag'. The 'BIF flag' is the 'BRK request' to 'tim_brk'. A 'Bidirectional mode control logic' block has inputs from 'System break request' and 'tim_brk request', and outputs 'MOE', 'BKBID', and 'BKDSRM'. A 'Bidirectional Break I/O TIM_BKIN' block has an input and is connected to the 'AF output (open drain)' which is pulled down to 'Vss'.](/RM0522-STM32C5/37c7981bbd8d94e00e409111036c7b75_img.jpg)
MSv62340V2
31.3.22 Output idle state override
It is possible to override the outputs states when they are disabled (ie MOE bit reset in TIM_BDTR). This feature can be used to apply specific patterns prior to start PWM operations, for instance to refresh bootstrap capacitors of power switch gate drivers.
The OOC control bit in the TIM_OOR register acts as following:
- • OOC= 0: 0: tim_ocx and tim_ocxn outputs are in the default idle state
- • OOC=1: tim_ocx and tim_ocxn outputs are forced in an idle state defined with OOSx/OOSxN bits in the TIM_OOR register
The OOC bit can only be modified when the outputs are in idle state (MOE = 0). It is cleared by hardware when the MOE bit is set, and the deadtime generator ensures there's no deadtime violation on complementary outputs.
The OOSx/OOSxN bits in the TIM_OOR register cannot be modified as long as LOCK level 1, 2 or 3 has been programmed (LOCK bits in TIM_BDTR register).
31.3.23 Clearing the tim_ocxref signal on an external event
The tim_ocxref signal of a given channel can be cleared when a high level is applied on the tim_ocref_clr_int input (OCxCE enable bit in the corresponding TIM_CCMRx register set to 1). tim_ocxref remains low until the next transition to the active state, on the following PWM cycle. This function can only be used in Output compare and PWM modes. It must not be used in Forced mode. tim_ocref_clr_int input can be selected between the tim_ocref_clr input and tim_etr(tim_etr_in after the filter) by configuring the OCCS bit in the TIM_SMCR register.
The tim_ocref_clr input can be selected among several inputs, using the OCRSEL[3:0] bitfield in the TIM_AF2 register, as shown on the Figure 277 below. Refer to Section 31.3.2: TIM1/TIM8 pins and internal signals for a list of sources available in the product.
Figure 277. tim_ocref_clr input selection multiplexer
![Block diagram of the tim_ocref_clr input selection multiplexer. It shows two multiplexers. The first multiplexer, controlled by TIM_AF2 OCRSEL[3:0], selects from inputs tim_ocref_clr0 to tim_ocref_clr15 to produce the tim_ocref_clr signal. The second multiplexer, controlled by TIM_SMCR OCCS, selects between tim_ocref_clr and tim_etr to produce the final tim_ocref_clr_int signal. The reference ID MSv80505V1 is in the bottom right corner.](/RM0522-STM32C5/ea8bf7bb4ac8f51d778e342643da4df8_img.jpg)
When tim_etr is chosen, tim_etr_in must be configured as follows:
- 1. The external trigger prescaler must be kept off: bits ETPS[1:0] of the TIM_SMCR register set to 00.
- 2. The external clock mode 2 must be disabled: bit ECE of the TIM_SMCR register set to 0.
- 3. The external trigger polarity (ETP) and the external trigger filter (ETF) can be configured according to application needs (as per polarity of the source connected to the trigger and eventual need to remove noise using the filter).
Figure 278 shows the behavior of the tim_ocxref signal when the tim_etr input becomes high, for both values of the enable bit OCxCE. In this example, the timer TIMx is programmed in PWM mode.
Figure 278. Clearing TIMx tim_ocxref

MSv62342V1
Note: In case of a PWM with a 100% duty cycle (if CCRx>ARR), then tim_ocxref is enabled again at the next counter overflow.
This feature is also supported in combined and asymmetric modes. In this case, it is mandatory to have the OCxCE bit enabled for the channel, the OCxCE bit of the complementary channel (e.g. OC2CE = X for oc2ref in Figure 279) is ignored in this case.
Figure 279 to Figure 282 are describing the output waveforms for some use cases, when the ocref_clr_int signal is asserted.
Figure 279. Asymmetric PWM mode 1

MSv76623V1
Figure 280. Asymmetric PWM mode 2

The diagram illustrates Asymmetric PWM mode 2. It features two triangular carrier waves, CC1 and CC2, where CC2 has a higher peak than CC1. The output signals are as follows:
- oc1ref: A PWM signal whose high level is determined by the intersection of the rising edge of CC1 and the falling edge of CC2.
- oc2ref: A PWM signal whose high level is determined by the intersection of the rising edge of CC2 and the falling edge of CC1.
- oc1refc (OC1CE = OC2CE = 0): The complementary signal of oc1ref.
- oc1refc (OC1CE = 1, OC2CE = X): This signal is cleared to a low state upon an ocref_clr_int event, indicated by an arrow pointing to a low pulse.
MSv76624V1
Figure 281. Asymmetric PWM mode 7 (OC1refc = oc1ref OR oc5ref)

The diagram illustrates Asymmetric PWM mode 7. It features two triangular carrier waves, CC1 and CC5, where CC5 has a higher peak than CC1. The output signals are as follows:
- oc1ref: A PWM signal whose high level is determined by the intersection of the rising edge of CC1 and the falling edge of CC5.
- oc5ref: A PWM signal whose high level is determined by the intersection of the rising edge of CC5 and the falling edge of CC1.
- oc1refc (OC1CE = OC5CE = 0): The complementary signal of oc1ref.
- oc1refc (OC1CE = 1, OC5CE = X): This signal is cleared to a low state upon an ocref_clr_int event, indicated by an arrow pointing to a low pulse.
- oc1refc (OC1CE = 1, OC5CE = X): This signal is cleared to a low state upon an ocref_clr_int event, indicated by an arrow pointing to a low pulse.
MSv76625V1
Figure 282. Combined PWM mode 1

The diagram illustrates the timing of various signals in Combined PWM mode 1. At the top, a sawtooth ramp represents the counter, with a 'Counter reset' indicated by a downward arrow. Two horizontal dashed lines represent the compare levels CC1 and CC2. Below the ramp, the following signals are shown:
- oc1ref: A PWM signal where the output is high when the counter is below CC1 and low otherwise.
- oc2ref: A PWM signal where the output is high when the counter is below CC2 and low otherwise.
- oc1refc (OC1CE = OC2CE = 0): The complementary output of oc1ref.
- oc1refc (OC1CE = 1, OC2CE = X): Shows a forced low state (indicated by a downward arrow labeled 'ocref_clr_int') when the counter reaches CC2.
- oc1refc (OC1CE = 1, OC2CE = X): Shows a forced low state (indicated by a downward arrow labeled 'ocref_clr_int') when the counter reaches CC1.
- oc1refc (OC1CE = 1, OC2CE = X): Shows a forced low state (indicated by a downward arrow labeled 'ocref_clr_int') when the counter reaches CC2.
MSv76626V2
Conditions of use
This feature is intended to support cycle-by-cycle current control loops, typically with a comparator shortening the PWM on-time when a current threshold is exceeded.
It cannot be used for the following modes, where the OCxCE bit must be cleared:
- • PWM toggle mode (OCxM[4:0] = 0x03)
- • One pulse mode with PWM active on match (OPM=1 and OCxM[4:0] = 0x06, 0x08, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18)
- • Combined 3-phase modes (GC5Cx or GC5CxO = 1)
- • Combined PWM mode 1 or 3 in center aligned mode (CMS[1:0] = 1,2,3 and OCxM[4:0] = 0x0C or 0x10)
31.3.24 6-step PWM generation
When complementary outputs are used on a channel, preload bits are available on the OCxM, CCxE, and CCxNE bits. The preload bits are transferred to the shadow bits at the COM commutation event. Thus one can program in advance the configuration for the next step and change the configuration of all the channels at the same time. COM can be generated by software by setting the COM bit in the TIM_EGR register or by hardware (on tim_trgi rising edge).
A flag is set when the COM event occurs (COMIF bit in the TIM_SR register), which can generate an interrupt (if the COMIE bit is set in the TIM_DIER register) or a DMA request (if the COMDE bit is set in the TIM_DIER register).
Figure 283 describes the behavior of the tim_ocx and tim_ocxn outputs when a COM event occurs, in three different examples of programmed configurations.
Figure 283. 6-step generation, COM example (OSSR = 1)

The diagram illustrates the 6-step generation process for the COM example (OSSR = 1). It shows the timing of the Counter (CNT), tim_ocxref, COM event, and output signals tim_ocx and tim_ocxn across three examples.
Example 1:
- Initial configuration: CCxE = 1, CCxNE = 0, OCxM = 0010 (forced inactive).
- Step 1: Write OCxM to 0100.
- Step 2: Write COM to 1.
- Final configuration: CCxE = 1, CCxNE = 0, OCxM = 0100.
Example 2:
- Initial configuration: CCxE = 1, CCxNE = 0, OCxM = 0100 (forced inactive).
- Step 1: Write CCxNE to 1 and OCxM to 0101.
- Step 2: Write COM to 1.
- Final configuration: CCxE = 0, CCxNE = 1, OCxM = 0101.
Example 3:
- Initial configuration: CCxE = 1, CCxNE = 0, OCxM = 0010 (forced inactive).
- Step 1: Write CCxNE to 0 and OCxM to 0100.
- Step 2: Write COM to 1.
- Final configuration: CCxE = 1, CCxNE = 1, OCxM = 0100.
MSv62343V1
31.3.25 One-pulse mode
One-pulse mode (OPM) is a particular case of the previous modes. It allows the counter to be started in response to a stimulus and to generate a pulse with a programmable length after a programmable delay.
Starting the counter can be controlled through the slave mode controller. Generating the waveform can be done in output compare mode or PWM mode. One-pulse mode is selected by setting the OPM bit in the TIM_CR1 register. This makes the counter stop automatically at the next update event UEV.
A pulse can be correctly generated only if the compare value is different from the counter initial value. Before starting (when the timer is waiting for the trigger), the configuration must be:
- • In upcounting: CNT < CCRx ≤ ARR (in particular, 0 < CCRx)
- • In downcounting: CNT > CCRx
Figure 284. Example of one pulse mode.

The diagram illustrates the timing for one pulse mode. It shows four signals over time: tim_ti2, tim_oc1ref, tim_oc1, and the Counter (with levels TIM_ARR and TIM_CCR1). A positive edge on tim_ti2 triggers the counter to start at 0. The counter increments in steps until it reaches TIM_CCR1, which occurs after a delay \(t_{DELAY}\). At this point, tim_oc1 transitions from low to high. The counter continues to increment until it reaches TIM_ARR, which occurs after a pulse width \(t_{PULSE}\). At this point, tim_oc1 transitions from high to low. The counter then resets to 0. The horizontal axis is labeled t and the vertical axis for the counter is labeled Counter. The reference signal tim_oc1ref is high during the \(t_{PULSE}\) period and low otherwise. The reference signal tim_oc1ref is high during the \(t_{PULSE}\) period and low otherwise.
In the following example, the user wants to generate a positive pulse on tim_oc1 with a length of \(t_{PULSE}\) and after a delay of \(t_{DELAY}\) as soon as a positive edge is detected on the tim_ti2 input pin.
Use tim_ti2fp2 as trigger 1:
- • Map tim_ti2fp2 to tim_ti2 by writing CC2S = 01 in the TIM_CCMR1 register.
- • tim_ti2fp2 must detect a rising edge, write CC2P = 0 and CC2NP = 0 in the TIM_CCER register.
- • Configure tim_ti2fp2 as trigger for the slave mode controller (tim_trgi) by writing TS = 00110 in the TIM_SMCR register.
- • tim_ti2fp2 is used to start the counter by writing SMS to 110 in the TIM_SMCR register (trigger mode).
The OPM waveform is defined by writing the compare registers (taking into account the clock frequency and the counter prescaler).
- • The \(t_{DELAY}\) is defined by the value written in the TIM_CCR1 register.
- • The \(t_{PULSE}\) is defined by the difference between the autoreload value and the compare value (TIM_ARR - TIM_CCR1).
- • Suppose the user wants to build a waveform with a transition from 0 to 1 when a compare match occurs and a transition from 1 to 0 when the counter reaches the auto-reload value. This is achieved by enabling PWM mode 2 (OC1M = 00111 in TIM_CCMR1). Optionally the preload registers can be enabled by writing OC1PE = 1 in the TIM_CCMR1 register and ARPE in the TIM_CR1 register. In this case one has to write the compare value in the TIM_CCR1 register, the autoreload value in the TIM_ARR register, generate an update by setting the UG bit and wait for external trigger event on tim_ti2. CC1P is written to 0 in this example.
In this example, the DIR and CMS bits in the TIM_CR1 register must be low.
Since only one pulse (Single mode) is needed, a 1 must be written in the OPM bit in the TIM_CR1 register to stop the counter at the next update event (when the counter rolls over)
from the autoreload value back to 0). When OPM bit in the TIM_CR1 register is set to 0, so the Repetitive mode is selected.
Particular case: tim_ocx fast enable:
In One-pulse mode, the edge detection on tim_tix input set the CEN bit which enables the counter. Then the comparison between the counter and the compare value makes the output toggle. But several clock cycles are needed for these operations and it limits the minimum delay tDELAY min that can be achieved.
To output a waveform with the minimum delay, the OCxFE bit can be set in the TIM_CCMRx register. Then tim_ocxref (and tim_ocx) are forced in response to the stimulus, without taking in account the comparison. Its new level is the same as if a compare match had occurred. OCxFE acts only if the channel is configured in PWM1 or PWM2 mode.
31.3.26 Retriggerable One-pulse mode
This mode allows the counter to be started in response to a stimulus and to generate a pulse with a programmable length, but with the following differences with nonretriggerable one-pulse mode described in Section 31.3.25:
- • The pulse starts as soon as the trigger occurs (no programmable delay). • The pulse is extended if a new trigger occurs before the previous one is completed.
The timer must be in Slave mode, with the bits SMS[4:0] = 01000 (Combined Reset + trigger mode) in the TIM_SMCR register, and the OCxM[4:0] bits set to 01000 or 01001 for retriggerable OPM mode 1 or 2.
If the timer is configured in Up-counting mode, the corresponding CCRx must be set to 0 (the ARR register sets the pulse length). If the timer is configured in Down-counting mode, CCRx must be above or equal to ARR.
Note: The OCxM[4:0] and SMS[4:0] bitfields are split into two parts for compatibility reasons, the most significant bit are not contiguous with the three least significant ones. This mode must not be used with center-aligned PWM modes. It is mandatory to have CMS[1:0] = 00 in TIM_CR1.
Figure 285. Retriggerable one-pulse mode

31.3.27 Pulse on compare mode
A pulse can be generated upon compare match event. A signal with a programmable pulsewidth generated when the counter value equals a given compare value, for debugging or synchronization purposes.
This mode is available for any slave mode selection, including encoder modes, in edge and center aligned counting modes. It is solely available for channel 3 and channel 4. The pulse generator is unique and is shared by the two channels, as shown on Figure 286.
Figure 286. Pulse generator circuitry
![Block diagram of the Pulse generator circuitry showing CCR3 match and CCR4 match inputs passing through enable blocks controlled by OC3M = 1010 and OC4M = 1010, fed into an OR gate that drives the Pulse generator block configured by PWPRSC[2:0] and PW[7:0]. The circuitry controls R/S latches and AND gates to produce tim_oc3 and tim_oc4 outputs. Document reference MSv62346V1 at bottom right.](/RM0522-STM32C5/015d452001804c64d2dbed2657cf9aa4_img.jpg)
Figure 287 shows how the pulse is generated for edge-aligned and encoder operating modes.
Figure 287. Pulse generation on compare event, for edge-aligned and encoder modes

The figure contains two timing diagrams illustrating pulse generation on compare events.
Top Diagram (Edge-aligned mode): Shows a counter ramping up. A horizontal dashed line represents the CMP3 threshold. Vertical dashed lines indicate triggers. The tim_ocx output is a pulse that starts at a trigger and has a fixed width. A second trigger occurring while the first pulse is active results in an "Extended pulsewidth due to re-trigger".
Bottom Diagram (Encoder mode): Shows a counter ramping up and then ramping down. Triggers are shown at the edges of the counter. The tim_ocx output pulses are generated at these trigger points.
MSv62347V1
This output compare mode is selected using the OC3M[3:0] and OC4M[3:0] bitfields in TIM_CCMR2 register.
The pulsewidth is programmed using the PW[7:0] bitfield in the register, using a specific clock prescaled according to PWPRSC[2:0] bits, as follows:
gives the resolution and maximum values depending on the prescaler value.
The pulse is retriggerable: a new trigger while the pulse is ongoing, causes the pulse to be extended.
Note: If the two channels are enabled simultaneously, the pulses are issued independently as long as the trigger on one channel is not overlapping the pulse generated on the concurrent output. On the opposite, if the two triggers are overlapping, the pulse width related to the first arriving trigger is extended (because of the retrigger), while the pulse width of the last arriving trigger is correct (as shown on Figure 288).
Figure 288. Extended pulsewidth in case of concurrent triggers

The diagram illustrates the behavior of two timer outputs, tim_oc3 and tim_oc4, in response to concurrent triggers from two compare units, CMP3 and CMP4. The triggers are represented by vertical dashed lines with downward arrows. tim_oc3 is shown as a square wave. When a CMP4 trigger occurs while tim_oc3 is high, the high pulse is extended until the end of the CMP4 trigger's active period, as indicated by a dashed box and the text "Extended pulsewidth due to overlapping CMP4 trigger". Similarly, tim_oc4 is shown as a square wave that is extended when a CMP3 trigger occurs during its high state. The diagram is labeled "MSv62348V1" in the bottom right corner.
31.3.28 Encoder interface mode
Quadrature encoder
To select Encoder Interface mode write SMS = 0001 in the TIM_SMCR register if the counter is counting on tim_ti1 edges only, SMS = 0010 if it is counting on tim_ti2 edges only and SMS = 0011 if it is counting on both tim_ti1 and tim_ti2 edges.
Select the tim_ti1 and tim_ti2 polarity by programming the CC1P and CC2P bits in the TIM_CCER register. When needed, the input filter can be programmed as well. CC1NP and CC2NP must be kept low.
The two inputs tim_ti1 and tim_ti2 are used to interface to a quadrature encoder. Refer to Table 299. The counter is clocked by each valid transition on tim_ti1fp1 or tim_ti2fp2(tim_ti1 and tim_ti2 after input filter and polarity selection, tim_ti1fp1= tim_ti1 if not filtered and not inverted, tim_ti2fp2= tim_ti2 if not filtered and not inverted) assuming that it is enabled (CEN bit in TIM_CR1 register written to 1). The sequence of transitions of the two inputs is evaluated and generates count pulses as well as the direction signal. Depending on the sequence the counter counts up or down, the DIR bit in the TIM_CR1 register is modified by hardware accordingly. The DIR bit is calculated at each transition on any input (tim_ti1 or tim_ti2), whatever the counter is counting on tim_ti1 only, tim_ti2 only or both tim_ti1 and tim_ti2.
Encoder interface mode acts simply as an external clock with direction selection. This means that the counter just counts continuously between 0 and the autoreload value in the TIM_ARR register (0 to ARR or ARR down to 0 depending on the direction). So the TIM_ARR must be configured before starting. In the same way, the capture, compare, prescaler, repetition counter, trigger output features continue to work as normal. Encoder mode and External clock mode 2 are not compatible and must not be selected together.
In this mode, the counter is modified automatically following the speed and the direction of the quadrature encoder and its content, therefore, always represents the encoder's position. The count direction correspond to the rotation direction of the connected sensor. The table summarizes the possible combinations, assuming tim_ti1 and tim_ti2 do not switch at the same time.
Table 299. Counting direction versus encoder signals (CC1P = CC2P = 0)
| Active edge | SMS[4:0] | Level on opposite signal (tim_ti1fp1 for tim_ti2, tim_ti2fp2 for tim_ti1) | tim_ti1fp1 signal | tim_ti2fp2 signal | ||
|---|---|---|---|---|---|---|
| Rising | Falling | Rising | Falling | |||
| Counting on tim_ti1 only x1 mode | 01110 | High | Down | Up | No count | No count |
| Low | No count | No count | No count | No count | ||
| Counting on tim_ti2 only x1 mode | 01111 | High | No count | No count | Up | Down |
| Low | No count | No count | No count | No count | ||
| Counting on tim_ti1 only x2 mode | 00001 | High | Down | Up | No count | No count |
| Low | Up | Down | No count | No count | ||
| Counting on tim_ti2 only x2 mode | 00010 | High | No count | No count | Up | Down |
| Low | No count | No count | Down | Up | ||
| Counting on tim_ti1 and tim_ti2 x4 mode | 00011 | High | Down | Up | Up | Down |
| Low | Up | Down | Down | Up | ||
A quadrature encoder can be connected directly to the MCU without external interface logic. However, comparators are normally be used to convert the encoder's differential outputs to digital signals. This greatly increases noise immunity. The third encoder output which indicate the mechanical zero position, may be connected to the external trigger input and trigger a counter reset.
Figure 289 gives an example of counter operation, showing count signal generation and direction control. It also shows how input jitter is compensated where both edges are selected. This might occur if the sensor is positioned near to one of the switching points. For this example the configuration is the following:
- • CC1S = 01 (TIM_CCMR1 register, tim_ti1fp1 mapped on tim_ti1).
- • CC2S = 01 (TIM_CCMR1 register, tim_ti2fp2 mapped on tim_ti2).
- • CC1P = 0 and CC1NP = 0 (TIM_CCER register, tim_ti1fp1 noninverted, tim_ti1fp1 = tim_ti1).
- • CC2P = 0 and CC2NP = 0 (TIM_CCER register, tim_ti1fp2 noninverted, tim_ti1fp2= tim_ti2).
- • SMS = 0011 (TIM_SMCR register, both inputs are active on both rising and falling edges).
- • CEN = 1 (TIM_CR1 register, Counter enabled).
Figure 289. Example of counter operation in encoder interface mode.

MSv62349V1
Figure 290 gives an example of counter behavior when tim_ti1fp1 polarity is inverted (same configuration as above except CC1P = 1).
Figure 290. Example of encoder interface mode with tim_ti1fp1 polarity inverted.

MSv62350V1
Figure 291 shows the timer counter value during a speed reversal, for various counting modes.
Figure 291. Quadrature encoder counting modes

The diagram illustrates the timing relationship between the quadrature encoder signals and the counter values. The signals shown are:
- tim_ti1: A square wave signal.
- tim_ti2: A square wave signal, phase-shifted relative to tim_ti1.
- DIR bit: A control signal that determines the counting direction. It is low for the first part of the diagram and transitions to high.
- Counter x4: A 32-bit counter showing values 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2.
- Counter x2: A 10-bit counter showing values 8, 9, 0, 1, 2, 1, 0, 9, 8, 7, 6.
- Counter x1: A 4-bit counter showing values 9, 0, 1, 0, 9, 8.
Vertical dashed lines indicate the timing of counter updates relative to the edges of tim_ti1 and tim_ti2. The counter values are shown in hexagonal boxes, indicating the state of the counter at specific points in time.
MSv62351V1
The timer, when configured in Encoder Interface mode provides information on the sensor's current position. Dynamic information can be obtained (speed, acceleration, deceleration) by measuring the period between two encoder events using a second timer configured in capture mode. The output of the encoder which indicates the mechanical zero can be used for this purpose. Depending on the time between two events, the counter can also be read at regular times. This can be done by latching the counter value into a third input capture register if available (then the capture signal must be periodic and can be generated by another timer). When available, it is also possible to read its value through a DMA request.
The IUFREMAP bit in the TIM_CR1 register forces a continuous copy of the update interrupt flag (UIF) into the timer counter register's bit 31 (TIM_CNT[31]). This allows both the counter value and a potential roll-over condition signaled by the UIFCPY flag to be read in an atomic way. It eases the calculation of angular speed by avoiding race conditions caused, for instance, by a processing shared between a background task (counter reading) and an interrupt (update interrupt).
There is no latency between the UIF and UIFCPY flag assertions.
In 32-bit timer implementations, when the IUFREMAP bit is set, bit 31 of the counter is overwritten by the UIFCPY flag upon read access (the counter's most significant bit is only accessible in write mode).
Clock plus direction encoder mode
In addition to the quadrature encoder mode, the timer offers support for other types of encoders.
In the clock plus direction mode shown on Figure 292, the clock is provided on a single line, on tim_ti2, while the direction is forced using the tim_ti1 input.
This mode is enabled with the SMS[4:0] bitfield in the TIM_SMCR register, as following:
- • 01010: x2 mode, the counter is updated on both rising and falling edges of the clock
- • 01011: x1 mode, the counter is updated on a single clock edge, as per CC2P bit value: CC2P = 0 corresponds to rising edge sensitivity and CC2P = 1 corresponds to falling edge sensitivity
The polarity of the direction signal on tim_ti1 is set with the CC1P bit: 0 corresponds to positive polarity (up-counting when tim_ti1 is high and down-counting when tim_ti1 is low) and CC1P= 1 corresponds to negative polarity (up-counting when tim_ti1 is low).
Figure 292. Direction plus clock encoder mode

The diagram illustrates the Direction plus clock encoder mode. It shows four signals over time: tim_ti1, tim_ti2, Counter x2 mode, and Counter x1 mode. tim_ti1 is a high-level signal that transitions to low. tim_ti2 is a clock signal. The Counter x2 mode signal shows a sequence of values: 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6. The Counter x1 mode signal shows a sequence of values: 6, 7, 8, 9, 8, 7. The transition from 11 to 10 in the Counter x2 mode occurs when tim_ti1 transitions from high to low.
Directional clock encoder mode
In the directional clock mode on Figure 293, the clocks are provided on two lines, with a single one at once, depending on the direction, so as to have one up-counting clock line and one down-counting clock line.
This mode is enabled with the SMS[4:0] bitfield in the TIM_SMCR register, as following:
- 01100: x2 mode, the counter is updated on both rising and falling edges of any of the two clock line. The
CC1PandCC2Pbits are coding for the clock idle state.CCxP= 0 corresponds to high-level idle state (refer to Figure 293) andCCxP= 1 corresponds to low-level idle state (refer to Figure 294). - 01101: x1 mode, the counter is updated on a single clock edge, as per
CC1PandCC2Pbit value.CCxP= 0 corresponds to falling edge sensitivity and high-level idle state (refer to Figure 293),CCxP= 1 corresponds to rising edge sensitivity and low-level idle state (refer to Figure 294).
Figure 293. Directional clock encoder mode (CC1P = CC2P = 0)

The diagram illustrates the Directional clock encoder mode with CC1P= CC2P= 0. It shows five signals over time: tim_ti1, tim_ti2, DIR bit, Counter x2 mode, and Counter x1 mode. tim_ti1 and tim_ti2 are clock signals. The DIR bit signal transitions from low to high. The Counter x2 mode signal shows a sequence of values: 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5. The Counter x1 mode signal shows a sequence of values: 6, 7, 8, 7, 6, 5. The transition from 11 to 10 in the Counter x2 mode occurs when the DIR bit transitions from low to high.
Figure 294. Directional clock encoder mode (CC1P = CC2P = 1)

MSv62354V1
Table 300 here-below details how the directional clock mode operates, for any input transition.
Table 300. Counting direction versus encoder signals and polarity settings
| Directional clock mode | SMS[4:0] | Level on opposite signal (tim_ti1fp1 for tim_ti2, tim_ti2fp2 for tim_ti1) | tim_ti1fp1 signal | tim_ti2fp2 signal | ||
|---|---|---|---|---|---|---|
| Rising | Falling | Rising | Falling | |||
| x2 mode CCxP = 0 | 01100 | High | Down | Down | Up | Up |
| Low | No count | No count | No count | No count | ||
| x2 mode CCxP = 1 | 01100 | High | No count | No count | No count | No count |
| Low | Down | Down | Up | Up | ||
| x1 mode CCxP = 0 | 01101 | High | No count | Down | No count | Up |
| Low | No count | No count | No count | No count | ||
| x1 mode CCxP = 1 | 01101 | High | No count | No count | No count | No count |
| Low | Down | No count | Up | No count | ||
Index input
The counter can be reset by an index signal coming from the encoder, indicating an absolute reference position. The index signal must be connected to the tim_etr_in input. It can be filtered using the digital input filter.
The index functionality is enabled with the IE bit in the TIM_ECR register. The IE bit must be set only in encoder mode, when the SMS[4:0] bitfield has the following values: 00001, 00010, 00011, 01010, 01011, 01100, 01101, 01110, 01111.
Available encoders are proposed with several options for index pulse conditioning, as per Figure 295:
- • gated with A and B: the pulsewidth is 1/4 of one channel period, aligned with both A and B edges
- • gated with A (or gated with B): the pulsewidth is 1/2 of one channel period, aligned with the two edges on channel A (resp. channel B)
- • ungated: the pulsewidth is up to one channel period, without any alignment to the edges
Figure 295. Index gating options

The circuitry tolerates jitter on index signal, whatever the gating mode, as show on Figure 296.
In ungated mode, the signal must be strictly below two encoder periods. If the pulsewidth is greater or equal to two encoder period, the counter is reset multiple times.
Figure 296. Jittered Index signals

The timer supports the three gating options identically, without any specific programming needed. It is only necessary to define on which encoder state (for example channel A and
channel B state combination) the index must be synchronized, using the IPOS[1:0] bitfield in the TIM_ECR register.
The index detection event acts differently depending on counting direction to ensure symmetrical operation during speed reversal:
- • The counter is reset during up-counting (DIR bit = 0).
- • The counter is set to TIM_ARR when down counting.
This allows the index to be generated on the very same mechanical angular position whatever the counting direction. Figure 297 shows at which position is the index generated, for a simplistic example (an encoder providing four edges par mechanical rotation).
Figure 297. Index generation for IPOS[1:0] = 11

Figure 298 presents waveforms and corresponding values for IPOS[1:0] = 11. It shows that the instant at which the counter value is forced is automatically adjusted depending on the counting direction:
- • Counter set to 0 when encoder state is 11 (ChA = 1, ChB = 1), when up-counting (DIR bit = 0).
- • Counter set to TIM_ARR when exiting the 11 state, when down-counting (DIR bit = 1).
An interrupt can be issued upon index detection event.
The arrows are indicating on which transition is the index event interrupt generated.
Figure 298. Counter reading with index gated on channel A (IPOS[1:0] = 11)

Figure 299. presents waveforms and corresponding values for the ungated mode. The arrows are indicating on which transition is the index event generated.
Figure 299. Counter reading with index ungated (IPOS[1:0] = 00)

The diagram shows the relationship between Channel A, Channel B, Index, DIR bit, and Counter in ungated mode. Channel A is a square wave. Channel B is a square wave that is 90 degrees out of phase with Channel A. The Index signal is a pulse that occurs on each Channel B transition. The DIR bit is high for the first half of the sequence and low for the second half. The Counter is shown as a sequence of 8-bit values (3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 7) that increments on Channel B rising edges and decrements on falling edges. Arrows indicate the specific transitions on Channel B that generate the index event.
Figure 300. shows how the 'gated on A & B' mode is handled, for various pulse alignment scenario. The arrows are indicating on which transition is the index event generated.
Figure 300. Counter reading with index gated on channel A and B

The diagram shows the relationship between Channel A, Channel B, Index, DIR bit, and Counter in gated mode. Channel A and Channel B are square waves. The Index signal is a pulse that occurs on each Channel B transition, but only when Channel A is in a specific state. The DIR bit is high for the first half of the sequence and low for the second half. The Counter is shown as a sequence of 8-bit values (5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1) that increments on Channel B rising edges and decrements on falling edges, but only when Channel A is in a specific state. Arrows indicate the specific transitions on Channel B that generate the index event.
Figure 301 and Figure 302 detail the case where the subsequent index pulse may be narrower than one quarter of the encoder clock period.
Figure 301. Encoder mode behavior in case of narrow index pulse (IPOS[1:0] = 11)

The figure consists of two timing diagrams, one above the other, illustrating encoder mode behavior with a narrow index pulse where IPOS[1:0] = 11. Both diagrams show the same set of signals: Channel A, Channel B, Index, DIR bit, and Counter.
Top Diagram: Index leading state transition
- Channel A: A square wave signal.
- Channel B: A square wave signal, 90 degrees out of phase with Channel A.
- Index: A narrow positive pulse. The leading edge of this pulse occurs while Channel B is high and Channel A is low.
- DIR bit: A signal that is low for the first half of the sequence and high for the second half. It transitions from low to high at the same time as the first Channel A falling edge.
- Counter: A 16-bit counter represented by a sequence of boxes labeled 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1. The counter increments on the falling edge of Channel A. The first increment (from 5 to 6) occurs before the Index pulse. The second increment (from 6 to 7) occurs during the Index pulse. The counter then wraps around to 0 and continues to increment.
Bottom Diagram: Index delayed versus state transition
- Channel A: A square wave signal.
- Channel B: A square wave signal, 90 degrees out of phase with Channel A.
- Index: A narrow positive pulse. The leading edge of this pulse occurs while Channel B is high and Channel A is low, but it is delayed relative to the first Channel A falling edge.
- DIR bit: A signal that is low for the first half of the sequence and high for the second half. It transitions from low to high at the same time as the first Channel A falling edge.
- Counter: A 16-bit counter represented by a sequence of boxes labeled 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1. The counter increments on the falling edge of Channel A. The first increment (from 5 to 6) occurs before the Index pulse. The second increment (from 6 to 7) occurs after the Index pulse has ended.
MSv45771V1
Figure 302. Counter reset Narrow index pulse (closer view, ARR = 0x07)

The figure consists of two identical timing diagrams stacked vertically. Each diagram shows the relationship between Channel A, Channel B, Index, DIR bit, and Counter over several cycles. Channel A and Channel B are square waves. The Index signal is a narrow pulse that occurs at the end of each cycle, coinciding with the transition of Channel B from high to low. The DIR bit is a constant low signal. The Counter is shown as a sequence of boxes labeled 5, 6, 7, 0, 1, 2, 3 in the top diagram and 4, 5, 6, 7, 0, 1, 2, 3 in the bottom diagram. Vertical dashed lines indicate the boundaries of the cycles. Arrows point from the Index signal to the Counter boxes, indicating the reset event.
MSv45772V1
Figure 303 shows how the index is managed in x1 and x2 modes.
Figure 303. Index behavior in x1 and x2 mode (IPOS[1:0] = 01)
![Timing diagram for Figure 303 showing Channel A, Channel B, Index, DIR bit, Counter x2, and Counter x1 signals. The diagram illustrates the index behavior in x1 and x2 modes when IPOS[1:0] = 01. Channel A and B are square waves. The Index signal is a pulse. The DIR bit is a logic level. Counter x2 and x1 show the counting sequence with index resets.](/RM0522-STM32C5/af3338c64e64175eb73d4755204f2cbd_img.jpg)
AB = IPOS[1:0] = 01
| Signal | Value/State |
|---|---|
| Channel A | Square wave |
| Channel B | Square wave |
| Index | Pulse |
| DIR bit | Logic level |
| Counter x2 | 10, 11, 0, 1, 2, 1, 0, 11, 10, 9, 8 |
| Counter x1 | 5, 6, 7, 0, 1, 3 |
MSv45773V1
Directional index sensitivity
The IDIR[1:0] bitfield in the TIM_ECR register allows the index to be active only in a selected counting direction.
Figure 304 shows the relationship between index and counter reset events, depending on IDIR[1:0] value.
Figure 304. Directional index sensitivity
![Timing diagram for Figure 304 showing DIR bit, Counter, Index input, and Counter reset signals for different IDIR[1:0] values. The diagram illustrates the relationship between index and counter reset events for UP-counting and Down-counting modes.](/RM0522-STM32C5/bfb17b941dd74e49a1ae614ba6077125_img.jpg)
DIR bit: UP-counting, Down-counting
| Signal | Value/State |
|---|---|
| Counter | Up-counting (sawtooth), Down-counting (sawtooth) |
| Index input | Pulses |
| IDIR[1:0]=00 | Counter reset |
| IDIR[1:0]=01 | Counter reset |
| IDIR[1:0]=10 | Counter reset |
MSv45774V1
Special first index event management
The FIDX bit in the TIM_ECR register allows the index to be taken only once, as shown on Figure 305. Once the first index has arrived, any subsequent index is ignored. If needed, the circuitry can be rearmed by writing the FIDX bit to 0 and setting it again to 1.
Figure 305. Counter reset as function of FIDX bit setting

The diagram illustrates the counter reset behavior based on the FIDX bit setting. It shows four signals over time: Counter, Index input, FIDX = 0, and FIDX = 1. The Counter signal is a sawtooth wave that resets to its initial value whenever an Index input pulse occurs. The Index input signal consists of several pulses. The FIDX = 0 signal is a constant low level. The FIDX = 1 signal is a constant high level. The Counter resets on every Index input pulse, regardless of the FIDX setting, as shown by the sawtooth wave resetting at each Index input pulse.
Index blanking
The index event can be blanked using the tim_ti3 or tim_ti4 inputs. During the blanking window, the index events are no longer resetting the counter, as shown on the Figure 306 below.
This mode is enabled using the IBLK[1:0] bitfield in the TIM_ECR register, as following:
- • IBLK[1:0] = 00: Index signal always active
- • IBLK[1:0] = 01: Index signal blanking on tim_ti3 input
- • IBLK[1:0] = 10: Index signal blanking on tim_ti4 input
Figure 306. Index blanking
![Timing diagram for Figure 306 showing Counter, Index input, Blanking signal TI3 (CC3P=0), and Counter reset signals for IBLK[1:0] = 00 and IBLK[1:0] = 01.](/RM0522-STM32C5/e420f43a55e05c45e85939d5a7d03b8e_img.jpg)
The diagram illustrates the index blanking behavior. It shows five signals over time: Counter, Index input, Blanking signal TI3 (CC3P=0), Counter reset (IBLK[1:0] = 00), and Counter reset (IBLK[1:0] = 01). The Counter signal is a sawtooth wave that resets to its initial value whenever an Index input pulse occurs, unless the Blanking signal is active. The Index input signal consists of several pulses. The Blanking signal TI3 (CC3P=0) is a rectangular pulse that is high during a specific time interval. The Counter reset (IBLK[1:0] = 00) signal is a constant low level. The Counter reset (IBLK[1:0] = 01) signal is a constant high level. The Counter resets on every Index input pulse that occurs when the Blanking signal is low. When the Blanking signal is high, the Counter does not reset on the Index input pulses, as shown by the sawtooth wave continuing without resetting.
Index management in nonquadrature mode
Figure 307 and Figure 308 detail how the index is managed in directional clock mode and clock plus direction mode, when the SMS[4:0] bitfield is equal to 01010, 01011, 01100, 01101.
For both of these modes, the index sensitivity is set with the IPOS[0] bit as following:
- • IPOS[0] = 0: Index is detected on clock low level
- • IPOS[0] = 1: Index is detected on clock high level
The IPOS[1] bit is not-significant.
Figure 307. Index behavior in clock + direction mode, IPOS[0] = 1
![Figure 307: Index behavior in clock + direction mode, IPOS[0] = 1, showing signals tim_ti1, tim_ti2, Index, Counter x2 mode, and Counter x1 mode with identifier MSv62355V1.](/RM0522-STM32C5/7736b0b7aef3526ceb13e819645bbaa6_img.jpg)
Figure 308. Index behavior in directional clock mode, IPOS[0] = 1
![Figure 308: Index behavior in directional clock mode, IPOS[0] = 1, showing signals tim_ti1, tim_ti2, DIR bit, Counter x2 mode, and Counter x1 mode with identifier MSv62356V1.](/RM0522-STM32C5/7518968efcc1be858fdf458f6350c9ff_img.jpg)
Encoder error management
For encoder configurations where two quadrature signals are available, it is possible to detect transition errors. The reading on the two inputs corresponds to a 2-bit gray code which can be represented as a state diagram, on Figure 309.. A single bit is expected to change at once. An erroneous transition sets the TERRF interrupt flag in the TIM_SR status
register. A transition error interrupt is generated if the TERRIE bit is set in the TIM_DIER register.
Figure 309. State diagram for quadrature encoded signals

The diagram shows four states represented by circles labeled 00, 01, 10, and 11. Correct transitions are indicated by solid double-headed arrows between adjacent states: 00 ↔ 01, 01 ↔ 11, 11 ↔ 10, and 10 ↔ 00. Erroneous transitions are indicated by dashed double-headed arrows between diagonal states: 00 ↔ 11 and 01 ↔ 10. A legend at the bottom left shows a solid double-headed arrow for 'Correct transitions' and a dashed double-headed arrow for 'Erroneous transitions'. The reference 'MSv45779V1' is located at the bottom right.
For encoder having an index signal, it is possible to detect abnormal operation resulting in an excess of pulses per revolution. An encoder with N pulses per revolution provides 4xN counts per revolution. The index signal resets the counter every 4xN clock periods.
If the counter value is incremented from TIM_ARR to 0 or decremented from 0 to TIM_ARR value without any index event, this is reported as an index position error.
The overflow threshold is programmed using the TIM_ARR register. A 1000 lines encoder results in a counter value being between 0 and 3999 (in 4x reading mode). The overflow detection threshold must be programmed by setting TIM_ARR = 3999+1 = 4000.
The error assertion is delayed to the transition 0 to 1 when in up-counting. This is cope with narrow index pulses in gated A and B mode, as shown on Figure 310.
Figure 310. Up-counting encoder error detection

The diagram illustrates two scenarios for up-counting encoder error detection, showing the relationship between tim_ti1, tim_ti2, Index, IERRF, and Counter signals.
Top Scenario: A narrow positive pulse on the Index signal occurs during the transition from counter value 7 to 0. An arrow labeled "Error detected" points to the start of this pulse. Another arrow labeled "Abort (index detection)" points to the end of the pulse, indicating the counter is aborted before reaching 0.
Bottom Scenario: A narrow positive pulse on the Index signal occurs during the transition from counter value 0 to 1. An arrow labeled "Error detected" points to the start of the pulse. A second arrow labeled "Error asserted" points to the rising edge of the IERRF signal, which occurs after the counter has transitioned to value 1.
Both scenarios show the counter values 5, 6, 7, 0, 1, 2, 3 in a sequence of trapezoids at the bottom. Vertical dashed lines align the transitions of tim_ti1 and tim_ti2 with the counter transitions.
MSv62357V1
In down-counting mode, the detection is conditioned by a preliminary transition from 1 to 0. This is to cope with narrow index pulses in gated A and B mode, as shown on Figure 311, to avoid any false error detection in case the encoder dithers between TIM_ARR and 0 immediately after the index detection.
Figure 311. Down-counting encode error detection

MSv80507V1
An index error sets the IERRF interrupt flag in the TIM_SR status register. An index error interrupt is generated if the IERRIE bit is set in the TIM_DIER register.
Functional encoder interrupts
The following interrupts are also available in encoder mode
- • Direction change: any change of the counting direction in encoder mode causes the DIR bit in the TIM_CR1 register to toggle. The direction change sets the DIRF interrupt flag in the TIM_SR status register. A direction change interrupt is generated if the DIRIE bit is set in the TIM_DIER register.
- • Index event: the index event sets the IDXF interrupt flag in the TIM_SR status register. An index interrupt is generated if the IDXIE bit is set in the TIM_DIER register.
Slave mode selection preload for run-time encoder mode update
It may be necessary to switch from one encoder mode to another during run-time. This is typically done at high-speed to decrease the update interrupt rate, by switching from x4 to x2 to x1 mode, as shown on Figure 312.
For this purpose, the SMS[4:0] bit can be preloaded. This is enabled by setting the SMSPE enable bit in the TIM_SMCR register. The trigger for the transfer from SMS[4:0] preload to active value can be selected with the SMSPS bit in the TIM_SMCR register.
- • SMSPS = 0: the transfer is triggered by the update event (UEV) occurring when the counter overflows when upcounting, and underflows when downcounting.
- • SMSPS = 1: the transfer is triggered by the index event.
Figure 312. Encoder mode change with preload transferred on update (SMSPS = 0)

The diagram illustrates the encoder mode change process. It is divided into three sections: x4 mode, x2 mode, and x1 mode. The 'Update event' row shows vertical pulses. The 'Preload value' row shows the SMS register value being updated to 0011, then 0001, and finally 1110. The 'Active value' row shows the current active SMS value, which changes from 0011 to 0001 and then to 1110 at the occurrence of an update event. The x4 mode shows three rapid cycles, x2 mode shows two slower cycles, and x1 mode shows one long cycle.
Encoder clock output
The encoder mode operating principle is not perfectly suited for high-resolution velocity measurements, at low speed, as it requires a relatively long integration time to have a sufficient number of clock edges and a precise measurement.
At low speed, a better solution is to do an edge-to-edge clock period measurement. This can be achieved using a slave timer. The timer can output the encoder clock information on the tim_trgo output. The slave timer can then perform a period measurement and provide velocity information for each and every encoder clock edge.
This mode is enabled by setting the MMS[3:0] bitfield to 1000, in the TIM_CR2 register. It is valid for the following SMS[4:0] values: 00001, 00010, 00011, 01010, 01011, 01100, 01101, 01110, 01111. Any other SMS[4:0] code is not allowed and may lead to unexpected behavior.
31.3.29 Encoder with built-in debouncer
This mode is intended to support noisy digital potentiometers and knobs, providing quadrature encoded signals with potentially long bouncing periods after each transition.
The operating principle consists of working on the first valid transition and discard any other until a second valid transition is detected on the alternate encoder signal.
The Figure 313 below represents the x2 operating mode. It must be noticed that a transition on input 1 is ignored during direction reversal, if there's no edge on input 2.
The Figure 314 below represents the x4 operating mode. In this case, a transition is always ignored during a direction reversal or when the encoder dithers between 2 positions.
These 2 modes are enabled by writing SMS[4:0] = 10000 or 10001 in TIM_SMCR register.
The encoder with built-in debouncer modes are not suitable for tracking a position or an angle in motor control applications. The transitions ignored during direction reversal will lead to a position/angle error that will build-up over time.
Figure 313. Encoder with built-in debouncer, x2 mode

The figure contains two separate timing diagrams for x2 mode. Each diagram shows the relationship between Input 1, Input 2, their debounced versions, the resulting Direction signal, and the Counter x2 value. In the first example, the counter sequence is 1, 2, 1, 0. In the second example, the counter sequence is 2, 1, 0, 1. The counter increments or decrements by 2 on valid direction changes, and ignores transitions during direction reversal.
MSv75806V1
Figure 314. Encoder with built-in debouncer, x4 mode

The figure shows a single timing diagram for x4 mode. It includes Input 1, Input 2, and their respective debounced signals. The Direction signal is derived from these inputs. The Counter x4 value follows a sequence of 1, 2, 3, 2, 1, 0, demonstrating increments and decrements by 4 on valid direction changes, while ignoring transitions during direction reversal or dithering.
MSv75807V2
31.3.30 Direction bit output
Its is possible to output a direction signal out of the timer, on the tim_oc3n and tim_oc4 output signals (copy of the DIR bit in the TIM_CR1 register). This is achieved by setting the OC3M[3:0] or the OC4M[3:0] bitfield to 1011 in the TIM_CCMR2 register.
This feature can be used for monitoring the counting direction (or rotation direction) in encoder mode, or to have a signal indicating the up/down phases in center-aligned PWM mode.
31.3.31 Clock drift measurement
It is possible to measure the drift between two clock sources using the directional clock encoder mode. This is useful for audio applications typically, when one need to compute the drift between two streams.
To do so, a signal representing the rate of a first audio stream must be connected to tim_ti1 and a signal representing the rate of a second audio stream must be connected to tim_ti2. The signals representing the audio rates are generally the SAIx_FS_A, SAIx_FS_B, SPIx_WS or spdifrx_frame_sync (this list of signals is provided as example and depends on the audio peripheral availability for a given product line, as detailed on the product datasheet).
In this case, the clocks are present on both tim_ti1 and tim2 simultaneously, as shown on Figure 315, and the counter value indicates the drift.
Let's define \(F_{tim\_ti1}\) and \(F_{tim\_ti2}\) the frequencies of the signals on tim_ti1 and tim_ti2. The counter value changes as following:
- • If \(F_{tim\_ti1} > F_{tim\_ti2}\) the counter value increases
- • If \(F_{tim\_ti1} < F_{tim\_ti2}\) the counter value decreases
- • If \(F_{tim\_ti1} = F_{tim\_ti2}\) the counter value dithers between two consecutive values, from one clock edge to the other. If the two clocks are perfectly synchronized (clock edges occuring simultaneously on the two inputs), the counter value does not change (as shown on Figure 315 below).
Figure 315. Clock drift measure using directional clock mode

The figure is a timing diagram illustrating clock drift measurement. It consists of three horizontal axes. The top axis shows two square wave signals, tim_ti1 and tim_ti2. The middle axis shows the Counter value as a staircase waveform. The diagram is divided into three regions by vertical dashed lines:
1. \(F_{tim\_ti1} > F_{tim\_ti2}\): The tim_ti1 signal has a higher frequency than tim_ti2. The counter value starts at 0x0000 and increments by 1 at each rising edge of tim_ti1 that occurs between tim_ti2 edges, reaching 0x0002.
2. \(F_{tim\_ti1} = F_{tim\_ti2}\): The two signals are perfectly synchronized. The counter value dithers between 0x0001 and 0x0002, changing at each clock edge.
3. \(F_{tim\_ti1} < F_{tim\_ti2}\): The tim_ti2 signal has a higher frequency. The counter value decrements by 1 at each rising edge of tim_ti2 that occurs between tim_ti1 edges, going from 0x0002 down to 0xFFFE.
The counter value axis is labeled with 0x0002, 0x0001, 0x0000, 0xFFFF, and 0xFFFE. The diagram is labeled MSv67593V1 in the bottom right corner.
31.3.32 UIF bit remapping
The IUFREMAP bit in the TIM_CR1 register forces a continuous copy of the update interrupt flag UIF into the timer counter register's bit 31 (TIM_CNT[31]). This allows both the counter value and a potential roll-over condition signaled by the UIFCPY flag to be read in an atomic way. In particular cases, it can ease the calculations by avoiding race conditions, caused for instance by a processing shared between a background task (counter reading) and an interrupt (update interrupt).
There is no latency between the UIF and UIFCPY flags assertion.
31.3.33 Timer input XOR function
The TI1S bit in the TIM_CR2 register, allows the input filter of channel 1 to be connected to the output of an XOR gate, combining the three input pins tim_ti1, tim_ti2 and tim_ti3.
The XOR output can be used with all the timer input functions such as trigger or input capture. It is convenient to measure the interval between edges on two input signals, as per Figure 316.
Figure 316. Measuring time interval between edges on three signals

The diagram illustrates the operation of the XOR gate for measuring time intervals. It shows five horizontal axes over time:
- tim_ti1: A square wave signal.
- tim_ti2: A square wave signal, phase-shifted relative to tim_ti1.
- tim_ti3: A square wave signal, phase-shifted relative to tim_ti1 and tim_ti2.
- XOR: The output of an XOR gate combining the three inputs. It is high when an odd number of inputs are high. Its rising edges are aligned with the rising edges of the input signals.
- TIMx Counter: A sawtooth waveform representing the timer counter. It increments on each rising edge of the XOR signal.
Vertical dashed lines indicate the timing of the rising edges of the input signals and the corresponding rising edges of the XOR output. The counter value increases linearly between these edges.
MSv75854V1
The XORPS control bit selects the position of the XOR gate, as shown on the Figure 317 and Figure 318 below, when the TI1S bit is set.
Figure 317. XOR gate connection with TI1S = 1 and XORPS = 0

Three control bits T1INV, T2INV and T3INV in the TIM_CR2 register can invert the tim_in1, tim_in2 and tim_in3 signals prior entering the XOR gate.
The status of the tim_in1, tim_in2, tim_in3 and tim_in4 signals can be software polled using the TI1FS, TI2FS, TI3FS and TI4FS bits in the TIM_SR register (tim_ti4 is not represented on figures above and do not enter into the XOR gate).
31.3.34 Interfacing with Hall sensors
This is done using the advanced-control timers to generate PWM signals to drive the motor and another timer TIMx referred to as “interfacing timer” in Figure 319. The “interfacing timer” captures the three timer input pins (tim_ti1, tim_ti2 and tim_ti3) connected through a XOR to the tim_ti1 input channel (selected by setting the TI1S bit in the TIM_CR2 register, with XORPS bit = 0).
The slave mode controller is configured in reset mode; the slave input is tim_ti1f_ed. Thus, each time one of the three inputs toggles, the counter restarts counting from 0. This creates a time base triggered by any change on the Hall inputs.
On the “interfacing timer”, capture/compare channel 1 is configured in capture mode, capture signal is tim_trc (See Figure 245). The captured value, which corresponds to the time elapsed between two changes on the inputs, gives information about motor speed.
The “interfacing timer” can be used in output mode to generate a pulse which changes the configuration of the channels of the advanced-control timer (by triggering a COM event). The advanced-control timer is used to generate PWM signals to drive the motor. To do this, the interfacing timer channel must be programmed so that a positive pulse is generated after a programmed delay (in output compare or PWM mode). This pulse is sent to the advanced-control timer through the tim_trgo output.
In this example the user wants to change the PWM configuration of the advanced-control timer after a programmed delay each time a change occurs on the Hall inputs connected to one of the TIMx timers.
- • Configure three timer inputs ORed to the tim_ti1 input channel by writing the TI1S bit in the TIM_CR2 register to 1.
- • Program the time base: write the TIM_ARR to the max value (the counter must be cleared by the tim_ti1 change. Set the prescaler to get a maximum counter period longer than the time between two changes on the sensors).
- • Program the channel 1 in capture mode (tim_trc selected): write the CC1S bits in the TIM_CCMR1 register to 01. The digital filter can also be programmed if needed.
- • Program the channel 2 in PWM 2 mode with the desired delay: write the OC2M bits to 111 and the CC2S bits to 00 in the TIM_CCMR1 register.
- • Select tim_oc2ref as trigger output on tim_trgo: write the MMS bits in the TIM_CR2 register to 101.
In the advanced-control timer, the right tim_itrx input must be selected as trigger input, the timer is programmed to generate PWM signals, the capture/compare control signals are preloaded (CCPC = 1 in the TIM_CR2 register) and the COM event is controlled by the trigger input (CCUS = 1 in the TIM_CR2 register). The PWM control bits (CCxE, OCxM) are written after a COM event for the next step (this can be done in an interrupt subroutine generated by the rising edge of tim_oc2ref).
Figure 319 describes this example.
Figure 319. Example of Hall sensor interface

The diagram illustrates the timing relationship between three Hall sensor inputs (tim_ti1, tim_ti2, tim_ti3) and the corresponding output signals (tim_oc1, tim_oc2, tim_oc3) and their complementary signals (tim_oc1n, tim_oc2n, tim_oc3n) for an advanced-control timer. The diagram is divided into two sections: 'Interfacing timer' and 'Advanced-control timers'.
In the 'Interfacing timer' section, the input signals (tim_ti1, tim_ti2, tim_ti3) are shown as square waves. The counter (CNT) and CCR2 signals are shown as sawtooth waves. The CCR1 register values are listed as C7A3, C7A8, C794, C7A5, C7AB, and C796. The tim_trgo = tim_oc2ref signal is shown as a square wave.
In the 'Advanced-control timers' section, the output signals (tim_oc1, tim_oc2, tim_oc3) and their complementary signals (tim_oc1n, tim_oc2n, tim_oc3n) are shown. The output signals are high-frequency pulses, while the complementary signals are low-frequency pulses. The diagram also shows the COM signal, which is a square wave.
Arrows at the bottom indicate the sequence of operations: 'Write CCxE, CCxNE and OCxM for next step'.
MSv62360V1
31.3.35 Timer synchronization
The TIMx timers are linked together internally for timer synchronization or chaining. Refer to Section 32.4.27: Timer synchronization for details. They can be synchronized in several modes: Reset mode, Gated mode, Trigger mode, Reset + trigger, and gated + reset modes.
Slave mode: Reset mode
The counter and its prescaler can be reinitialized in response to an event on a trigger input. Moreover, if the URS bit from the TIM_CR1 register is low, an update event UEV is generated. Then all the preloaded registers (TIM_ARR, TIM_CCRx) are updated.
In the following example, the upcounter is cleared in response to a rising edge on tim_ti1 input:
- • Configure the channel 1 to detect rising edges on
tim_ti1. Configure the input filter duration (in this example, we do not need any filter, so we keepIC1F = 0000). The capture prescaler is not used for triggering, so it does not need to be configured. TheCC1Sbits select the input capture source only,CC1S = 01in theTIM_CCMR1register. WriteCC1P = 0andCC1NP = 0inTIM_CCERregister to validate the polarity (and detect rising edges only). - • Configure the timer in reset mode by writing
SMS = 100inTIM_SMCRregister. Selecttim_ti1as the input source by writingTS = 00101inTIM_SMCRregister. - • Start the counter by writing
CEN = 1in theTIM_CR1register.
The counter starts counting on the internal clock, then behaves normally until tim_ti1 rising edge. When tim_ti1 rises, the counter is cleared and restarts from 0. In the meantime, the trigger flag is set (TIF bit in the TIM_SR register) and an interrupt request, or a DMA request can be sent if enabled (depending on the TIE and TDE bits in TIM_DIER register).
The following figure shows this behavior when the autoreload register TIM_ARR = 0x36. The delay between the rising edge on tim_ti1 and the actual reset of the counter is due to the resynchronization circuit on tim_ti1 input.
Figure 320. Control circuit in reset mode

Slave mode: Gated mode
The counter can be enabled depending on the level of a selected input.
In the following example, the upcounter counts only when tim_ti1 input is low:
- • Configure the channel 1 to detect low levels on
tim_ti1. Configure the input filter duration (in this example, we do not need any filter, so we keepIC1F = 0000). The capture prescaler is not used for triggering, so it does not need to be configured. TheCC1Sbits select the input capture source only,CC1S = 01inTIM_CCMR1register. WriteCC1P = 1andCC1NP = 0inTIM_CCERregister to validate the polarity (and detect low level only). - • Configure the timer in gated mode by writing
SMS = 101inTIM_SMCRregister. Selecttim_ti1as the input source by writingTS = 00101inTIM_SMCRregister. - • Enable the counter by writing
CEN = 1in theTIM_CR1register (in gated mode, the counter does not start ifCEN = 0, whatever is the trigger input level).
The counter starts counting on the internal clock as long as tim_ti1 is low and stops as soon as tim_ti1 becomes high. The TIF flag in the TIM_SR register is set both when the counter starts or stops.
The delay between the rising edge on tim_ti1 and the actual stop of the counter is due to the resynchronization circuit on tim_ti1 input.
Figure 321. Control circuit in Gated mode

Slave mode: Trigger mode
The counter can start in response to an event on a selected input.
In the following example, the upcounter starts in response to a rising edge on tim_ti2 input:
- • Configure the channel 2 to detect rising edges on tim_ti2. Configure the input filter duration (in this example, we do not need any filter, so we keep IC2F = 0000). The capture prescaler is not used for triggering, so it does not need to be configured. The CC2S bits are configured to select the input capture source only, CC2S = 01 in TIM_CCMR1 register. Write CC2P = 1 and CC2NP = 0 in TIM_CCER register to validate the polarity (and detect low level only). • Configure the timer in trigger mode by writing SMS = 110 in TIM_SMCR register. Select tim_ti2 as the input source by writing TS = 00110 in TIM_SMCR register.
When a rising edge occurs on tim_ti2, the counter starts counting on the internal clock and the TIF flag is set.
The delay between the rising edge on tim_ti2 and the actual start of the counter is due to the resynchronization circuit on tim_ti2 input.
Figure 322. Control circuit in trigger mode

MSv62363V1
Slave mode: Combined reset + trigger mode
In this case, a rising edge of the selected trigger input (tim_trgi) reinitializes the counter, generates an update of the registers, and starts the counter.
This mode is used for One-pulse mode.
Slave mode: Combined gated + reset mode
The counter clock is enabled when the trigger input (tim_trgi) is high. The counter stops and is reset) as soon as the trigger becomes low. Both start and stop of the counter are controlled.
This mode is used to detect out-of-range PWM signal (duty cycle exceeding a maximum expected value).
Slave mode: external clock mode 2 + trigger mode
The external clock mode 2 can be used in addition to another slave mode (except external clock mode 1 and encoder mode). In this case, the tim_etr_in signal is used as external clock input, and another input can be selected as trigger input (in reset mode, gated mode or trigger mode). It is recommended not to select tim_etr_in as tim_trgi through the TS bits of TIM_SMCR register.
In the following example, the upcounter is incremented at each rising edge of the tim_etr_in signal as soon as a rising edge of tim_ti1 occurs:
- 1. Configure the external trigger input circuit by programming the
TIM_SMCRregister as follows:- –
ETF = 0000: no filter - –
ETPS = 00: prescaler disabled - –
ETP = 0: detection of rising edges ontim_etr_inandECE = 1to enable the external clock mode 2.
- –
- 2. Configure the channel 1 as follows, to detect rising edges on TI:
- –
IC1F = 0000: no filter. - – The capture prescaler is not used for triggering and does not need to be configured.
- –
CC1S = 01inTIM_CCMR1register to select only the input capture source - –
CC1P = 0andCC1NP = 0inTIM_CCERregister to validate the polarity (and detect rising edge only).
- –
- 3. Configure the timer in trigger mode by writing
SMS = 110inTIM_SMCRregister. Selecttim_ti1as the input source by writingTS = 00101inTIM_SMCRregister.
A rising edge on tim_ti1 enables the counter and sets the TIF flag. The counter then counts on tim_etr_in rising edges.
The delay between the rising edge of the tim_etr_in signal and the actual reset of the counter is due to the resynchronization circuit on tim_etrp input.
Figure 323. Control circuit in external clock mode 2 + trigger mode

MSv62364V1
Note: The clock of the slave peripherals (such as timer, ADC) receiving the tim_trgo or the tim_trgo2 signals must be enabled prior to receive events from the master timer, and the clock frequency (prescaler) must not be changed on-the-fly while triggers are received from the master timer.
31.3.36 ADC triggers
The timer can generate an ADC triggering event with various internal signals, such as reset, enable or compare events. It is also possible to generate a pulse issued by internal edge detectors, such as:
- • Rising and falling edges of OC4ref
- • Rising edge on OC5ref or falling edge on OC6ref
Refer to MMS2[4:0] bitfield description in TIM_CR2 for the complete list of triggering options.
The triggers are issued on the tim_trgo2 internal line which is redirected to the ADC. There is a total of 24 possible events, which can be selected using the MMS2[4:0] bits in the TIM_CR2 register.
An example of an application for 3-phase motor drives is given in Figure 263.
Note: The clock of the slave peripherals (timer, ADC, ...) receiving the tim_trgo or the tim_trgo2 signals must be enabled prior to receive events from the master timer, and the clock frequency (prescaler) must not be changed on-the-fly while triggers are received from the master timer.
Note: The clock of the ADC must be enabled prior to receive events from the master timer, and must not be changed on-the-fly while triggers are received from the timer.
It is possible to reduce the ADC triggering rate with the tim_trgo2 post scaler. This is done by periodically discarding tim_trgo2 events, as per the value programmed in TGO2PSC[4:0] bitfield in TIM_CR1, as shown on Figure 324 below.
Figure 324. tim_trgo2 postscaler example
![Timing diagram showing Input, tim_trgo2 with TGO2PSC[4:0] = 0, tim_trgo2 with TGO2PSC[4:0] = 1, and tim_trgo2 with TGO2PSC[4:0] = 3. The diagram illustrates how the postscaler value affects the frequency of the tim_trgo2 signal relative to the input signal. For TGO2PSC[4:0] = 0, the output frequency is the same as the input. For TGO2PSC[4:0] = 1, the output frequency is halved. For TGO2PSC[4:0] = 3, the output frequency is quartered.](/RM0522-STM32C5/c867387e23beb2a9bb9a9adc54be7515_img.jpg)
MSv75810V1
The post scaler is able to operate with:
- – pulses as shown on Figure 324 above, when selecting for instance MMS2[4:0] = 10001 to have a trigger on tim_oc7refc rising rising or falling edges
- – the tim_ocxrefc signal itself (ie with user-defined duty cycle), when selecting for instance MMS2[4:0] = 10000 to have a trigger on tim_oc7refc
31.3.37 ADC synchronization
The timer operation can be synchronized to the ADC clock to trigger jitter-free ADC sampling. This function is enabled using the ADSYNC bit in the TIM_CR2 register.
This feature is useful when the timers and the ADCs are operating with semisynchronous clocks (clocks derived from a same source with integer ratio tim_ker_ck/adc_ker_ck), for instance adc_ker_ck = 75 MHz and tim_ker_ck = 150 MHz or 300 MHz.
ADSYNC must also be set when both peripherals are operating at the same frequency from the same clock source, when jitter-free operation is needed.
ADSYNC must not be set and jitter-free operation is not supported in the following cases:
- • when the clock ratio is not an integer (for example
adc_ker_ck= 75 MHz andtim_ker_ck= 100 MHz): in this case, the sampling point jitter due to the timer to ADC signal resynchronization is 1adc_ker_ckperiod maximum - • when the ADC is operating in asynchronous mode (
adc_ker_ckuncorrelated withtim_ker_ck): in this case, the sampling point jitter due to the timer to ADC signal resynchronization is 1adc_ker_ckperiod maximum.
When ADSYNC= 1, the timer operation is slightly changed: the counter enable and counter reset events are aligned to the adc_ker_ck ADC clock, to avoid any phase shift due to clocks enable in the RCC.
Jitter-free operation is guaranteed only when one of the two requirements below is met (depending on the selected trigger source).
- 1. The counter period must be a multiple of the ADC clock period:
- 2. The compare value must be a multiple of the ADC clock period:
Note: If none of the two above requirements are met, the trigger is still generated, but the latency is not constant and varies with the timer and ADC clocks phase shift.
Programming guidelines
The ADC synchronization feature must not be modified during run-time, once the counter is enabled and once the ADC has been configured for receiving triggers from the timer.
It is mandatory to follow the procedure below to use the ADC synchronization:
- 1. Enable the destination ADC clock.
- 2. Configure the timer and set the
ADSYNCbit. - 3. Configure the ADC and enable it (using
ADSTARTand/orJADSTARTbits). - 4. Start the timer (with the
CENcounter enable bit).
31.3.38 DMA burst mode
The TIMx timers have the capability to generate multiple DMA requests upon a single event. The main purpose is to be able to reprogram part of the timer multiple times without software overhead, but it can also be used to read several registers in a row, at regular intervals.
The DMA controller destination is unique and must point to the virtual register TIM_DMAR. On a given timer event, the timer launches a sequence of DMA requests (burst). Each write into the TIM_DMAR register is actually redirected to one of the timer registers.
The DBL[4:0] bits in the TIM_DCR register set the DMA burst length. The timer recognizes a burst transfer when a read or a write access is done to the TIM_DMAR address, i.e. the number of transfers (in words).
The DBA[4:0] bits in the TIM_DCR register define the DMA base address for DMA transfers (when read/write access are done through the TIM_DMAR address). DBA is defined as an offset starting from the address of the TIM_CR1 register:
Example:
00000: TIM_CR1
00001: TIM_CR2
00010: TIM_SMCR
The DBSS[3:0] bits in the TIM_DCR register defines the interrupt source that triggers the DMA burst transfers (see Section 31.6.34: TIM DMA control register (TIM_DCR) for details).
As an example, the timer DMA burst feature is used to update the contents of the CCRx registers (x = 2, 3, 4) upon an update event, with the DMA transferring half words into the CCRx registers.
This is done in the following steps:
- 1. Configure the corresponding DMA channel as follows:
- – DMA channel peripheral address is the DMAR register address.
- – DMA channel memory address is the address of the buffer in the RAM containing the data to be transferred by DMA into CCRx registers.
- – Number of data to transfer = 3 (see note below).
- – Circular mode disabled.
- 2. Configure the DCR register by configuring the DBA and DBL bitfields as follows:
DBL = 2, DBA = 0xE and DBSS = 1. - 3. Enable the TIMx update DMA request (set the UDE bit in the DIER register).
- 4. Enable TIMx.
- 5. Enable the DMA channel.
This example is for the case where every CCRx register to be updated once. If every CCRx register is to be updated twice for example, the number of data to transfer must be 6. Let's take the example of a buffer in the RAM containing data1, data2, data3, data4, data5, and data6. The data is transferred to the CCRx registers as follows: on the first update DMA request, data1 is transferred to CCR2, data2 is transferred to CCR3, data3 is transferred to CCR4 and on the second update DMA request, data4 is transferred to CCR2, data5 is transferred to CCR3, and data6 is transferred to CCR4.
Note: A null value can be written to the reserved registers.
31.3.39 TIM1/TIM8 DMA requests
The TIM1/TIM8 can generate a DMA request, as shown in the table below.
Table 301. DMA request
| DMA request signal | DMA request | Enable control bit |
|---|---|---|
| tim_upd_dma | Update | UDE |
| tim_cc1_dma | Capture/compare 1 | CC1DE |
| tim_cc2_dma | Capture/compare 2 | CC2DE |
| tim_cc3_dma | Capture/compare 3 | CC3DE |
Table 301. DMA request (continued)
| DMA request signal | DMA request | Enable control bit |
|---|---|---|
| tim_cc4_dma | Capture/compare 4 | CC4DE |
| tim_com_dma | Commutation (COM) | COMDE |
| tim_trgi_dma | Trigger | TDE |
31.3.40 Debug mode
When the microcontroller enters debug mode (Cortex-M33 core halted), the TIMx counter can either continue to work normally or stop, depending on DBG_TIM_STOP configuration bit in DBG module.
The behavior in debug mode can be programmed with a dedicated configuration bit per timer in the Debug support (DBG) module.
For safety purposes, when the counter is stopped, the outputs are disabled (as if the MOE bit was reset). The outputs can either be forced to an inactive state (OSSI bit = 1), or have their control taken over by the GPIO controller (OSSI bit = 0), typically to force a Hi-Z.
For more details, refer to section Debug support (DBG).
31.4 TIM1/TIM8 low-power modes
Table 302. Effect of low-power modes on TIM1/TIM8
| Mode | Description |
|---|---|
| Sleep | No effect, peripheral is active. The interrupts can cause the device to exit from Sleep mode. |
| Stop | The timer operation is stopped and the register content is kept. No interrupt can be generated. |
| Standby | The timer is powered-down and must be reinitialized after exiting the Standby mode. |
31.5 TIM1/TIM8 interrupts
The TIM1/TIM8 can generate multiple interrupts, as shown in Table 303.
Table 303. Interrupt requests
| Interrupt acronym | Interrupt event | Event flag | Enable control bit | Interrupt clear method | Exit from Sleep mode | Exit from Stop and Standby mode | |
|---|---|---|---|---|---|---|---|
| TIM_UPD | Update | UIF | UIE | write 0 in UIF | Yes | No | |
| TIM_CC | Capture/compare 1 | CC1IF | CC1IE | write 0 in CC1IF | Yes | No | |
| Capture/compare 2 | CC2IF | CC2IE | write 0 in CC2IF | Yes | No | ||
| Capture/compare 3 | CC3IF | CC3IE | write 0 in CC3IF | Yes | No | ||
| Capture/compare 4 | CC4IF | CC4IE | write 0 in CC4IF | Yes | No | ||
| TIM_TRGI_COM_DIR_IDX | TIM_COM | Commutation (COM) | COMIF | COMIE | write 0 in COMIF | Yes | No |
| TIM_TRGI | Trigger | TIF | TIE | write 0 in TIF | Yes | No | |
| TIM_IDX | Index | IDXF | IDXIE | write 0 in IDXF | Yes | No | |
| TIM_DIR | Direction | DIRF | DIRIE | write 0 in DIRF | Yes | No | |
| TIM_BRK_TERR_IERR | TIM_BRK | Break | BIF | BIE | write 0 in BIF | Yes | No |
| Break2 | B2IF | write 0 in B2IF | Yes | No | |||
| System Break | SBIF | write 0 in SBIF | Yes | No | |||
| TIM_IERR | Index Error | IERRF | IERRIE | write 0 in IERRF | Yes | No | |
| TIM_TERR | Transition Error | TERRF | TERRIE | write 0 in TERRF | Yes | No | |
31.6 TIM1/TIM8 registers
Refer to Section 1.2 for a list of abbreviations used in register descriptions.
The peripheral registers can be accessed by half-words (16-bit) or words (32-bit).
31.6.1 TIM control register 1 (TIM_CR1)
Address offset: 0x000
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | CKD2[3:0] | Res. | Res. | Res. | TGO2PSC[4:0] | |||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | |||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | DITHE N | UIFRE MAP | Res. | CKD[1:0] | ARPE | CMS[1:0] | DIR | OPM | URS | UDIS | CEN | ||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | ||||
Bits 31:28 Reserved, must be kept at reset value.
Bits 27:24 CKD2[3:0]: Clock division 2
This bit field indicates the division between sampling clock (\(t_{DTS}\)) used by the dead-time generators and the digital filters (tim_etr_in, tim_tix).
0000: No Division
0001: \(t_{DTS2} = 4 * t_{DTS}\)
0010: \(t_{DTS2} = 16 * t_{DTS}\)
0011: \(t_{DTS2} = 64 * t_{DTS}\)
0100: \(t_{DTS2} = 256 * t_{DTS}\)
0101: \(t_{DTS2} = 1024 * t_{DTS}\)
0110: \(t_{DTS2} = 4096 * t_{DTS}\)
0111: \(t_{DTS2} = 16384 * t_{DTS}\)
1000: \(t_{DTS2} = 65536 * t_{DTS}\)
1001: \(t_{DTS2} = 262144 * t_{DTS}\)
Others: Reserved, do not program this value
Bits 23:21 Reserved, must be kept at reset value.
Bits 20:16 TGO2PSC[4:0]: Trigger output 2 postcaler
The postcaler discards periodically events sent on the tim_trgo2 output, to reduce the ADC triggering rate.
The number of events on tim_trgo2 is divided by (TGO2PSC[4:0] + 1).
When TGO2PSC[4:0] = 0x0, the tim_trgo2 event rate is not affected.
With TGO2PSC[4:0] = 0x1, one event out of 2 is sent on tim_trgo2, with TGO2PSC[4:0] = 0x2, one event out of 3 is sent on tim_trgo2, up to 1 event out of 31 when TGO2PSC[4:0] = 0x1F,...
Note: The postcaler is only applicable when tim_trgo2 transfers a pulse (reset, update, compare pulse). When the tim_trgo2 outputs a level-based information (compare signal or enable bit for gated mode), the postcaler must be set set to 0
Bits 15:13 Reserved, must be kept at reset value.
- Bit 12 DITHER: Dithering enable
0: Dithering disabled
1: Dithering enabled
Note: The DITHER bit can only be modified when CEN bit is reset. - Bit 11 UIFREMAP: UIF status bit remapping
0: No remapping. UIF status bit is not copied to TIM_CNT register bit 31.
1: Remapping enabled. UIF status bit is copied to TIM_CNT register bit 31. - Bit 10 Reserved, must be kept at reset value.
- Bits 9:8 CKD[1:0]: Clock division
This bitfield indicates the division ratio between the timer clock (tim_ker_ck) frequency and the dead-time and sampling clock (\(t_{DTS}\)) used by the dead-time generators and the digital filters (tim_etr_in, tim_tix),
00: \(t_{DTS} = t_{tim\_ker\_ck}\)
01: \(t_{DTS} = 2 * t_{tim\_ker\_ck}\)
10: \(t_{DTS} = 4 * t_{tim\_ker\_ck}\)
11: \(t_{DTS} = 8 * t_{tim\_ker\_ck}\) - Bit 7 ARPE: Autoreload preload enable
0: TIM_ARR register is not buffered
1: TIM_ARR register is buffered - Bits 6:5 CMS[1:0]: Center-aligned mode selection
00: Edge-aligned mode. The counter counts up or down depending on the direction bit (DIR).
01: Center-aligned mode 1. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS = 00 in TIM_CCMRx register) are set only when the counter is counting down.
10: Center-aligned mode 2. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS = 00 in TIM_CCMRx register) are set only when the counter is counting up.
11: Center-aligned mode 3. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS = 00 in TIM_CCMRx register) are set both when the counter is counting up or down.
Note: It is not allowed to switch from edge-aligned mode to center-aligned mode as long as the counter is enabled (CEN = 1) - Bit 4 DIR: Direction
0: Counter used as upcounter
1: Counter used as downcounter
Note: This bit is read only when the timer is configured in Center-aligned mode or Encoder mode. - Bit 3 OPM: One-pulse mode
0: Counter is not stopped at update event
1: Counter stops counting at the next update event (clearing the bit CEN)
Bit 2 URS: Update request source
This bit is set and cleared by software to select the UEV event sources.
0: Any of the following events generate an update interrupt or DMA request if enabled.
These events can be:
- – Counter overflow/underflow
- – Setting the UG bit
- – Update generation through the slave mode controller
1: Only counter overflow/underflow generates an update interrupt or DMA request if enabled.
Bit 1 UDIS: Update disable
This bit is set and cleared by software to enable/disable UEV event generation.
0: UEV enabled. The Update (UEV) event is generated by one of the following events:
- – Counter overflow/underflow
- – Setting the UG bit
- – Update generation through the slave mode controller
Buffered registers are then loaded with their preload values.
1: UEV disabled. The Update event is not generated, shadow registers keep their value (ARR, PSC, CCRx). However 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.
Bit 0 CEN: Counter enable
0: Counter disabled
1: Counter enabled
Note: External clock, gated mode and encoder mode can work only if the CEN bit has been previously set by software. However trigger mode can set the CEN bit automatically by hardware.
31.6.2 TIM control register 2 (TIM_CR2)
Address offset: 0x004
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| TI3INV | TI2INV | TI1INV | ADSYN C | XORPS | Res. | MMS[3] | MMS2[4:0] | OIS7 | OIS6 | Res. | OIS5 | ||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | ||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| OIS4N | OIS4 | OIS3N | OIS3 | OIS2N | OIS2 | OIS1N | OIS1 | TI1S | MMS[2:0] | CCDS | CCUS | Res. | CCPC | ||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | |
Bit 31 TI3INV: tim_ti3 signal inversion on XOR gate input
0: tim_ti3 non-inverted
1: tim_ti3 inverted
Bit 30 TI2INV: tim_ti2 signal inversion on XOR gate input
0: tim_ti2 non-inverted
1: tim_ti2 inverted
Bit 29 TI1INV: tim_ti1 signal inversion on XOR gate input
0: tim_ti1 non-inverted
1: tim_ti1 inverted
Bit 28 ADSYNC: ADC synchronization
0: The timer operates independently from the ADC
1: The timer operation is synchronized with the ADC clock to provide jitter-free sampling point. This mode can be enabled only with specific ADC / timer clock relationship. Refer to Section 31.3.37 for requirements.
The ADSYNC must not be modified when the counter is enabled (CEN bit is set).
Bit 27 XORPS: XOR gate position selection
This bit defines the position of the XOR gate with respect to input filters.
0: XOR gate placed before TI1 filter
1: XOR gate placed after TI1, TI2 and TI3 filters
Bit 26 Reserved, must be kept at reset value.
Bits 24:20 MMS2[4:0]: Master mode selection 2
These bits allow the information to be sent to ADC for synchronization (tim_trgo2) to be selected. The combination is as follows:
00000:Reset - the UG bit from the TIM_EGR register is used as trigger output (tim_trgo2). If the reset is generated by the trigger input (slave mode controller configured in reset mode), the signal on tim_trgo2 is delayed compared to the actual reset.
00001:Enable - the Counter Enable signal CNT_EN is used as trigger output (tim_trgo2). It is useful to start several timers at the same time or to control a window in which a slave timer is enabled. The Counter Enable signal is generated by a logic AND between the CEN control bit and the trigger input when configured in Gated mode. When the Counter Enable signal is controlled by the trigger input, there is a delay on tim_trgo2, except if the Master/Slave mode is selected (see the MSM bit description in TIM_SMCR register).
00010:Update - the update event is selected as trigger output (tim_trgo2). For instance, a master timer can then be used as a prescaler for a slave timer.
00011:Compare pulse - the trigger output sends a positive pulse when the CC1IF flag is to be set (even if it was already high), as soon as a capture or compare match occurs (tim_trgo2).
00100:Compare - tim_oc1refc signal is used as trigger output (tim_trgo2)
00101:Compare - tim_oc2refc signal is used as trigger output (tim_trgo2)
00110:Compare - tim_oc3refc signal is used as trigger output (tim_trgo2)
00111:Compare - tim_oc4refc signal is used as trigger output (tim_trgo2)
01000:Compare - tim_oc5refc signal is used as trigger output (tim_trgo2)
01001:Compare - tim_oc6refc signal is used as trigger output (tim_trgo2)
01010:Compare Pulse - tim_oc4refc rising or falling edges generate pulses on tim_trgo2
01011:Compare pulse - tim_oc6refc rising or falling edges generate pulses on tim_trgo2
01100:Compare pulse - tim_oc4refc or tim_oc6refc rising edges generate pulses on tim_trgo2
01101:Compare pulse - tim_oc4refc rising or tim_oc6refc falling edges generate pulses on tim_trgo2
01110:Compare pulse - tim_oc5refc or tim_oc6refc rising edges generate pulses on tim_trgo2
01111:Compare pulse - tim_oc5refc rising or tim_oc6refc falling edges generate pulses on tim_trgo2
10000: Compare - tim_oc7refc signal is used as trigger output (tim_trgo2)
10001: Compare Pulse - tim_oc7refc rising or falling edges generate pulses on tim_trgo2
10010: Compare Pulse - tim_oc4refc or tim_oc7refc rising edges generate pulses on tim_trgo2
10011: Compare Pulse - tim_oc4refc rising or tim_oc7refc falling edges generate pulses on tim_trgo2
10100: Compare Pulse - tim_oc5refc or tim_oc7refc rising edges generate pulses on tim_trgo2
10101: Compare Pulse - tim_oc5refc rising or tim_oc7refc falling edges generate pulses on tim_trgo2
10110: Compare Pulse - tim_oc6refc or tim_oc7refc rising edges generate pulses on tim_trgo2
10111: Compare Pulse - tim_oc6refc rising or tim_oc7refc falling edges generate pulses on tim_trgo2
Note: The clock of the slave timer or ADC must be enabled prior to receive events from the master timer, and must not be changed on-the-fly while triggers are received from the master timer.
Bit 19 OIS7: Output idle state 7 (tim_oc7 output)
Refer to OIS1 bit
- Bit 18 OIS6: Output idle state 6 (tim_oc6 output)
Refer to OIS1 bit - Bit 17 Reserved, must be kept at reset value.
- Bit 16 OIS5: Output idle state 5 (tim_oc5 output)
Refer to OIS1 bit - Bit 15 OIS4N: Output idle state 4 (tim_oc4n output)
Refer to OIS1N bit - Bit 14 OIS4: Output idle state 4 (tim_oc4 output)
Refer to OIS1 bit - Bit 13 OIS3N: Output idle state 3 (tim_oc3n output)
Refer to OIS1N bit - Bit 12 OIS3: Output idle state 3 (tim_oc3n output)
Refer to OIS1 bit - Bit 11 OIS2N: Output idle state 2 (tim_oc2n output)
Refer to OIS1N bit - Bit 10 OIS2: Output idle state 2 (tim_oc2 output)
Refer to OIS1 bit - Bit 9 OIS1N: Output idle state 1 (tim_oc1n output)
0: tim_oc1n = 0 after a dead-time when MOE = 0
1: tim_oc1n = 1 after a dead-time when MOE = 0
Note: This bit can not be modified as long as LOCK level 1, 2 or 3 has been programmed (LOCK bits in TIM_BDTR register). - Bit 8 OIS1: Output idle state 1 (tim_oc1 output)
0: tim_oc1 = 0 (after a dead-time) when MOE = 0
1: tim_oc1 = 1 (after a dead-time) when MOE = 0
Note: This bit can not be modified as long as LOCK level 1, 2 or 3 has been programmed (LOCK bits in TIM_BDTR register). - Bit 7 TI1S: tim_ti1 selection
This bit enables the insertion of a XOR gate to combine tim_ti1_in[15:0], tim_ti2_in[15:0], and tim_ti3_in[15:0] inputs into tim_ti1.
The position of the XOR gate, with respect to input filters, is defined with the XORPS bit.
0: The tim_ti1_in[15:0] multiplexer output is connected to tim_ti1 input
1: tim_ti1_in[15:0], tim_ti2_in[15:0] and tim_ti3_in[15:0] multiplexers outputs are XORed and connected to the tim_ti1 input
Bits 25, 6:4 MMS[3:0]: Master mode selection
These bits select the information to be sent in master mode to slave timers for synchronization (tim_trgo). The combination is as follows:
- 0000: Reset - the UG bit from the TIM_EGR register is used as trigger output (tim_trgo). If the reset is generated by the trigger input (slave mode controller configured in reset mode) then the signal on tim_trgo is delayed compared to the actual reset.
- 0001: Enable - the Counter Enable signal CNT_EN is used as trigger output (tim_trgo). It is useful to start several timers at the same time or to control a window in which a slave timer is enable. The Counter Enable signal is generated by a logic AND between CEN control bit and the trigger input when configured in gated mode. When the Counter Enable signal is controlled by the trigger input, there is a delay on tim_trgo, except if the master/slave mode is selected (see the MSM bit description in TIM_SMCR register).
- 0010: Update - The update event is selected as trigger output (tim_trgo). For instance a master timer can then be used as a prescaler for a slave timer.
- 0011: Compare Pulse - The trigger output send a positive pulse when the CC1IF flag is to be set (even if it was already high), as soon as a capture or a compare match occurred. (tim_trgo).
- 0100: Compare - tim_oc1refc signal is used as trigger output (tim_trgo)
- 0101: Compare - tim_oc2refc signal is used as trigger output (tim_trgo)
- 0110: Compare - tim_oc3refc signal is used as trigger output (tim_trgo)
- 0111: Compare - tim_oc4refc signal is used as trigger output (tim_trgo)
- 1000: Encoder Clock output - The encoder clock signal is used as trigger output (tim_trgo). This code is valid for the following SMS[4:0] values: 00001, 00010, 00011, 01010, 01011, 01100, 01101, 01110, 01111. Any other SMS[4:0] code is not allowed and may lead to unexpected behavior.
Other codes reserved
Note: The clock of the slave timer or ADC must be enabled prior to receive events from the master timer, and must not be changed on-the-fly while triggers are received from the master timer.
Bit 3 CCDS: Capture/compare DMA selection
- 0: CCx DMA request sent when CCx event occurs
- 1: CCx DMA requests sent when update event occurs
Bit 2 CCUS: Capture/compare control update selection
- 0: When capture/compare control bits are preloaded (CCPC = 1), they are updated by setting the COMG bit only
- 1: When capture/compare control bits are preloaded (CCPC = 1), they are updated by setting the COMG bit or when an rising edge occurs on tim_trgi
Note: This bit acts only on channels that have a complementary output.
Bit 1 Reserved, must be kept at reset value.
Bit 0 CCPC: Capture/compare preloaded control
- 0: CCxE, CCxNE, CCxP, CCxNP and OCxM bits are not preloaded
- 1: CCxE, CCxNE, CCxP, CCxNP and OCxM bits are preloaded, after having been written, they are updated only when a commutation event (COM) occurs (COMG bit set or rising edge detected on tim_trgi, depending on the CCUS bit).
Note: This bit acts only on channels that have a complementary output.
31.6.3 TIM slave mode control register (TIM_SMCR)
Address offset: 0x008
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | SETPS[3:0] | SMSPS | SMSPE | Res. | Res. | TS[4:3] | Res. | Res. | SMS[4:3] | |||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | ||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| ETP | ECE | ETPS[1:0] | ETF[3:0] | MSM | TS[2:0] | OCCS | SMS[2:0] | ||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:30 Reserved, must be kept at reset value.
Bits 29:26 SETPS[3:0]: Synchronous external trigger prescaler
The linear synchronous prescaler divides the frequency of the tim_etr signal, by a factor (SETPS[3:0] + 1).
Bit 25 SMSPS: SMS preload source
This bit selects whether the events that triggers the SMS[4:0] bitfield transfer from preload to active
0: The transfer is triggered by the Timer's Update event
1: The transfer is triggered by the Index event
Bit 24 SMSPE: SMS preload enable
This bit selects whether the SMS[3:0] bitfield is preloaded
0: SMS[4:0] bitfield is not preloaded
1: SMS[4:0] preload is enabled
Bits 23:22 Reserved, must be kept at reset value.
Bits 21:20 TS[4:3]: Trigger selection - bit 4:3
Refer to TS[2:0] description - bits 6:4
Bits 19:18 Reserved, must be kept at reset value.
Bit 15 ETP: External trigger polarity
This bit selects whether tim_etr_in or tim_etr_in is used for trigger operations
0: tim_etr_in is non-inverted, active at high level or rising edge.
1: tim_etr_in is inverted, active at low level or falling edge.
Bit 14 ECE: External clock enable
This bit enables External clock mode 2.
0: External clock mode 2 disabled
1: External clock mode 2 enabled. The counter is clocked by any active edge on the tim_etr signal.
Note: Setting the ECE bit has the same effect as selecting external clock mode 1 with tim_trgi connected to tim_etr (SMS = 111 and TS = 0011).
It is possible to simultaneously use external clock mode 2 with the following slave modes: reset mode, gated mode and trigger mode. Nevertheless, tim_trgi must not be connected to tim_etr in this case (TS bits must not be 0011).
If external clock mode 1 and external clock mode 2 are enabled at the same time, the external clock input is tim_etr.
Bits 13:12 ETPS[1:0]: External trigger prescaler
External trigger signal tim_etrp frequency must be at most 1/4 of TIMxCLK frequency. A prescaler can be enabled to reduce tim_etrp frequency. It is useful when inputting fast external clocks on tim_etr_in.
00: Prescaler OFF
01: tim_etr_in frequency divided by 2
10: tim_etr_in frequency divided by 4
11: tim_etr_in frequency divided by 8
Bits 11:8 ETF[3:0]: External trigger filter
This bitfield then defines the frequency used to sample tim_etrp signal and the length of the digital filter applied to tim_etrp. The digital filter is made of an event counter in which N consecutive events are needed to validate a transition on the output:
0000: No filter, sampling is done at fDTS2
0001: fSAMPLING = ftim_ker_ck, N = 2
0010: fSAMPLING = ftim_ker_ck, N = 4
0011: fSAMPLING = ftim_ker_ck, N = 8
0100: fSAMPLING = fDTS2/2, N = 6
0101: fSAMPLING = fDTS2/2, N = 8
0110: fSAMPLING = fDTS2/4, N = 6
0111: fSAMPLING = fDTS2/4, N = 8
1000: fSAMPLING = fDTS2/8, N = 6
1001: fSAMPLING = fDTS2/8, N = 8
1010: fSAMPLING = fDTS2/16, N = 5
1011: fSAMPLING = fDTS2/16, N = 6
1100: fSAMPLING = fDTS2/16, N = 8
1101: fSAMPLING = fDTS2/32, N = 5
1110: fSAMPLING = fDTS2/32, N = 6
1111: fSAMPLING = fDTS2/32, N = 8
Bit 7 MSM: Master/slave mode
0: No action
1: The effect of an event on the trigger input (tim_trgi) is delayed to allow a perfect synchronization between the current timer and its slaves (through tim_trgo). It is useful if we want to synchronize several timers on a single external event.
Bits 6:4 TS[2:0]: Trigger selection
This bitfield is combined with TS[4:3] bits.
This bitfield selects the trigger input to be used to synchronize the counter.
00000: Internal trigger 0 (tim_itr0)
00001: Internal trigger 1 (tim_itr1)
00010: Internal trigger 2 (tim_itr2)
00011: Internal trigger 3 (tim_itr3)
00100: tim_ti1 Edge Detector (tim_ti1f_ed)
00101: Filtered Timer Input 1 (tim_ti1fp1)
00110: Filtered Timer Input 2 (tim_ti2fp2)
00111: External trigger input (tim_etr)
01000: Internal trigger 4 (tim_itr4)
01001: Internal trigger 5 (tim_itr5)
01010: Internal trigger 6 (tim_itr6)
01011: Internal trigger 7 (tim_itr7)
01100: Internal trigger 8 (tim_itr8)
01101: Internal trigger 9 (tim_itr9)
01110: Internal trigger 10 (tim_itr10)
01111: Internal trigger 11 (tim_itr11)
10000: Internal trigger 12 (tim_itr12)
10001: Internal trigger 13 (tim_itr13)
10010: Internal trigger 14 (tim_itr14)
10011: Internal trigger 15 (tim_itr15)
10100: Internal trigger 16 (tim_itr16)
10101: Internal trigger 17 (tim_itr17)
10110: Internal trigger 18 (tim_itr18)
10111: Internal trigger 19 (tim_itr19)
11000: Internal trigger 20 (tim_itr20)
11001: Internal trigger 21 (tim_itr21)
11010: Internal trigger 22 (tim_itr22)
11011: Internal trigger 23 (tim_itr23)
11100: Internal trigger 24 (tim_itr24)
11101: Internal trigger 25 (tim_itr25)
11110: Internal trigger 26 (tim_itr26)
11111: Internal trigger 27 (tim_itr27)
See Section 31.3.2: TIM1/TIM8 pins and internal signals for more details on tim_itr meaning for each Timer.
Note: These bits must be changed only when they are not used (for example when SMS = 000) to avoid wrong edge detections at the transition.
Bit 3 OCCS: OCREF clear selection
This bit is used to select the OCREF clear source.
0: tim_ocref_clr_int is connected to the tim_ocref_clr input
1: tim_ocref_clr_int is connected to tim_etr
Bits 17:16, 2:0 SMS[4:0]: Slave mode selection
When external signals are selected the active edge of the trigger signal (tim_trgi) is linked to the polarity selected on the external input (refer to ETP bit in TIM_SMCR for tim_etr_in and CCxP/CCxNP bits in TIM_CCER register for tim_ti1fp1 and tim_ti2fp2).
00000: Slave mode disabled - if CEN = 1 then the prescaler is clocked directly by the internal clock.
00001: Quadrature encoder mode 1, x2 mode - Counter counts up/down on tim_ti1fp1 edge depending on tim_ti2fp2 level.
00010: Quadrature encoder mode 2, x2 mode - Counter counts up/down on tim_ti2fp2 edge depending on tim_ti1fp1 level.
00011: Quadrature encoder mode 3, x4 mode - Counter counts up/down on both tim_ti1fp1 and tim_ti2fp2 edges depending on the level of the other input.
00100: Reset mode - Rising edge of the selected trigger input (tim_trgi) reinitializes the counter and generates an update of the registers.
00101: Gated mode - The counter clock is enabled when the trigger input (tim_trgi) is high. The counter stops (but is not reset) as soon as the trigger becomes low. Both start and stop of the counter are controlled.
00110: Trigger mode - The counter starts at a rising edge of the trigger tim_trgi (but it is not reset). Only the start of the counter is controlled.
00111: External Clock mode 1 - Rising edges of the selected trigger (tim_trgi) clock the counter.
01000: Combined reset + trigger mode - Rising edge of the selected trigger input (tim_trgi) reinitializes the counter, generates an update of the registers and starts the counter.
01001: Combined gated + reset mode - The counter clock is enabled when the trigger input (tim_trgi) is high. The counter stops and is reset as soon as the trigger becomes low. Both start and stop of the counter are controlled.
01010: Encoder mode: Clock plus direction, x2 mode.
01011: Encoder mode: Clock plus direction, x1 mode, tim_ti2fp2 edge sensitivity is set by CC2P
01100: Encoder mode: Directional Clock, x2 mode.
01101: Encoder mode: Directional Clock, x1 mode, tim_ti1fp1 and tim_ti2fp2 edge sensitivity is set by CC1P and CC2P.
01110: Quadrature encoder mode: x1 mode, counting on tim_ti1fp1 edges only, edge sensitivity is set by CC1P.
01111: Quadrature encoder mode: x1 mode, counting on tim_ti2fp2 edges only, edge sensitivity is set by CC2P.
10000: Quadrature encoder with built-in debouncer: x2 mode.
10001: Quadrature encoder with built-in debouncer: x4 mode.
Note: The gated mode must not be used if tim_ti1f_ed is selected as the trigger input (TS = 00100). Indeed, tim_ti1f_ed outputs 1 pulse for each transition on TI1F, whereas the gated mode checks the level of the trigger signal.
Note: The clock of the slave peripherals (timer, ADC, ...) receiving the tim_trgo or the tim_trgo2 signals must be enabled prior to receive events from the master timer, and the clock frequency (prescaler) must not be changed on-the-fly while triggers are received from the master timer.
31.6.4 TIM DMA/interrupt enable register (TIM_DIER)
Address offset: 0x00C
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | TERRI E | IERRIE | DIRIE | IDXIE | Res. | Res. | Res. | Res. |
| rw | rw | rw | rw | ||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | TDE | COMD E | CC4DE | CC3DE | CC2DE | CC1DE | UDE | BIE | TIE | COMIE | CC4IE | CC3IE | CC2IE | CC1IE | UIE |
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:24 Reserved, must be kept at reset value.
Bit 23 TERRIE: Transition error interrupt enable
- 0: Transition error interrupt disabled
- 1: Transition error interrupt enabled
Bit 22 IERRIE: Index error interrupt enable
- 0: Index error interrupt disabled
- 1: Index error interrupt enabled
Bit 21 DIRIE: Direction change interrupt enable
- 0: Direction Change interrupt disabled
- 1: Direction Change interrupt enabled
Bit 20 IDXIE: Index interrupt enable
- 0: Index interrupt disabled
- 1: Index Change interrupt enabled
Bits 19:15 Reserved, must be kept at reset value.
Bit 14 TDE: Trigger DMA request enable
- 0: Trigger DMA request disabled
- 1: Trigger DMA request enabled
Bit 13 COMDE: COM DMA request enable
- 0: COM DMA request disabled
- 1: COM DMA request enabled
Bit 12 CC4DE: Capture/compare 4 DMA request enable
- 0: CC4 DMA request disabled
- 1: CC4 DMA request enabled
Bit 11 CC3DE: Capture/compare 3 DMA request enable
- 0: CC3 DMA request disabled
- 1: CC3 DMA request enabled
Bit 10 CC2DE: Capture/compare 2 DMA request enable
- 0: CC2 DMA request disabled
- 1: CC2 DMA request enabled
Bit 9 CC1DE: Capture/compare 1 DMA request enable
- 0: CC1 DMA request disabled
- 1: CC1 DMA request enabled
- Bit 8 UDE: Update DMA request enable
0: Update DMA request disabled
1: Update DMA request enabled - Bit 7 BIE: Break interrupt enable
0: Break interrupt disabled
1: Break interrupt enabled - Bit 6 TIE: Trigger interrupt enable
0: Trigger interrupt disabled
1: Trigger interrupt enabled - Bit 5 COMIE: COM interrupt enable
0: COM interrupt disabled
1: COM interrupt enabled - Bit 4 CC4IE: Capture/compare 4 interrupt enable
0: CC4 interrupt disabled
1: CC4 interrupt enabled - Bit 3 CC3IE: Capture/compare 3 interrupt enable
0: CC3 interrupt disabled
1: CC3 interrupt enabled - Bit 2 CC2IE: Capture/compare 2 interrupt enable
0: CC2 interrupt disabled
1: CC2 interrupt enabled - Bit 1 CC1IE: Capture/compare 1 interrupt enable
0: CC1 interrupt disabled
1: CC1 interrupt enabled - Bit 0 UIE: Update interrupt enable
0: Update interrupt disabled
1: Update interrupt enabled
31.6.5 TIM status register (TIM_SR)
Address offset: 0x010
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| TI4FS | TI3FS | TI2FS | TI1FS | Res. | Res. | ODS | UIOVR F | TERRF | IERRF | DIRF | IDXF | Res. | CC7IF | CC6IF | CC5IF |
| r | r | r | r | r | rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 | |||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| B2GF | BGF | SBIF | CC4OF | CC3OF | CC2OF | CC1OF | B2IF | BIF | TIF | COMIF | CC4IF | CC3IF | CC2IF | CC1IF | UIF |
| rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 | rc_w0 |
- Bit 31 TI4FS: tim_ti4f status
This flag indicates the value of the tim_ti4f signal (after the digital filtering stage), for polling purpose.
0: tim_ti4f signal is low
1: tim_ti4f signal is high - Bit 30 TI3FS: tim_ti3f status
This flag indicates the value of the tim_ti3f signal (after the digital filtering stage), for polling purpose.
0: tim_ti3f signal is low
1: tim_ti3f signal is high - Bit 29 TI2FS: tim_ti2f status
This flag indicates the value of the tim_ti2f signal (after the digital filtering stage), for polling purpose.
0: tim_ti2f signal is low
1: tim_ti2f signal is high - Bit 28 TI1FS: tim_ti1f status
This flag indicates the value of the tim_ti1f signal (after the digital filtering stage), for polling purpose.
0: tim_ti1f signal is low
1: tim_ti1f signal is high - Bits 27:26 Reserved, must be kept at reset value.
- Bit 25 ODS: Output disable status
This bit indicates the global output state when a break or break2 event occurred, to discriminate the source.
0: Idle state: break was triggered (or MOE was written to 0), and OIS states are forced on tim_ocx and tim_ocxn outputs
1: Disabled state: break2 was triggered, tim_ocx and tim_ocxn outputs are inactive - Bit 24 UIOVRF: Update Interrupt Overrun flag
This flag is set by hardware when an update request occurs while an update interrupt is pending (update interrupt flag set). It is cleared by software by writing it to '0'.
0: No Update Interrupt Overrun
1: Update Interrupt Overrun - Bit 23 TERRF: Transition error interrupt flag
This flag is set by hardware when a transition error is detected in encoder mode. It is cleared by software by writing it to 0.
0: No encoder transition error has been detected.
1: An encoder transition error has been detected - Bit 22 IERRF: Index error interrupt flag
This flag is set by hardware when an index error is detected. It is cleared by software by writing it to 0.
0: No index error has been detected.
1: An index error has been detected - Bit 21 DIRF: Direction change interrupt flag
This flag is set by hardware when the direction changes in encoder mode (DIR bit value in TIM_CR is changing). It is cleared by software by writing it to 0.
0: No direction change
1: Direction change
- Bit 20 IDXF: Index interrupt flag
This flag is set by hardware when an index event is detected. It is cleared by software by writing it to 0.
0: No index event occurred.
1: An index event has occurred - Bit 19 Reserved, must be kept at reset value.
- Bit 18 CC7IF: Compare 7 interrupt flag
Refer to CC1IF description
Note: Channel 7 can only be configured as output. - Bit 17 CC6IF: Compare 6 interrupt flag
Refer to CC1IF description
Note: Channel 6 can only be configured as output. - Bit 16 CC5IF: Compare 5 interrupt flag
Refer to CC1IF description
Note: Channel 5 can only be configured as output. - Bit 15 B2GF: Break 2 generation flag
This flag is set by hardware as soon as a break 2 event is forced by software, using the B2G bit. It is useful to distinguish hardware-triggered from software-triggered break events. It is cleared by software by writing it to 0.
0: No break 2 event occurred.
1: A break 2 event was forced with the B2G bit - Bit 14 BGF: Break generation flag
This flag is set by hardware as soon as a break event is forced by software, using the BG bit. It is useful to distinguish hardware-triggered from software-triggered break events. It is cleared by software by writing it to 0.
0: No break event occurred.
1: A break event was forced with the BG bit - Bit 13 SBIF: System break interrupt flag
This flag is set by hardware as soon as the system break input goes active. It can be cleared by software if the system break input is not active.
This flag must be reset to re-start PWM operation.
0: No break event occurred.
1: An active level has been detected on the system break input. An interrupt is generated if BIE = 1 in the TIM_DIER register. - Bit 12 CC4OF: Capture/compare 4 overcapture flag
Refer to CC1OF description - Bit 11 CC3OF: Capture/compare 3 overcapture flag
Refer to CC1OF description - Bit 10 CC2OF: Capture/compare 2 overcapture flag
Refer to CC1OF description - Bit 9 CC1OF: Capture/compare 1 overcapture flag
This flag is set by hardware only when the corresponding channel is configured in input capture mode. It is cleared by software by writing it to 0.
0: No overcapture has been detected.
1: The counter value has been captured in TIM_CCR1 register while CC1IF flag was already set
Bit 8 B2IF: Break 2 interrupt flag
This flag is set by hardware as soon as the break 2 input goes active. It can be cleared by software if the break 2 input is not active.
0: No break event occurred.
1: An active level has been detected on the break 2 input. An interrupt is generated if BIE = 1 in the TIM_DIER register.
Bit 7 BIF: Break interrupt flag
This flag is set by hardware as soon as the break input goes active. It can be cleared by software if the break input is not active.
0: No break event occurred.
1: An active level has been detected on the break input. An interrupt is generated if BIE = 1 in the TIM_DIER register.
Bit 6 TIF: Trigger interrupt flag
This flag is set by hardware on the TRG trigger event (active edge detected on tim_trgi input when the slave mode controller is enabled in all modes but gated mode. It is set when the counter starts or stops when gated mode is selected. It is cleared by software.
0: No trigger event occurred.
1: Trigger interrupt pending.
Bit 5 COMIF: COM interrupt flag
This flag is set by hardware on COM event (when capture/compare Control bits - CCxE, CCxNE, OCxM - have been updated). It is cleared by software.
0: No COM event occurred.
1: COM interrupt pending.
Bit 4 CC4IF: Capture/compare 4 interrupt flag
Refer to CC1IF description
Bit 3 CC3IF: Capture/compare 3 interrupt flag
Refer to CC1IF description
Bit 2 CC2IF: Capture/compare 2 interrupt flag
Refer to CC1IF description
Bit 1 CC1IF: Capture/compare 1 interrupt flag
This flag is set by hardware. It is cleared by software (input capture or output compare mode) or by reading the TIM_CCR1 register (input capture mode only).
0: No compare match / No input capture occurred
1: A compare match or an input capture occurred
If channel CC1 is configured as output: this flag is set when the content of the counter TIM_CNT matches the content of the TIM_CCR1 register. When the content of TIM_CCR1 is greater than the content of TIM_ARR, the CC1IF bit goes high on the counter overflow (in up-counting and up/down-counting modes) or underflow (in downcounting mode). There are 3 possible options for flag setting in center-aligned mode, refer to the CMS bits in the TIM_CR1 register for the full description.
If channel CC1 is configured as input: this bit is set when counter value has been captured in TIM_CCR1 register (an edge has been detected on IC1, as per the edge sensitivity defined with the CC1P and CC1NP bits setting, in TIM_CCER).
Bit 0 UIF: Update interrupt flag
This bit is set by hardware on an update event. It is cleared by software.
0: No update occurred.
1: Update interrupt pending. This bit is set by hardware when the registers are updated:
–At overflow or underflow regarding the repetition counter value (update if repetition counter = 0) and if the UDIS = 0 in the TIM_CR1 register.
–When CNT is reinitialized by software using the UG bit in TIM_EGR register, if URS = 0 and UDIS = 0 in the TIM_CR1 register.
–When CNT is reinitialized by a trigger event (refer to Section 31.6.3: TIM slave mode control register (TIM_SMCR)), if URS = 0 and UDIS = 0 in the TIM_CR1 register.
31.6.6 TIM event generation register (TIM_EGR)
Address offset: 0x014
Reset value: 0x0000
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res | Res | Res | Res | Res | Res | Res | B2G | BG | TG | COMG | CC4G | CC3G | CC2G | CC1G | UG |
| w | w | w | w | w | w | w | w | w |
Bits 15:9 Reserved, must be kept at reset value.
Bit 8 B2G: Break 2 generation
This bit is set by software in order to generate an event, it is automatically cleared by hardware.
0: No action
1: A break 2 event is generated. MOE bit is cleared and B2IF flag is set. Related interrupt can occur if enabled.
Bit 7 BG: Break generation
This bit is set by software in order to generate an event, it is automatically cleared by hardware.
0: No action
1: A break event is generated. MOE bit is cleared and BIF flag is set. Related interrupt or DMA transfer can occur if enabled.
Bit 6 TG: Trigger generation
This bit is set by software in order to generate an event, it is automatically cleared by hardware.
0: No action
1: The TIF flag is set in TIM_SR register. Related interrupt or DMA transfer can occur if enabled.
Bit 5 COMG: Capture/compare control update generation
This bit can be set by software, it is automatically cleared by hardware
0: No action
1: CCxE, CCxNE and OCxM bits update (providing CCPC bit is set)
Note: This bit acts only on channels having a complementary output.
Bit 4 CC4G: Capture/compare 4 generation
Refer to CC1G description
Bit 3 CC3G: Capture/compare 3 generation
Refer to CC1G description
Bit 2 CC2G: Capture/compare 2 generation
Refer to CC1G description
Bit 1 CC1G: Capture/compare 1 generation
This bit is set by software in order to generate an event, it is automatically cleared by hardware.
0: No action
1: A capture/compare event is generated on channel 1:
If channel CC1 is configured as output:
CC1IF flag is set, Corresponding interrupt or DMA request is sent if enabled.
If channel CC1 is configured as input:
The current value of the counter is captured in TIM_CCR1 register. The CC1IF flag is set, the corresponding interrupt or DMA request is sent if enabled. The CC1OF flag is set if the CC1IF flag was already high.
Bit 0 UG: Update generation
This bit can be set by software, it is automatically cleared by hardware.
0: No action
1: Reinitialize the counter and generates an update of the registers. Note that the prescaler counter is cleared too (anyway the prescaler ratio is not affected). The counter is cleared if the center-aligned mode is selected or if DIR = 0 (upcounting), else it takes the autoreload value (TIM_ARR) if DIR = 1 (downcounting).
31.6.7 TIM capture/compare mode register 1 (TIM_CCMR1)
Address offset: 0x018
Reset value: 0x0000 0000
The same register can be used for input capture mode (this section) or for output compare mode (next section). The direction of a channel is defined by configuring the corresponding CCxS bits. All the other bits of this register have a different function for input capture and for output compare modes. It is possible to combine both modes independently (for example channel 1 in input capture mode and channel 2 in output compare mode).
| column_1 | column_2 | column_3 | column_4 | column_5 | column_6 | column_7 | column_8 | column_9 | column_10 | column_11 | column_12 | column_13 | column_14 | column_15 | RM0522 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| IC2F[3:0] | IC2PSC[1:0] | CC2S[1:0] | IC1F[3:0] | IC1PSC[1:0] | CC1S[1:0] | ||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
| Bits 15:12 | IC2F[3:0]: | Input capture 2 filter | |||||||||||||
| Bits 11:10 | IC2PSC[1:0] | : Input capture 2 prescaler | |||||||||||||
| Bits 9:8 | CC2S[1:0] | : Capture/compare 2 selection |
Input capture mode:
Bits 31:16 Reserved, must be kept at reset value.
Bits 15:12 IC2F[3:0]: Input capture 2 filter
Refer to IC1F[3:0] bit description
Bits 11:10 IC2PSC[1:0]: Input capture 2 prescaler
Refer to IC1PSC[1:0] bit description
Bits 9:8 CC2S[1:0]: Capture/compare 2 selection
This bitfield defines the direction of the channel (input/output) as well as the used input.
00: CC2 channel is configured as output
01: CC2 channel is configured as input, tim_ic2 is mapped on tim_ti2
10: CC2 channel is configured as input, tim_ic2 is mapped on tim_ti1
11: CC2 channel is configured as input, tim_ic2 is mapped on tim_trc. This mode is working only if an internal trigger input is selected through TS bit (TIM_SMCR register)
Note: CC2S bits are writable only when the channel is OFF (CC2E = 0 in TIM_CCER).

Bits 7:4 IC1F[3:0]: Input capture 1 filter
This bitfield defines the frequency used to sample tim_ti1 input and the length of the digital filter applied to tim_ti1. The digital filter is made of an event counter in which N consecutive events are needed to validate a transition on the output:
0000: No filter, sampling is done at \(f_{\text{DTS}}\)
0001: \(f_{\text{SAMPLING}} = f_{\text{tim_ker_ck}}\), N = 2
0010: \(f_{\text{SAMPLING}} = f_{\text{tim_ker_ck}}\), N = 4
0011: \(f_{\text{SAMPLING}} = f_{\text{tim_ker_ck}}\), N = 8
0100: \(f_{\text{SAMPLING}} = f_{\text{DTS}}/2\), N = 6
0101: \(f_{\text{SAMPLING}} = f_{\text{DTS}}/2\), N = 8
0110: \(f_{\text{SAMPLING}} = f_{\text{DTS}}/4\), N = 6
0111: \(f_{\text{SAMPLING}} = f_{\text{DTS}}/4\), N = 8
1000: \(f_{\text{SAMPLING}} = f_{\text{DTS}}/8\), N = 6
1001: \(f_{\text{SAMPLING}} = f_{\text{DTS}}/8\), N = 8
1010: \(f_{\text{SAMPLING}} = f_{\text{DTS}}/16\), N = 5
1011: \(f_{\text{SAMPLING}} = f_{\text{DTS}}/16\), N = 6
1100: \(f_{\text{SAMPLING}} = f_{\text{DTS}}/16\), N = 8
1101: \(f_{\text{SAMPLING}} = f_{\text{DTS}}/32\), N = 5
1110: \(f_{\text{SAMPLING}} = f_{\text{DTS}}/32\), N = 6
1111: \(f_{\text{SAMPLING}} = f_{\text{DTS}}/32\), N = 8
Bits 3:2 IC1PSC[1:0]: Input capture 1 prescaler
This bitfield defines the ratio of the prescaler acting on CC1 input (tim_ic1). The prescaler is reset as soon as CC1E = 0 (TIM_CCER register).
00: no prescaler, capture is done each time an edge is detected on the capture input
01: capture is done once every 2 events
10: capture is done once every 4 events
11: capture is done once every 8 events
Bits 1:0 CC1S[1:0]: Capture/compare 1 Selection
This bitfield defines the direction of the channel (input/output) as well as the used input.
00: CC1 channel is configured as output
01: CC1 channel is configured as input, tim_ic1 is mapped on tim_ti1
10: CC1 channel is configured as input, tim_ic1 is mapped on tim_ti2
11: CC1 channel is configured as input, tim_ic1 is mapped on tim_trc. This mode is working only if an internal trigger input is selected through TS bit (TIM_SMCR register)
Note: CC1S bits are writable only when the channel is OFF (CC1E = 0 in TIM_CCER).
31.6.8 TIM capture/compare mode register 1 [alternate] (TIM_CCMR1)
Address offset: 0x018
Reset value: 0x0000 0000
The same register can be used for output compare mode (this section) or for input capture mode (previous section). The direction of a channel is defined by configuring the corresponding CCxS bits. All the other bits of this register have a different function for input capture and for output compare modes. It is possible to combine both modes independently (for example channel 1 in input capture mode and channel 2 in output compare mode).
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | OC2M[4:3] | Res. | Res. | Res. | Res. | Res. | Res. | OC1M[4:3] | ||
| rw | rw | rw | rw | ||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| OC2CE | OC2M[2:0] | OC2PE | OC2FE | CC2S[1:0] | OC1CE | OC1M[2:0] | OC1PE | OC1FE | CC1S[1:0] | ||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Output compare mode:
Bits 31:26 Reserved, must be kept at reset value.
Bits 23:18 Reserved, must be kept at reset value.
Bit 15 OC2CE: Output compare 2 clear enable
0: tim_oc2ref is not affected by the tim_ocref_clr_int signal
1: tim_oc2ref is cleared as soon as a High level is detected on tim_ocref_clr_int signal (tim_ocref_clr input or tim_etrf input)
Note: This mode is not available for all PWM modes. Refer to Section 31.3.23: Clearing the tim_ocxref signal on an external event for the list of forbidden configurations.
Bits 25:24, 14:12 OC2M[4:0]: Output compare 2 mode
Refer to OC1M[4:0] bit description
Bit 11 OC2PE: Output compare 2 preload enable
0: Preload register on TIM_CCR2 disabled. TIM_CCR2 can be written at anytime, the new value is taken in account immediately.
1: Preload register on TIM_CCR2 enabled. Read/Write operations access the preload register. TIM_CCR2 preload value is loaded in the active register at each update event.
These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIM_BDTR register) and CC1S = 00 (the channel is configured in output).
Bit 10 OC2FE: Output compare 2 fast enable
This bit decreases the latency between a trigger event and a transition on the timer output. It must be used in one-pulse mode (OPM bit set in TIM_CR1 register), to have the output pulse starting as soon as possible after the starting trigger.
0: CC2 behaves normally depending on counter and CCR2 values even when the trigger is ON. The minimum delay to activate CC2 output when an edge occurs on the trigger input is 5 clock cycles.
1: An active edge on the trigger input acts like a compare match on CC2 output. Then, OC is set to the compare level independently from the result of the comparison. Delay to sample the trigger input and to activate CC2 output is reduced to 3 clock cycles. OCFE acts only if the channel is configured in PWM1 or PWM2 mode.
Bits 9:8 CC2S[1:0]: Capture/compare 2 selection
This bitfield defines the direction of the channel (input/output) as well as the used input.
00: CC2 channel is configured as output
01: CC2 channel is configured as input, tim_ic2 is mapped on tim_ti2
10: CC2 channel is configured as input, tim_ic2 is mapped on tim_ti1
11: CC2 channel is configured as input, tim_ic2 is mapped on tim_trc. This mode is working only if an internal trigger input is selected through the TS bit (TIM_SMCR register)
Note: CC2S bits are writable only when the channel is OFF (CC2E = 0 in TIM_CCER).
Bit 7 OC1CE: Output compare 1 clear enable
0: tim_oc1ref is not affected by the tim_ocref_clr_int signal
1: tim_oc1ref is cleared as soon as a High level is detected on tim_ocref_clr_int signal
(tim_ocref_clr input or tim_etr input)
Note: This mode is not available for all PWM modes. Refer to Section 31.3.23: Clearing the tim_ocxref signal on an external event for the list of forbidden configurations.
Bits 17:16, 6:4 OC1M[4:0]: Output compare 1 mode
These bits define the behavior of the output reference signal tim_oc1ref from which tim_oc1 and tim_oc1n are derived. tim_oc1ref is active high whereas tim_oc1 and tim_oc1n active level depends on CC1P and CC1NP bits.
00000:Frozen - The comparison between the output compare register TIM_CCR1 and the counter TIM_CNT has no effect on the outputs. This mode can be used when the timer serves as a software timebase. When the frozen mode is enabled during timer operation, the output keeps the state (active or inactive) it had before entering the frozen state.
00001:Set channel 1 to active level on match. tim_oc1ref signal is forced high when the counter TIM_CNT matches the capture/compare register 1 (TIM_CCR1).
00010:Set channel 1 to inactive level on match. tim_oc1ref signal is forced low when the counter TIM_CNT matches the capture/compare register 1 (TIM_CCR1).
00011:Toggle - tim_oc1ref toggles when TIM_CNT= TIM_CCR1.
00100:Force inactive level - tim_oc1ref is forced low.
00101:Force active level - tim_oc1ref is forced high.
00110:PWM mode 1 - In upcounting, channel 1 is active as long as TIM_CNT< TIM_CCR1 else inactive. In downcounting, channel 1 is inactive (tim_oc1ref= 0) as long as TIM_CNT> TIM_CCR1 else active (tim_oc1ref= 1).
00111:PWM mode 2 - In upcounting, channel 1 is inactive as long as TIM_CNT< TIM_CCR1 else active. In downcounting, channel 1 is active as long as TIM_CNT> TIM_CCR1 else inactive.
01000:Retrigerrable OPM mode 1 - In up-counting mode, the channel is active until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 1 and the channels becomes active again at the next update. In down-counting mode, the channel is inactive until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 1 and the channels becomes inactive again at the next update.
01001:Retrigerrable OPM mode 2 - In up-counting mode, the channel is inactive until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 2 and the channels becomes inactive again at the next update. In down-counting mode, the channel is active until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 1 and the channels becomes active again at the next update.
01100-01101:Combined PWM mode 1 and 2. Refer to Table 296 for details.
01110-01111:Asymmetric PWM mode 1 and 2. Refer to Table 295 for details.
10000-10001:Combined PWM mode 3 and 4. Refer to Table 296 for details.
10010-11001: Asymmetric PWM mode 3 to 10. Refer to Table 295 for details.
Others: Reserved
Note: These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIM_BDTR register) and CC1S= 00 (the channel is configured in output).
Note: In PWM mode, the OCREF level changes when the result of the comparison changes, when the output compare mode switches from “frozen” mode to “PWM” mode and when the output compare mode switches from “force active/inactive” mode to “PWM” mode.
Note: On channels having a complementary output, this bitfield is preloaded. If the CCPC bit is set in the TIM_CR2 register then the OC1M active bits take the new value from the preloaded bits only when a COM event is generated.
Bit 3 OC1PE: Output compare 1 preload enable
0: Preload register on TIM_CCR1 disabled. TIM_CCR1 can be written at anytime, the new value is taken in account immediately.
1: Preload register on TIM_CCR1 enabled. Read/Write operations access the preload register. TIM_CCR1 preload value is loaded in the active register at each update event.
Note: These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIM_BDTR register) and CC1S = 00 (the channel is configured in output).
Bit 2 OC1FE: Output compare 1 fast enable
This bit decreases the latency between a trigger event and a transition on the timer output. It must be used in one-pulse mode (OPM bit set in TIM_CR1 register), to have the output pulse starting as soon as possible after the starting trigger.
0: CC1 behaves normally depending on counter and CCR1 values even when the trigger is ON. The minimum delay to activate CC1 output when an edge occurs on the trigger input is 5 clock cycles.
1: An active edge on the trigger input acts like a compare match on CC1 output. Then, OC is set to the compare level independently from the result of the comparison. Delay to sample the trigger input and to activate CC1 output is reduced to 3 clock cycles. OCFE acts only if the channel is configured in PWM1 or PWM2 mode.
Bits 1:0 CC1S[1:0]: Capture/compare 1 selection
This bitfield defines the direction of the channel (input/output) as well as the used input.
00: CC1 channel is configured as output
01: CC1 channel is configured as input, tim_ic1 is mapped on tim_ti1
10: CC1 channel is configured as input, tim_ic1 is mapped on tim_ti2
11: CC1 channel is configured as input, tim_ic1 is mapped on tim_trc. This mode is working only if an internal trigger input is selected through TS bit (TIM_SMCR register)
Note: CC1S bits are writable only when the channel is OFF (CC1E = 0 in TIM_CCER).
31.6.9 TIM capture/compare mode register 2 (TIM_CCMR2)
Address offset: 0x01C
Reset value: 0x0000 0000
The same register can be used for input capture mode (this section) or for output compare mode (next section). The direction of a channel is defined by configuring the corresponding CCxS bits. All the other bits of this register have a different function for input capture and for output compare modes. It is possible to combine both modes independently (for example channel 3 in input capture mode and channel 4 in output compare mode).
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| IC4F[3:0] | IC4PSC[1:0] | CC4S[1:0] | IC3F[3:0] | IC3PSC[1:0] | CC3S[1:0] | ||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Input capture mode

Bits 31:16 Reserved, must be kept at reset value.
Bits 15:12 IC4F[3:0]: Input capture 4 filter
Refer to IC3F[3:0] bit description
Bits 11:10 IC4PSC[1:0]: Input capture 4 prescaler
Refer to IC3PSC[1:0] bit description
Bits 9:8 CC4S[1:0]: Capture/compare 4 selection
This bitfield defines the direction of the channel (input/output) as well as the used input.
00: CC4 channel is configured as output
01: CC4 channel is configured as input, tim_ic4 is mapped on tim_ti4
10: CC4 channel is configured as input, tim_ic4 is mapped on tim_ti3
11: CC4 channel is configured as input, tim_ic4 is mapped on tim_trc. This mode is working only if an internal trigger input is selected through TS bit (TIM_SMCR register)
Note: CC4S bits are writable only when the channel is OFF (CC4E = 0 in TIM_CCER).
Bits 7:4 IC3F[3:0]: Input capture 3 filter
This bitfield defines the frequency used to sample tim_ti3 input and the length of the digital filter applied to tim_ti3. The digital filter is made of an event counter in which N consecutive events are needed to validate a transition on the output:
0000: No filter, sampling is done at \(f_{DTS2}\)
0001: \(f_{SAMPLING} = f_{tim\_ker\_ck}\), N = 2
0010: \(f_{SAMPLING} = f_{tim\_ker\_ck}\), N = 4
0011: \(f_{SAMPLING} = f_{tim\_ker\_ck}\), N = 8
0100: \(f_{SAMPLING} = f_{DTS2}/2\), N = 6
0101: \(f_{SAMPLING} = f_{DTS2}/2\), N = 8
0110: \(f_{SAMPLING} = f_{DTS2}/4\), N = 6
0111: \(f_{SAMPLING} = f_{DTS2}/4\), N = 8
1000: \(f_{SAMPLING} = f_{DTS2}/8\), N = 6
1001: \(f_{SAMPLING} = f_{DTS2}/8\), N = 8
1010: \(f_{SAMPLING} = f_{DTS2}/16\), N = 5
1011: \(f_{SAMPLING} = f_{DTS2}/16\), N = 6
1100: \(f_{SAMPLING} = f_{DTS2}/16\), N = 8
1101: \(f_{SAMPLING} = f_{DTS2}/32\), N = 5
1110: \(f_{SAMPLING} = f_{DTS2}/32\), N = 6
1111: \(f_{SAMPLING} = f_{DTS2}/32\), N = 8
Bits 3:2 IC3PSC[1:0]: Input capture 3 prescaler
This bitfield defines the ratio of the prescaler acting on CC3 input (tim_ic3). The prescaler is reset as soon as CC3E = 0 (TIM_CCER register).
00: no prescaler, capture is done each time an edge is detected on the capture input
01: capture is done once every 2 events
10: capture is done once every 4 events
11: capture is done once every 8 events
Bits 1:0 CC3S[1:0]: Capture/compare 3 selection
This bitfield defines the direction of the channel (input/output) as well as the used input.
00: CC3 channel is configured as output
01: CC3 channel is configured as input, tim_ic3 is mapped on tim_ti3
10: CC3 channel is configured as input, tim_ic3 is mapped on tim_ti4
11: CC3 channel is configured as input, tim_ic3 is mapped on tim_trc. This mode is working only if an internal trigger input is selected through TS bit (TIM_SMCR register)
Note: CC3S bits are writable only when the channel is OFF (CC3E = 0 in TIM_CCER).
31.6.10 TIM capture/compare mode register 2 [alternate] (TIM_CCMR2)
Address offset: 0x01C
Reset value: 0x0000 0000
The same register can be used for output compare mode (this section) or for input capture mode (previous section). The direction of a channel is defined by configuring the corresponding CCxS bits. All the other bits of this register have a different function for input capture and for output compare modes. It is possible to combine both modes independently (for example channel 3 in input capture mode and channel 4 in output compare mode).
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | OC4M[4:3] | Res. | Res. | Res. | Res. | Res. | Res. | OC3M[4:3] | ||
| rw | rw | rw | rw | ||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| OC4CE | OC4M[2:0] | OC4PE | OC4FE | CC4S[1:0] | OC3CE | OC3M[2:0] | OC3PE | OC3FE | CC3S[1:0] | ||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Output compare mode
Bits 31:26 Reserved, must be kept at reset value.
Bits 23:18 Reserved, must be kept at reset value.
Bit 15 OC4CE: Output compare 4 clear enable
0: tim_oc4ref is not affected by the tim_ocref_clr_int signal
1: tim_oc4ref is cleared as soon as a High level is detected on tim_ocref_clr_int signal (tim_ocref_clr input or tim_etrf input)
Note: This mode is not available for all PWM modes. Refer to Section 31.3.23: Clearing the tim_ocxref signal on an external event for the list of forbidden configurations.
Bits 25:24, 14:12 OC4M[4:0]: Output compare 4 mode
Refer to OC3M[4:0] bit description
Bit 11 OC4PE: Output compare 4 preload enable
0: Preload register on TIM_CCR4 disabled. TIM_CCR4 can be written at anytime, the new value is taken in account immediately.
1: Preload register on TIM_CCR4 enabled. Read/Write operations access the preload register. TIM_CCR4 preload value is loaded in the active register at each update event.
These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIM_BDTR register) and CC1S = 00 (the channel is configured in output).
Bit 10 OC4FE: Output compare 4 fast enable
This bit decreases the latency between a trigger event and a transition on the timer output. It must be used in one-pulse mode (OPM bit set in TIM_CR1 register), to have the output pulse starting as soon as possible after the starting trigger.
0: CC4 behaves normally depending on counter and CCR4 values even when the trigger is ON. The minimum delay to activate CC4 output when an edge occurs on the trigger input is 5 clock cycles.
1: An active edge on the trigger input acts like a compare match on CC4 output. Then, OC is set to the compare level independently from the result of the comparison. Delay to sample the trigger input and to activate CC4 output is reduced to 3 clock cycles. OCFE acts only if the channel is configured in PWM1 or PWM2 mode.
Bits 9:8 CC4S[1:0]: Capture/compare 4 selection
This bitfield defines the direction of the channel (input/output) as well as the used input.
00: CC4 channel is configured as output
01: CC4 channel is configured as input, tim_ic4 is mapped on tim_ti4
10: CC4 channel is configured as input, tim_ic4 is mapped on tim_ti3
11: CC4 channel is configured as input, tim_ic4 is mapped on tim_trc. This mode is working only if an internal trigger input is selected through TS bit (TIM_SMCR register)
Note: CC4S bits are writable only when the channel is OFF (CC4E = 0 in TIM_CCER).
Bit 7 OC3CE: Output compare 3 clear enable
0: tim_oc3ref is not affected by the tim_ocref_clr_int signal
1: tim_oc3ref is cleared as soon as a High level is detected on tim_ocref_clr_int signal (tim_ocref_clr input or tim_etrf input)
Note: This mode is not available for all PWM modes. Refer to Section 31.3.23: Clearing the tim_ocxref signal on an external event for the list of forbidden configurations.
Bits 17:16, 6:4 OC3M[4:0]: Output compare 3 mode
These bits define the behavior of the output reference signal tim_oc3ref from which tim_oc3 and tim_oc3n are derived. tim_oc3ref is active high whereas tim_oc3 and tim_oc3n active level depends on CC3P and CC3NP bits.
00000:Frozen - The comparison between the output compare register TIM_CCR3 and the counter TIM_CNT has no effect on the outputs.(this mode is used to generate a timing base).
00001:Set channel 3 to active level on match. tim_oc3ref signal is forced high when the counter TIM_CNT matches the capture/compare register 3 (TIM_CCR3).
00010:Set channel 3 to inactive level on match. tim_oc3ref signal is forced low when the counter TIM_CNT matches the capture/compare register 3 (TIM_CCR3).
00011:Toggle - tim_oc3ref toggles when TIM_CNT= TIM_CCR3.
00100:Force inactive level - tim_oc3ref is forced low.
00101:Force active level - tim_oc3ref is forced high.
00110:PWM mode 1 - In upcounting, channel 3 is active as long as TIM_CNT< TIM_CCR3 else inactive. In downcounting, channel 3 is inactive (tim_oc3ref= 0) as long as TIM_CNT> TIM_CCR3 else active (tim_oc3ref= 1).
00111:PWM mode 2 - In upcounting, channel 3 is inactive as long as TIM_CNT< TIM_CCR3 else active. In downcounting, channel 3 is active as long as TIM_CNT> TIM_CCR3 else inactive.
01000:Retrigerrable OPM mode 1 - In up-counting mode, the channel is active until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 1 and the channels becomes active again at the next update. In down-counting mode, the channel is inactive until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 1 and the channels becomes inactive again at the next update.
01001:Retrigerrable OPM mode 2 - In up-counting mode, the channel is inactive until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 2 and the channels becomes inactive again at the next update. In down-counting mode, the channel is active until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 1 and the channels becomes active again at the next update.
01010:Pulse on compare: a pulse is generated on tim_oc3ref upon CCR3 match event, as per PWPRSC[2:0] and PW[7:0] bitfields programming in TIM_ECR.
01011:Direction output. The tim_oc3ref signal is overridden by a copy of the DIR bit.
01100-01101:Combined PWM mode 1 and 2. Refer to Table 296 for details.
01110-01111:Asymmetric PWM mode 1 and 2. Refer to Table 295 for details.
10000-10001:Combined PWM mode 3 and 4. Refer to Table 296 for details.
10010-11001: Asymmetric PWM mode 3 to 10. Refer to Table 295 for details.
Others: Reserved
Note: These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIM_BDTR register) and CC1S= 00 (the channel is configured in output).
Note: In PWM mode, the OCREF level changes only when the result of the comparison changes or when the output compare mode switches from “frozen” mode to “PWM” mode.
Note: On channels having a complementary output, this bitfield is preloaded. If the CCPC bit is set in the TIM_CR2 register then the OC3M active bits take the new value from the preloaded bits only when a COM event is generated.
Bit 3 OC3PE: Output compare 3 preload enable
0: Preload register on TIM_CCR3 disabled. TIM_CCR3 can be written at anytime, the new value is taken in account immediately.
1: Preload register on TIM_CCR3 enabled. Read/Write operations access the preload register. TIM_CCR3 preload value is loaded in the active register at each update event.
These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIM_BDTR register) and CC1S = 00 (the channel is configured in output).
Bit 2 OC3FE: Output compare 3 fast enable
This bit decreases the latency between a trigger event and a transition on the timer output. It must be used in one-pulse mode (OPM bit set in TIM_CR1 register), to have the output pulse starting as soon as possible after the starting trigger.
0: CC3 behaves normally depending on counter and CCR3 values even when the trigger is ON. The minimum delay to activate CC3 output when an edge occurs on the trigger input is 5 clock cycles.
1: An active edge on the trigger input acts like a compare match on CC3 output. Then, OC is set to the compare level independently from the result of the comparison. Delay to sample the trigger input and to activate CC3 output is reduced to 3 clock cycles. OCFE acts only if the channel is configured in PWM1 or PWM2 mode.
Bits 1:0 CC3S[1:0]: Capture/compare 3 selection
This bitfield defines the direction of the channel (input/output) as well as the used input.
00: CC3 channel is configured as output
01: CC3 channel is configured as input, tim_ic3 is mapped on tim_ti3
10: CC3 channel is configured as input, tim_ic3 is mapped on tim_ti4
11: CC3 channel is configured as input, tim_ic3 is mapped on tim_trc. This mode is working only if an internal trigger input is selected through TS bit (TIM_SMCR register)
Note: CC3S bits are writable only when the channel is OFF (CC3E = 0 in TIM_CCER).
31.6.11 TIM capture/compare enable register (TIM_CCER)
Address offset: 0x020
Reset value: 0x0000 0000
| column_1 | column_2 | Bit 3 Bit 2 Bits 1:0 | OC3PE OC3FE CC3S[1:0] | is 5 clock cycles. | column_6 | column_7 | column_8 | column_9 | column_10 | column_11 | column_12 | column_13 | column_14 | column_15 | RM0522 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | CC7P CC7E | Res. | Res. | CC6P CC6E | Res. | Res. | CC5P CC5E | |||
| rw | rw | rw | rw | rw | rw | ||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
| Bit 25 | CC7P | : Capture/compare 7 output polarity | |||||||||||||
| Bit 24 | CC7E | : Capture/compare 7 output enable | |||||||||||||
| Bit 21 | CC6P | : Capture/compare 6 output polarity |
Bits 31:26 Reserved, must be kept at reset value.
Bit 25 CC7P: Capture/compare 7 output polarity
Refer to CC1P description
Bit 24 CC7E: Capture/compare 7 output enable
Refer to CC1E description
Bits 23:22 Reserved, must be kept at reset value.
Bit 21 CC6P: Capture/compare 6 output polarity
Refer to CC1P description
- Bit 20 CC6E: Capture/compare 6 output enable
Refer to CC1E description - Bits 19:18 Reserved, must be kept at reset value.
- Bit 17 CC5P: Capture/compare 5 output polarity
Refer to CC1P description - Bit 16 CC5E: Capture/compare 5 output enable
Refer to CC1E description - Bit 15 CC4NP: Capture/compare 4 complementary output polarity
Refer to CC1NP description - Bit 14 CC4NE: Capture/compare 4 complementary output enable
Refer to CC1NE description - Bit 13 CC4P: Capture/compare 4 output polarity
Refer to CC1P description - Bit 12 CC4E: Capture/compare 4 output enable
Refer to CC1E description - Bit 11 CC3NP: Capture/compare 3 complementary output polarity
Refer to CC1NP description - Bit 10 CC3NE: Capture/compare 3 complementary output enable
Refer to CC1NE description - Bit 9 CC3P: Capture/compare 3 output polarity
Refer to CC1P description - Bit 8 CC3E: Capture/compare 3 output enable
Refer to CC1E description - Bit 7 CC2NP: Capture/compare 2 complementary output polarity
Refer to CC1NP description - Bit 6 CC2NE: Capture/compare 2 complementary output enable
Refer to CC1NE description - Bit 5 CC2P: Capture/compare 2 output polarity
Refer to CC1P description - Bit 4 CC2E: Capture/compare 2 output enable
Refer to CC1E description - Bit 3 CC1NP: Capture/compare 1 complementary output polarity
CC1 channel configured as output:
0: tim_oc1n active high.
1: tim_oc1n active low.
CC1 channel configured as input:
This bit is used in conjunction with CC1P to define the polarity of tim_ti1fp1 and tim_ti2fp1.
Refer to CC1P description.
Note: This bit is not writable as soon as LOCK level 2 or 3 has been programmed (LOCK bits in TIM_BDTR register) and CC1S = 00 (channel configured as output).
Note: On channels having a complementary output, this bit is preloaded. If the CCPC bit is set in the TIM_CR2 register then the CC1NP active bit takes the new value from the preloaded bit only when a Commutation event is generated.
Note: In input mode, this bit is preloaded as per CCPC bit in TIM_CR2.
Bit 2 CC1NE: Capture/compare 1 complementary output enable
0: Off - tim_oc1n is not active. tim_oc1n level is then function of MOE, OSSI, OSSR, OIS1, OIS1N and CC1E bits.
1: On - tim_oc1n signal is output on the corresponding output pin depending on MOE, OSSI, OSSR, OIS1, OIS1N and CC1E bits.
Note: On channels having a complementary output, this bit is preloaded. If the CCPC bit is set in the TIM_CR2 register then the CC1NE active bit takes the new value from the preloaded bit only when a Commutation event is generated.
Bit 1 CC1P: Capture/compare 1 output polarity
0: OC1 active high (output mode) / Edge sensitivity selection (input mode, see below)
1: OC1 active low (output mode) / Edge sensitivity selection (input mode, see below)
When CC1 channel is configured as input, both CC1NP/CC1P bits select the active polarity of TI1FP1 and TI2FP1 for trigger or capture operations.
CC1NP = 0, CC1P = 0: non-inverted/rising edge. The circuit is sensitive to TIxFP1 rising edge (capture or trigger operations in reset, external clock or trigger mode), TIxFP1 is not inverted (trigger operation in gated mode or encoder mode).
CC1NP = 0, CC1P = 1: inverted/falling edge. The circuit is sensitive to TIxFP1 falling edge (capture or trigger operations in reset, external clock or trigger mode), TIxFP1 is inverted (trigger operation in gated mode or encoder mode).
CC1NP = 1, CC1P = 1: non-inverted/both edges/ The circuit is sensitive to both TIxFP1 rising and falling edges (capture or trigger operations in reset, external clock or trigger mode), TIxFP1 is not inverted (trigger operation in gated mode). This configuration must not be used in encoder mode.
CC1NP = 1, CC1P = 0: the configuration is reserved, it must not be used.
Note: This bit is not writable as soon as LOCK level 2 or 3 has been programmed (LOCK bits in TIM_BDTR register).
Note: On channels having a complementary output, this bit is preloaded. If the CCPC bit is set in the TIM_CR2 register then the CC1P active bit takes the new value from the preloaded bit only when a Commutation event is generated.
Note: In input mode, this bit is preloaded as per CCPC bit in TIM_CR2.
Bit 0 CC1E: Capture/compare 1 output enable
0: Capture mode disabled / OC1 is not active (see below)
1: Capture mode enabled / OC1 signal is output on the corresponding output pin
When CC1 channel is configured as output, the OC1 level depends on MOE, OSSI, OSSR, OIS1, OIS1N and CC1NE bits, regardless of the CC1E bits state. Refer to Table 304 for details.
Note: On channels having a complementary output, this bit is preloaded. If the CCPC bit is set in the TIM_CR2 register then the CC1E active bit takes the new value from the preloaded bit only when a Commutation event is generated.
Table 304. Output control bits for complementary tim_ocx and tim_ocxn channels with break feature
| Control bits | Output states(1) | |||||
|---|---|---|---|---|---|---|
| MOE bit | OSSI bit | OSSR bit | CCxE bit | CCxNE bit | tim_ocx output state | tim_ocxn output state |
| 1 | X | 0 | 0 | 0 | Output disabled (not driven by the timer: Hi-Z) tim_ocx = 0, tim_ocxn = 0 | |
| 1 | 0 | 0 | Off-State (output enabled with inactive state) tim_ocx=CCxP, tim_ocxn=CCxNP | |||
| 0 | 0 | 1 | Output disabled (not driven by the timer: Hi-Z) tim_ocx = 0 | tim_ocxref + Polarity tim_ocxn = tim_ocxref xor CCxNP | ||
| 0 | 1 | 0 | tim_ocxref + Polarity tim_ocx = tim_ocxref xor CCxP | Output Disabled (not driven by the timer: Hi-Z) tim_ocxn = 0 | ||
| X | 1 | 1 | OCREF + Polarity + dead-time | Complementary to OCREF (not OCREF) + Polarity + dead-time | ||
| 1 | 0 | 1 | Off-State (output enabled with inactive state) tim_ocx = CCxP | tim_ocxref + Polarity tim_ocxn = tim_ocxref x or CCxNP | ||
| 1 | 1 | 0 | tim_ocxref + Polarity tim_ocx = tim_ocxref xor CCxP | Off-State (output enabled with inactive state) tim_ocxn = CCxNP | ||
| 0 | 0 | X | X | X | Output disabled (not driven by the timer: Hi-Z). | |
| 1 | 0 | 0 | ||||
| 0 | 1 | Off-State (output enabled with inactive state) | ||||
| 1 | 0 | Asynchronously: tim_ocx = CCxP, tim_ocxn = CCxNP (if tim_brk or tim_brk2 is triggered). | ||||
| 1 | 1 | Then (this is valid only if tim_brk is triggered), if the clock is present: tim_ocx = OISx and tim_ocxn = OISxN after a dead-time, assuming that OISx and OISxN do not correspond to OCX and tim_ocxn both in active state (may cause a short circuit when driving switches in half-bridge configuration). Note: tim_brk2 can only be used if OSSI = OSSR = 1. | ||||
- 1. When both outputs of a channel are not used (control taken over by GPIO), the OISx, OISxN, CCxP and CCxNP bits must be kept cleared.
Note: The state of the external I/O pins connected to the complementary tim_ocx and tim_ocxn channels depends on the tim_ocx and tim_ocxn channel state and the GPIO registers.
31.6.12 TIM counter (TIM_CNT)
Address offset: 0x024
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| UIFCP Y | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| r | |||||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| CNT[15:0] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bit 31 UIFCPY: UIF copy
This bit is a read-only copy of the UIF bit of the TIM_ISR register. If the UIFREMAP bit in the TIM_CR1 is reset, bit 31 is reserved and read at 0.
Bits 30:16 Reserved, must be kept at reset value.
Bits 15:0 CNT[15:0]: Counter value
Non-dithering mode (DITHEN = 0)
The register holds the counter value.
Dithering mode (DITHEN = 1)
The register only holds the non-dithered part in CNT[15:0]. The fractional part is not available.
31.6.13 TIM prescaler (TIM_PSC)
Address offset: 0x028
Reset value: 0x0000
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| PSC[15:0] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 15:0 PSC[15:0]: Prescaler value
The counter clock frequency (\(f_{tim\_cnt\_ck}\)) is equal to \(f_{tim\_psc\_ck} / (PSC[15:0] + 1)\).
PSC contains the value to be loaded in the active prescaler register at each update event (including when the counter is cleared through UG bit of TIM_EGR register or through trigger controller when configured in “reset mode”).
31.6.14 TIM autoreload register (TIM_ARR)
Address offset: 0x02C
Reset value: 0x0000 FFFF
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | ARR[19:16] | |||
| rw | rw | rw | rw | ||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| ARR[15:0] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:20 Reserved, must be kept at reset value.
Bits 19:0 ARR[19:0]: Autoreload value
ARR is the value to be loaded in the actual autoreload register.
Refer to the Section 31.3.3: Time-base unit for more details about ARR update and behavior.
The counter is blocked while the autoreload value is null.
Non-dithering mode (DITHEN = 0)
The register holds the autoreload value.
Dithering mode (DITHEN = 1)
The register holds the integer part in ARR[19:4]. The ARR[3:0] bitfield contains the dithered part.
31.6.15 TIM repetition counter register (TIM_RCR)
Address offset: 0x030
Reset value: 0x0000
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| REP[15:0] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 15:0 REP[15:0]: Repetition counter reload value
This bitfield defines the update rate of the compare registers (i.e. periodic transfers from preload to active registers) when preload registers are enable. It also defines the update interrupt generation rate, if this interrupt is enable.
When the repetition down-counter reaches zero, an update event is generated and it restarts counting from REP value. As the repetition counter is reloaded with REP value only at the repetition update event UEV, any write to the TIM_RCR register is not taken in account until the next repetition update event.
It means in PWM mode (REP+1) corresponds to:
- – the number of PWM periods in edge-aligned mode
- – the number of half PWM period in center-aligned mode.
31.6.16 TIM capture/compare register 1 (TIM_CCR1)
Address offset: 0x034
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CCR1[19:16] | |||
| rw | rw | rw | rw | ||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| CCR1[15:0] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:20 Reserved, must be kept at reset value.
Bits 19:0 CCR1[19:0]: Capture/compare 1 value
If channel CC1 is configured as output: CCR1 is the value to be loaded in the actual capture/compare 1 register (preload value).
It is loaded permanently if the preload feature is not selected in the TIM_CCMR1 register (bit OC1PE). Else the preload value is copied in the active capture/compare 1 register when an update event occurs.
The active capture/compare register contains the value to be compared to the counter TIM_CNT and signaled on tim_oc1 output.
Non-dithering mode (DITHEN = 0)
The register holds the compare value in CCR1[15:0]. The CCR1[19:16] bits are reset.
Dithering mode (DITHEN = 1)
The register holds the integer part in CCR1[19:4]. The CCR1[3:0] bitfield contains the dithered part.
If channel CC1 is configured as input: CR1 is the counter value transferred by the last input capture 1 event (tim_ic1). The TIM_CCR1 register is read-only and cannot be programmed.
Non-dithering mode (DITHEN = 0)
The register holds the capture value in CCR1[15:0]. The CCR1[19:16] bits are reset.
Dithering mode (DITHEN = 1)
The register holds the capture in CCR1[19:4]. The CCR1[3:0] bits are reset.
31.6.17 TIM capture/compare register 2 (TIM_CCR2)
Address offset: 0x038
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CCR2[19:16] | |||
| rw | rw | rw | rw | ||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| CCR2[15:0] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:20 Reserved, must be kept at reset value.
Bits 19:0 CCR2[19:0]: Capture/compare 2 value
If channel CC2 is configured as output: CCR2 is the value to be loaded in the actual capture/compare 2 register (preload value).
It is loaded permanently if the preload feature is not selected in the TIM_CCMR1 register (bit OC2PE). Else the preload value is copied in the active capture/compare 2 register when an update event occurs.
The active capture/compare register contains the value to be compared to the counter TIM_CNT and signaled on tim_oc2 output.
Non-dithering mode (DITHEN = 0)
The register holds the compare value in CCR2[15:0]. The CCR2[19:16] bits are reset.
Dithering mode (DITHEN = 1)
The register holds the integer part in CCR2[19:4]. The CCR2[3:0] bitfield contains the dithered part.
If channel CC2 is configured as input: CCR2 is the counter value transferred by the last input capture 2 event (tim_ic2). The TIM_CCR2 register is read-only and cannot be programmed.
Non-dithering mode (DITHEN = 0)
The register holds the capture value in CCR2[15:0]. The CCR2[19:16] bits are reset.
Dithering mode (DITHEN = 1)
The register holds the capture in CCR2[19:4]. The CCR2[3:0] bits are reset.
31.6.18 TIM capture/compare register 3 (TIM_CCR3)
Address offset: 0x03C
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CCR3[19:16] | |||
| rw | rw | rw | rw | ||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| CCR3[15:0] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:20 Reserved, must be kept at reset value.
Bits 19:0 CCR3[19:0]: Capture/compare value
If channel CC3 is configured as output: CCR3 is the value to be loaded in the actual capture/compare 3 register (preload value).
It is loaded permanently if the preload feature is not selected in the TIM_CCMR2 register (bit OC3PE). Else the preload value is copied in the active capture/compare 3 register when an update event occurs.
The active capture/compare register contains the value to be compared to the counter TIM_CNT and signaled on tim_oc3 output.
Non-dithering mode (DITHEN = 0)
The register holds the compare value in CCR3[15:0]. The CCR3[19:16] bits are reset.
Dithering mode (DITHEN = 1)
The register holds the integer part in CCR3[19:4]. The CCR3[3:0] bitfield contains the dithered part.
If channel CC3 is configured as input: CCR3 is the counter value transferred by the last input capture 3 event (tim_ic3). The TIM_CCR3 register is read-only and cannot be programmed.
Non-dithering mode (DITHEN = 0)
The register holds the capture value in CCR3[15:0]. The CCR3[19:16] bits are reset.
Dithering mode (DITHEN = 1)
The register holds the capture in CCR3[19:4]. The CCR3[3:0] bits are reset.
31.6.19 TIM capture/compare register 4 (TIM_CCR4)
Address offset: 0x040
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CCR4[19:16] | |||
| rw | rw | rw | rw | ||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| CCR4[15:0] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:20 Reserved, must be kept at reset value.
Bits 19:0 CCR4[19:0]: Capture/compare value
If channel CC4 is configured as output: CCR4 is the value to be loaded in the actual capture/compare 4 register (preload value).
It is loaded permanently if the preload feature is not selected in the TIM_CCMR2 register (bit OC4PE). Else the preload value is copied in the active capture/compare 4 register when an update event occurs.
The active capture/compare register contains the value to be compared to the counter TIM_CNT and signalled on tim_oc4 output.
Non-dithering mode (DITHEN = 0)
The register holds the compare value in CCR4[15:0]. The CCR4[19:16] bits are reset.
Dithering mode (DITHEN = 1)
The register holds the integer part in CCR4[19:4]. The CCR4[3:0] bitfield contains the dithered part.
If channel CC4 is configured as input: CCR4 is the counter value transferred by the last input capture 4 event (tim_ic4). The TIM_CCR4 register is read-only and cannot be programmed.
Non-dithering mode (DITHEN = 0)
The register holds the capture value in CCR4[15:0]. The CCR4[19:16] bits are reset.
Dithering mode (DITHEN = 1)
The register holds the capture in CCR4[19:4]. The CCR4[3:0] bits are reset.
31.6.20 TIM break and dead-time register (TIM_BDTR)
Address offset: 0x044
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | BK2BI D | BKBID | BK2DS RM | BKDSR M | BK2P | BK2E | BK2F[3:0] | BKF[3:0] | ||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | ||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| MOE | AOE | BKP | BKE | OSSR | OSSI | LOCK[1:0] | DTG[7:0] | ||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Note: As the bits BKBID/BK2BID/BK2P, BK2E, BK2F[3:0], BKF[3:0], AOE, BKP, BKE, OSSI, OSSR, and DTG[7:0] can be write-locked depending on the LOCK configuration, it can be necessary to configure all of them during the first write access to the TIM_BDTR register.
Bits 31:30 Reserved, must be kept at reset value.
Bit 29 BK2BID: Break2 bidirectional
Refer to BKBID description
Bit 28 BKBID: Break bidirectional
0: Break input tim_brk in input mode
1: Break input tim_brk in bidirectional mode
In the bidirectional mode (BKBID bit set to 1), the break input is configured both in input mode and in open drain output mode. Any active break event asserts a low logic level on the Break input to indicate an internal break event to external devices.
Note: This bit cannot be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Note: Any write operation to this bit takes a delay of 1 APB clock cycle to become effective.
Bit 27 BK2DSRM: Break2 disarm
Refer to BKDSRM description
Bit 26 BKDSRM: Break disarm
0: Break input tim_brk is armed
1: Break input tim_brk is disarmed
This bit is cleared by hardware when no break source is active.
The BKDSRM bit must be set by software to release the bidirectional output control (open-drain output in Hi-Z state) and then be polled it until it is reset by hardware, indicating that the fault condition has disappeared.
Note: Any write operation to this bit takes a delay of 1 APB clock cycle to become effective.
Bit 25 BK2P: Break 2 polarity
0: Break input tim_brk2 is active low
1: Break input tim_brk2 is active high
Note: This bit cannot be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register) and when BK2E bit is set.
Note: Any write operation to this bit takes a delay of 1 tim_ker_ck clock cycle to become effective.
Bit 24 BK2E: Break 2 enable
This bit enables the complete break 2 protection, see Figure 269: Break and Break2 circuitry overview.
0: Break2 function disabled
1: Break2 function enabled
Note: The BRKIN2 must only be used with OSSR = OSSI = 1.
Note: This bit cannot be modified when LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Note: Any write operation to this bit takes a delay of 1 tim_ker_ck clock cycle to become effective.
Bits 23:20 BK2F[3:0]: Break 2 filter
This bitfield defines the frequency used to sample tim_brk2 input and the length of the digital filter applied to tim_brk2. The digital filter is made of an event counter in which N consecutive events are needed to validate a transition on the output:
0000: No filter, tim_brk2 acts asynchronously
0001: fSAMPLING = ftim_ker_ck, N = 2
0010: fSAMPLING = ftim_ker_ck, N = 4
0011: fSAMPLING = ftim_ker_ck, N = 8
0100: fSAMPLING = fDTS/2, N = 6
0101: fSAMPLING = fDTS/2, N = 8
0110: fSAMPLING = fDTS/4, N = 6
0111: fSAMPLING = fDTS/4, N = 8
1000: fSAMPLING = fDTS/8, N = 6
1001: fSAMPLING = fDTS/8, N = 8
1010: fSAMPLING = fDTS/16, N = 5
1011: fSAMPLING = fDTS/16, N = 6
1100: fSAMPLING = fDTS/16, N = 8
1101: fSAMPLING = fDTS/32, N = 5
1110: fSAMPLING = fDTS/32, N = 6
1111: fSAMPLING = fDTS/32, N = 8
Note: This bit cannot be modified when LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register) and when BK2E bit is set.
Bits 19:16 BKF[3:0]: Break filter
This bitfield defines the frequency used to sample tim_brk input and the length of the digital filter applied to tim_brk. The digital filter is made of an event counter in which N consecutive events are needed to validate a transition on the output:
0000: No filter, tim_brk acts asynchronously
0001: fSAMPLING = ftim_ker_ck, N = 2
0010: fSAMPLING = ftim_ker_ck, N = 4
0011: fSAMPLING = ftim_ker_ck, N = 8
0100: fSAMPLING = fDTS/2, N = 6
0101: fSAMPLING = fDTS/2, N = 8
0110: fSAMPLING = fDTS/4, N = 6
0111: fSAMPLING = fDTS/4, N = 8
1000: fSAMPLING = fDTS/8, N = 6
1001: fSAMPLING = fDTS/8, N = 8
1010: fSAMPLING = fDTS/16, N = 5
1011: fSAMPLING = fDTS/16, N = 6
1100: fSAMPLING = fDTS/16, N = 8
1101: fSAMPLING = fDTS/32, N = 5
1110: fSAMPLING = fDTS/32, N = 6
1111: fSAMPLING = fDTS/32, N = 8
Note: This bit cannot be modified when LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register) and when BKE bit is set.
Bit 15 MOE: Main output enable
This bit is cleared asynchronously by hardware as soon as one of the break inputs is active (tim_brk or tim_brk2). It is set by software or automatically depending on the AOE bit. It is acting only on the channels which are configured in output.
0: In response to a break 2 event. OC and OCN outputs are disabled
In response to a break event or if MOE is written to 0: OC and OCN outputs are disabled or forced to idle state depending on the OSSR bit.
1: OC and OCN outputs are enabled if their respective enable bits are set (CCxE, CCxNE in TIM_CCER register).
See OC/OCN enable description for more details (Section 31.6.11: TIM capture/compare enable register (TIM_CCER)).
Bit 14 AOE: Automatic output enable
0: MOE can be set only by software
1: MOE can be set by software or automatically at the next update event (if none of the break inputs tim_brk and tim_brk2 is active)
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 13 BKP: Break polarity
0: Break input tim_brk is active low
1: Break input tim_brk is active high
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register) and when BKE bit is set.
Note: Any write operation to this bit takes a delay of 1 tim_cker_ck clock cycle to become effective.
Bit 12 BKE: Break enable
This bit enables the complete break protection (including all sources connected to tim_sys_brk and BKIN sources, as per Figure 269: Break and Break2 circuitry overview).
0: Break function disabled
1: Break function enabled
Note: This bit cannot be modified when LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Note: Any write operation to this bit takes a delay of 1 tim_cker_ck clock cycle to become effective.
Bit 11 OSSR: Off-state selection for Run mode
This bit is used when MOE = 1 on channels having a complementary output which are configured as outputs. OSSR is not implemented if no complementary output is implemented in the timer.
See OC/OCN enable description for more details (Section 31.6.11: TIM capture/compare enable register (TIM_CCER)).
0: When inactive, OC/OCN outputs are disabled (the timer releases the output control which is taken over by the GPIO logic, which forces a Hi-Z state).
1: When inactive, OC/OCN outputs are enabled with their inactive level as soon as CCxE = 1 or CCxNE = 1 (the output is still controlled by the timer).
Note: This bit can not be modified as soon as the LOCK level 2 has been programmed (LOCK bits in TIM_BDTR register).
Bit 10 OSSI: Off-state selection for idle mode
This bit is used when MOE = 0 due to a break event or by a software write, on channels configured as outputs.
See OC/OCN enable description for more details (Section 31.6.11: TIM capture/compare enable register (TIM_CCER)).
0: When inactive, OC/OCN outputs are disabled (the timer releases the output control which is taken over by the GPIO logic and which imposes a Hi-Z state).
1: When inactive, OC/OCN outputs are first forced with their inactive level then forced to their idle level after the deadtime. The timer maintains its control over the output.
Note: This bit can not be modified as soon as the LOCK level 2 has been programmed (LOCK bits in TIM_BDTR register).
Bits 9:8 LOCK[1:0]: Lock configuration
These bits offer a write protection against software errors.
00: LOCK OFF - No bit is write protected.
01: LOCK Level 1 = DTG bits in TIM_BDTR register, OISx and OISxN bits in TIM_CR2 register and BKBID/BK2BID/BKE/BKP/AOE bits in TIM_BDTR register can no longer be written.
10: LOCK Level 2 = LOCK Level 1 + CC Polarity bits (CCxP/CCxNP bits in TIM_CCER register, as long as the related channel is configured in output through the CCxS bits) as well as OSSR and OSSI bits can no longer be written.
11: LOCK Level 3 = LOCK Level 2 + CC Control bits (OCxM and OCxPE bits in TIM_CCMRx registers, as long as the related channel is configured in output through the CCxS bits) can no longer be written.
Note: The LOCK bits can be written only once after the reset. Once the TIM_BDTR register has been written, their content is frozen until the next reset.
Bits 7:0 DTG[7:0]: Dead-time generator setup
This bitfield defines the duration of the dead-time inserted between the complementary outputs. DT correspond to this duration.
\(DTG[7:5] = 0xx \Rightarrow DT = DTG[7:0] \times t_{DTG}\) with \(t_{DTG} = t_{DTS}\).
\(DTG[7:5] = 10x \Rightarrow DT = (64+DTG[5:0]) \times t_{DTG}\) with \(t_{DTG} = 2 \times t_{DTS}\).
\(DTG[7:5] = 110 \Rightarrow DT = (32+DTG[4:0]) \times t_{DTG}\) with \(t_{DTG} = 8 \times t_{DTS}\).
\(DTG[7:5] = 111 \Rightarrow DT = (32+DTG[4:0]) \times t_{DTG}\) with \(t_{DTG} = 16 \times t_{DTS}\).
Example if \(t_{DTS} = 125\) ns (8 MHz), dead-time possible values are:
0 to 15875 ns by 125 ns steps,
16 μs to 31750 ns by 250 ns steps,
32 μs to 63 μs by 1 μs steps,
64 μs to 126 μs by 2 μs steps
Note: This bitfield can not be modified as long as LOCK level 1, 2 or 3 has been programmed (LOCK bits in TIM_BDTR register).
31.6.21 TIM capture/compare register 5 (TIM_CCR5)
Address offset: 0x048
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| GC5C3 | GC5C2 | GC5C1 | GC5C4 | GC5C4 O | GC5C3 O | GC5C2 O | GC5C1 O | Res. | Res. | Res. | Res. | CCR5[19:16] | |||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | ||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| CCR5[15:0] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
- Bit 31 GC5C3: Group channel 5 and channel 3
Distortion on channel 3 output:
0: No effect of tim_oc5ref on tim_oc3refc
1: tim_oc3refc is the logical AND of tim_oc3ref and tim_oc5ref
This bit can either have immediate effect or be preloaded and taken into account after an update event (if preload is enabled with OC5PE in TIM_CCMR3).
Note: it is also possible to apply this distortion on combined PWM signals. - Bit 30 GC5C2: Group channel 5 and channel 2
Distortion on channel 2 output:
0: No effect of tim_oc5ref on tim_oc2refc
1: tim_oc2refc is the logical AND of tim_oc2ref and tim_oc5ref
This bit can either have immediate effect or be preloaded and taken into account after an update event (if preload is enabled with OC5PE in TIM_CCMR3).
Note: it is also possible to apply this distortion on combined PWM signals. - Bit 29 GC5C1: Group channel 5 and channel 1
Distortion on channel 1 output:
0: No effect of oc5ref on oc1refc
1: oc1refc is the logical AND of oc1ref and oc5ref
This bit can either have immediate effect or be preloaded and taken into account after an update event (if preload is enabled with OC5PE in TIM_CCMR3).
Note: it is also possible to apply this distortion on combined PWM signals. - Bit 28 GC5C4: Group channel 5 and channel 4
Distortion on channel 1 output:
0: No effect of oc5ref on oc4refc
1: oc4refc is the logical AND of oc4ref and oc5ref
This bit can either have immediate effect or be preloaded and taken into account after an update event (if preload is enabled with OC5PE in TIM_CCMR3).
Note: it is also possible to apply this distortion on combined PWM signals. - Bit 27 GC5C4O: Group channel 5 and channel 4 (ORed)
Distortion on channel 4 output:
This bit can either have immediate effect or be preloaded and taken into account after an update event (if preload is enabled with OC5PE in TIM_CCMR3).
0: No effect of oc5ref on oc4refc
1: oc4refc is the logical OR of oc4ref and oc5ref
Note: it is also possible to apply this distortion on combined PWM signals. - Bit 26 GC5C3O: Group channel 5 and channel 3 (ORed)
Distortion on channel 3 output:
This bit can either have immediate effect or be preloaded and taken into account after an update event (if preload is enabled with OC5PE in TIM_CCMR3).
0: No effect of oc5ref on oc3refc
1: oc4refc is the logical OR of oc3ref and oc5ref
Note: it is also possible to apply this distortion on combined PWM signals.
Bit 25 GC5C2O: Group channel 5 and channel 2 (ORed)
Distortion on channel 2 output:
This bit can either have immediate effect or be preloaded and taken into account after an update event (if preload is enabled with OC5PE in TIM_CCMR3).
0: No effect of oc5ref on oc2refc
1: oc4refc is the logical OR of oc2ref and oc5ref
Note: it is also possible to apply this distortion on combined PWM signals.
Bit 24 GC5C1O: Group channel 5 and channel 1 (ORed)
Distortion on channel 1 output:
This bit can either have immediate effect or be preloaded and taken into account after an update event (if preload is enabled with OC5PE in TIM_CCMR3).
0: No effect of oc5ref on oc1refc
1: oc4refc is the logical OR of oc1ref and oc5ref
Note: it is also possible to apply this distortion on combined PWM signals.
Bits 23:20 Reserved, must be kept at reset value.
Bits 19:0 CCR5[19:0]: compare 5 value
CCR5 is the value to be loaded in the actual compare 5 register (preload value).
It is loaded permanently if the preload feature is not selected in the TIM_CCMR3 register (bit OC5PE). Else the preload value is copied in the active compare 5 register when an update event occurs.
The active compare register contains the value to be compared to the counter TIM_CNT and signaled on tim_oc5 output.
Non-dithering mode (DITHEN = 0)
The register holds the compare value in CCR5[15:0]. The CCR5[19:16] bits are reset.
Dithering mode (DITHEN = 1)
The register holds the integer part in CCR5[19:4]. The CCR5[3:0] bitfield contains the dithered part.
31.6.22 TIM capture/compare register 6 (TIM_CCR6)
Address offset: 0x04C
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CCR6[19:16] | |||
| rw | rw | rw | rw | ||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| CCR6[15:0] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:20 Reserved, must be kept at reset value.
Bits 19:0 CCR6[19:0]: Compare 6 value
CCR6 is the value to be loaded in the actual compare 6 register (preload value).
It is loaded permanently if the preload feature is not selected in the TIM_CCMR3 register (bit OC6PE). Else the preload value is copied in the active compare 6 register when an update event occurs.
The active compare register contains the value to be compared to the counter TIM_CNT and signaled on tim_oc6 output.
Non-dithering mode (DITHEN = 0)
The register holds the compare value in CCR6[15:0]. The CCR6[19:16] bits are reset.
Dithering mode (DITHEN = 1)
The register holds the integer part in CCR6[19:4]. The CCR6[3:0] bitfield contains the dithered part.
31.6.23 TIM capture/compare mode register 3 (TIM_CCMR3)
Address offset: 0x050
Reset value: 0x0000 0000
Refer to the above CCMR1 register description. Channels 5 and 6 can only be configured in output.
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | OC6M[4:3] | Res. | Res. | Res. | Res. | Res. | Res. | OC5M[4:3] | ||
| rw | rw | rw | rw | ||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| OC6CE | OC6M[2:0] | OC6PE | OC6FE | Res. | Res. | OC5CE | OC5M[2:0] | OC5PE | OC5FE | Res. | Res. | ||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | ||||
Bits 31:26 Reserved, must be kept at reset value.
Bits 23:18 Reserved, must be kept at reset value.
Bit 15 OC6CE: Output compare 6 clear enable
0: tim_oc6ref is not affected by the tim_ocref_clr_int signal
1: tim_oc6ref is cleared as soon as a High level is detected on tim_ocref_clr_int signal (tim_ocref_clr input or tim_etrif input)
Note: This mode is not available for all PWM modes. Refer to Section 31.3.23: Clearing the tim_ocxref signal on an external event for the list of forbidden configurations.
Bits 25:24, 14:12 OC6M[4:0]: Output compare 6 mode
Refer to OC5M[4:0] bit description
Bit 11 OC6PE: Output compare 6 preload enable
0: Preload register on TIM_CCR6 disabled. TIM_CCR6 can be written at anytime, the new value is taken in account immediately.
1: Preload register on TIM_CCR6 enabled. Read/Write operations access the preload register. TIM_CCR6 preload value is loaded in the active register at each update event.
These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIM_BDTR register) and CC1S = 00 (the channel is configured in output).
Bit 10 OC6FE: Output compare 6 fast enable
This bit decreases the latency between a trigger event and a transition on the timer output. It must be used in one-pulse mode (OPM bit set in TIM_CR1 register), to have the output pulse starting as soon as possible after the starting trigger.
0: CC6 behaves normally depending on counter and CCR6 values even when the trigger is ON. The minimum delay to activate CC6 output when an edge occurs on the trigger input is 5 clock cycles.
1: An active edge on the trigger input acts like a compare match on CC6 output. Then, OC is set to the compare level independently from the result of the comparison. Delay to sample the trigger input and to activate CC6 output is reduced to 3 clock cycles. OCFE acts only if the channel is configured in PWM1 or PWM2 mode.
Bits 9:8 Reserved, must be kept at reset value.
Bit 7 OC5CE: Output compare 5 clear enable
0: tim_oc5ref is not affected by the tim_oref_clr_int signal
1: tim_oc5ref is cleared as soon as a High level is detected on tim_oref_clr_int signal (tim_oref_clr input or tim_etr input)
Note: This mode is not available for all PWM modes. Refer to Section 31.3.23: Clearing the tim_ocxref signal on an external event for the list of forbidden configurations.
Bits 17:16, 6:4 OC5M[4:0]: Output compare 5 mode
These bits define the behavior of the output reference signal tim_oc5ref. tim_oc5ref is active high whereas tim_oc5 active level depends on CC5P bit.
00000:Frozen - The comparison between the output compare register TIM_CCR5 and the counter TIM_CNT has no effect on the outputs.(this mode is used to generate a timing base).
00001:Set channel 5 to active level on match. tim_oc5ref signal is forced high when the counter TIM_CNT matches the capture/compare register 5 (TIM_CCR5).
00010:Set channel 5 to inactive level on match. tim_oc5ref signal is forced low when the counter TIM_CNT matches the capture/compare register 5 (TIM_CCR5).
00011:Toggle - tim_oc5ref toggles when TIM_CNT= TIM_CCR5.
00100:Force inactive level - tim_oc5ref is forced low.
00101:Force active level - tim_oc5ref is forced high.
00110:PWM mode 1 - In upcounting, channel 5 is active as long as TIM_CNT< TIM_CCR5 else inactive. In downcounting, channel 5 is inactive (tim_oc5ref= 0) as long as TIM_CNT> TIM_CCR5 else active (tim_oc5ref= 1).
00111:PWM mode 2 - In upcounting, channel 5 is inactive as long as TIM_CNT< TIM_CCR5 else active. In downcounting, channel 5 is active as long as TIM_CNT> TIM_CCR5 else inactive.
01000:Retrigerrable OPM mode 1 - In up-counting mode, the channel is active until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 1 and the channels becomes active again at the next update. In down-counting mode, the channel is inactive until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 1 and the channels becomes inactive again at the next update.
01001:Retrigerrable OPM mode 2 - In up-counting mode, the channel is inactive until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 2 and the channels becomes inactive again at the next update. In down-counting mode, the channel is active until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 1 and the channels becomes active again at the next update.
01010-01011:Reserved.
01100-01101:Combined PWM mode 1 and 2. Refer to Table 296 for details.
01110-01111:Asymmetric PWM mode 1 and 2. Refer to Table 295 for details.
Others: Reserved
Note: These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIM_BDTR register) and CC1S= 00 (the channel is configured in output).
Note: In PWM mode, the OCREF level changes only when the result of the comparison changes or when the output compare mode switches from “frozen” mode to “PWM” mode.
Bit 3 OC5PE: Output compare 5 preload enable
0: Preload register on TIM_CCR5 disabled. TIM_CCR5 can be written at anytime, the new value is taken in account immediately.
1: Preload register on TIM_CCR5 enabled. Read/Write operations access the preload register. TIM_CCR5 preload value is loaded in the active register at each update event.
These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIM_BDTR register) and CC1S = 00 (the channel is configured in output).
Bit 2 OC5FE: Output compare 5 fast enable
This bit decreases the latency between a trigger event and a transition on the timer output. It must be used in one-pulse mode (OPM bit set in TIM_CR1 register), to have the output pulse starting as soon as possible after the starting trigger.
0: CC5 behaves normally depending on counter and CCR5 values even when the trigger is ON. The minimum delay to activate CC5 output when an edge occurs on the trigger input is 5 clock cycles.
1: An active edge on the trigger input acts like a compare match on CC5 output. Then, OC is set to the compare level independently from the result of the comparison. Delay to sample the trigger input and to activate CC5 output is reduced to 3 clock cycles. OCFE acts only if the channel is configured in PWM1 or PWM2 mode.
Bits 1:0 Reserved, must be kept at reset value.
31.6.24 TIM timer deadtime register 2 (TIM_DTR2)
Address offset: 0x054
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | DTPE | DTAE |
| rw | rw | ||||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | DTGF[7:0] | |||||||
| rw | rw | rw | rw | rw | rw | rw | rw | ||||||||
Bits 31:18 Reserved, must be kept at reset value.
Bit 17 DTPE: Deadtime preload enable
0: Deadtime value is not preloaded
1: Deadtime value preload is enabled
Note: This bit can not be modified as long as LOCK level 1, 2 or 3 has been programmed (LOCK bits in TIM_BDTR register).
Bit 16 DTAE: Deadtime asymmetric enable
0: Deadtime on rising and falling edges are identical, and defined with DTG[7:0] register
1: Deadtime on rising edge is defined with DTG[7:0] register and deadtime on falling edge is defined with DTGF[7:0] bits.
Note: This bit can not be modified as long as LOCK level 1, 2 or 3 has been programmed (LOCK bits in TIM_BDTR register).
Bits 15:8 Reserved, must be kept at reset value.
Bits 7:0 DTGF[7:0]: Dead-time falling edge generator setup
This bitfield defines the duration of the dead-time inserted between the complementary outputs, on the falling edge.
\(DTGF[7:5] = 0xx \Rightarrow DTF = DTGF[7:0] \times t_{DTG}\) with \(t_{DTG} = t_{DTS}\).
\(DTGF[7:5] = 10x \Rightarrow DTF = (64+DTGF[5:0]) \times t_{DTG}\) with \(t_{DTG} = 2 \times t_{DTS}\).
\(DTGF[7:5] = 110 \Rightarrow DTF = (32+DTGF[4:0]) \times t_{DTG}\) with \(t_{DTG} = 8 \times t_{DTS}\).
\(DTGF[7:5] = 111 \Rightarrow DTF = (32+DTGF[4:0]) \times t_{DTG}\) with \(t_{DTG} = 16 \times t_{DTS}\).
Example if \(t_{DTS} = 125\) ns (8 MHz), dead-time possible values are:
0 to 15875 ns by 125 ns steps,
16 μs to 31750 ns by 250 ns steps,
32 μs to 63 μs by 1 μs steps,
64 μs to 126 μs by 2 μs steps
Note: This bitfield can not be modified as long as LOCK level 1, 2 or 3 has been programmed (LOCK bits in TIM_BDTR register).
31.6.25 TIM timer encoder control register (TIM_ECR)
Address offset: 0x058
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | PWPRSC[2:0] | PW[7:0] | |||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | |||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | IPOS[1:0] | FIDX | IBLK[1:0] | IDIR[1:0] | IE | |||
| rw | rw | rw | rw | rw | rw | rw | rw | ||||||||
Bits 31:27 Reserved, must be kept at reset value.
Bits 26:24 PWPRSC[2:0]: Pulse width prescaler
This bitfield sets the clock prescaler for the pulse generator, as following:
Bits 23:16 PW[7:0]: Pulse width
This bitfield defines the pulse duration, as following:
Bits 15:8 Reserved, must be kept at reset value.
Bits 7:6 IPOS[1:0]: Index positioning
In quadrature encoder mode (SMS[4:0] = 00001, 00010, 00011, 01110, 01111), this bit indicates in which AB input configuration the Index event resets the counter.
- 00: Index resets the counter when AB = 00
- 01: Index resets the counter when AB = 01
- 10: Index resets the counter when AB = 10
- 11: Index resets the counter when AB = 11
In directional clock mode or clock plus direction mode (SMS[4:0] = 01010, 01011, 01100, 01101), these bits indicates on which level the Index event resets the counter. In bidirectional clock mode, this applies for both clock inputs.
- x0: Index resets the counter when clock is 0
- x1: Index resets the counter when clock is 1
Note: IPOS[1] bit is not significant
Bit 5 FIDX: First index
This bit indicates if the first index only is taken into account
- 0: Index is always active
- 1: the first Index only resets the counter
Bits 4:3 IBLK[1:0]: Index blanking
This bit indicates if the Index event is conditioned by the tim_ti3 or tim_ti4 input
- 00: Index always active
- 01: Index disabled when tim_ti3 input is active, as per CC3P bitfield
- 10: Index disabled when tim_ti4 input is active, as per CC4P bitfield
- 11: Reserved
Bits 2:1 IDIR[1:0]: Index direction
This bit indicates in which direction the Index event resets the counter.
- 00: Index resets the counter whatever the direction
- 01: Index resets the counter when up-counting only
- 10: Index resets the counter when down-counting only
- 11: Reserved
Bit 0 IE: Index enable
This bit indicates if the Index event resets the counter.
- 0: Index disabled
- 1: Index enabled
31.6.26 TIM timer input selection register (TIM_TISEL)
Address offset: 0x05C
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | TI4SEL[3:0] | Res. | Res. | Res. | Res. | TI3SEL[3:0] | ||||||
| rw | rw | rw | rw | rw | rw | rw | rw | ||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | TI2SEL[3:0] | Res. | Res. | Res. | Res. | TI1SEL[3:0] | ||||||
| rw | rw | rw | rw | rw | rw | rw | rw | ||||||||
Bits 31:28 Reserved, must be kept at reset value.
Bits 27:24 TI4SEL[3:0]: Selects tim_ti4[15:0] input
0000: tim_ti4_in0: TIM_CH4
0001: tim_ti4_in1
...
1111: tim_ti4_in15
Refer to Section 31.3.2: TIM1/TIM8 pins and internal signals for interconnects list.
Bits 23:20 Reserved, must be kept at reset value.
Bits 19:16 TI3SEL[3:0]: Selects tim_ti3[15:0] input
0000: tim_ti3_in0: TIM_CH2
0001: tim_ti3_in1
...
1111: tim_ti3_in15
Refer to Section 31.3.2: TIM1/TIM8 pins and internal signals for interconnects list.
Bits 15:12 Reserved, must be kept at reset value.
Bits 11:8 TI2SEL[3:0]: Selects tim_ti2[15:0] input
0000: tim_ti2_in0: TIM_CH2
0001: tim_ti2_in1
...
1111: tim_ti2_in15
Refer to Section 31.3.2: TIM1/TIM8 pins and internal signals for interconnects list.
Bits 7:4 Reserved, must be kept at reset value.
Bits 3:0 TI1SEL[3:0]: Selects tim_ti1[15:0] input
0000: tim_ti1_in0: TIM_CH1
0001: tim_ti1_in1
...
1111: tim_ti1_in15
Refer to Section 31.3.2: TIM1/TIM8 pins and internal signals for interconnects list.
31.6.27 TIM alternate function option register 1 (TIM_AF1)
Address offset: 0x060
Reset value: 0x0000 0001
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| BKCM P20E | BKCM P19E | BKCM P18E | BKCM P17E | BKCM P16E | BKCM P15E | BKCM P14E | BKCM P13E | BKCM P12E | BKCM P11E | BKCM P10E | BKCM P9E | Res. | ETRSEL[4:2] | ||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| ETRSEL[1:0] | BKCM P4P | BKCM P3P | BKCM P2P | BKCM P1P | BKINP | BKCM P8E | BKCM P7E | BKCM P6E | BKCM P5E | BKCM P4E | BKCM P3E | BKCM P2E | BKCM P1E | BKINE | |
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
- Bit 31 BKCMP20E: tim_brk_cmp20 enable
This bit enables the tim_brk_cmp20 for the timer's tim_brk input. tim_brk_cmp20 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp20 input disabled
1: tim_brk_cmp20 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 30 BKCMP19E: tim_brk_cmp19 enable
This bit enables the tim_brk_cmp19 for the timer's tim_brk input. tim_brk_cmp19 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp19 input disabled
1: tim_brk_cmp19 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 29 BKCMP18E: tim_brk_cmp18 enable
This bit enables the tim_brk_cmp18 for the timer's tim_brk input. tim_brk_cmp18 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp18 input disabled
1: tim_brk_cmp18 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 28 BKCMP17E: tim_brk_cmp17 enable
This bit enables the tim_brk_cmp17 for the timer's tim_brk input. tim_brk_cmp17 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp17 input disabled
1: tim_brk_cmp17 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 27 BKCMP16E: tim_brk_cmp16 enable
This bit enables the tim_brk_cmp16 for the timer's tim_brk input. tim_brk_cmp16 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp16 input disabled
1: tim_brk_cmp16 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 26 BKCMP15E: tim_brk_cmp15 enable
This bit enables the tim_brk_cmp15 for the timer's tim_brk input. tim_brk_cmp15 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp15 input disabled
1: tim_brk_cmp15 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 25 BKCMP14E: tim_brk_cmp14 enable
This bit enables the tim_brk_cmp14 for the timer's tim_brk input. tim_brk_cmp14 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp14 input disabled
1: tim_brk_cmp14 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
- Bit 24 BKCMP13E: tim_brk_cmp13 enable
This bit enables the tim_brk_cmp13 for the timer's tim_brk input. tim_brk_cmp13 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp13 input disabled
1: tim_brk_cmp13 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 23 BKCMP12E: tim_brk_cmp12 enable
This bit enables the tim_brk_cmp12 for the timer's tim_brk input. tim_brk_cmp12 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp12 input disabled
1: tim_brk_cmp12 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 22 BKCMP11E: tim_brk_cmp11 enable
This bit enables the tim_brk_cmp11 for the timer's tim_brk input. tim_brk_cmp11 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp11 input disabled
1: tim_brk_cmp11 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 21 BKCMP10E: tim_brk_cmp10 enable
This bit enables the tim_brk_cmp10 for the timer's tim_brk input. tim_brk_cmp10 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp10 input disabled
1: tim_brk_cmp10 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 20 BKCMP9E: tim_brk_cmp9 enable
This bit enables the tim_brk_cmp9 for the timer's tim_brk input. tim_brk_cmp9 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp9 input disabled
1: tim_brk_cmp9 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 19 Reserved, must be kept at reset value.
- Bits 18:14 ETRSEL[4:0]: etr_in source selection
These bits select the etr_in input source.
00000:tim_etr0: TIM_ETR input
00001:tim_etr1
...
11111:tim_etr31
Refer to Section 31.3.2: TIM1/TIM8 pins and internal signals for product specific implementation.
Note: These bits can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 13 BKCMP4P: tim_brk_cmp4 input polarity
This bit selects the tim_brk_cmp4 input sensitivity. It must be programmed together with the BKP polarity bit.
0: tim_brk_cmp4 input polarity is not inverted (active low if BKP = 0, active high if BKP = 1)
1: tim_brk_cmp4 input polarity is inverted (active high if BKP = 0, active low if BKP = 1)
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 12 BKCMP3P: tim_brk_cmp3 input polarity
This bit selects the tim_brk_cmp3 input sensitivity. It must be programmed together with the BKP polarity bit.
0: tim_brk_cmp3 input polarity is not inverted (active low if BKP = 0, active high if BKP = 1)
1: tim_brk_cmp3 input polarity is inverted (active high if BKP = 0, active low if BKP = 1)
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 11 BKCMP2P: tim_brk_cmp2 input polarity
This bit selects the tim_brk_cmp2 input sensitivity. It must be programmed together with the BKP polarity bit.
0: tim_brk_cmp2 input polarity is not inverted (active low if BKP = 0, active high if BKP = 1)
1: tim_brk_cmp2 input polarity is inverted (active high if BKP = 0, active low if BKP = 1)
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 10 BKCMP1P: tim_brk_cmp1 input polarity
This bit selects the tim_brk_cmp1 input sensitivity. It must be programmed together with the BKP polarity bit.
0: tim_brk_cmp1 input polarity is not inverted (active low if BKP = 0, active high if BKP = 1)
1: tim_brk_cmp1 input polarity is inverted (active high if BKP = 0, active low if BKP = 1)
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 9 BKINP: TIM_BKIN input polarity
This bit selects the TIM_BKIN alternate function input sensitivity. It must be programmed together with the BKP polarity bit.
0: TIM_BKIN input polarity is not inverted (active low if BKP = 0, active high if BKP = 1)
1: TIM_BKIN input polarity is inverted (active high if BKP = 0, active low if BKP = 1)
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 8 BKCMP8E: tim_brk_cmp8 enable
This bit enables the tim_brk_cmp8 for the timer's tim_brk input. tim_brk_cmp8 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp8 input disabled
1: tim_brk_cmp8 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 7 BKCMP7E: tim_brk_cmp7 enable
This bit enables the tim_brk_cmp7 for the timer's tim_brk input. tim_brk_cmp7 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp7 input disabled
1: tim_brk_cmp7 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 6 BKCMP6E: tim_brk_cmp6 enable
This bit enables the tim_brk_cmp6 for the timer's tim_brk input. tim_brk_cmp6 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp6 input disabled
1: tim_brk_cmp6 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 5 BKCMP5E: tim_brk_cmp5 enable
This bit enables the tim_brk_cmp5 for the timer's tim_brk input. tim_brk_cmp5 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp5 input disabled
1: tim_brk_cmp5 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 4 BKCMP4E: tim_brk_cmp4 enable
This bit enables the tim_brk_cmp4 for the timer's tim_brk input. tim_brk_cmp4 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp4 input disabled
1: tim_brk_cmp4 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 3 BKCMP3E: tim_brk_cmp3 enable
This bit enables the tim_brk_cmp3 for the timer's tim_brk input. tim_brk_cmp3 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp3 input disabled
1: tim_brk_cmp3 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 2 BKCMP2E: tim_brk_cmp2 enable
This bit enables the tim_brk_cmp2 for the timer's tim_brk input. tim_brk_cmp2 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp2 input disabled
1: tim_brk_cmp2 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 1 BKCMP1E: tim_brk_cmp1 enable
This bit enables the tim_brk_cmp1 for the timer's tim_brk input. tim_brk_cmp1 output is 'ORed' with the other tim_brk sources.
0: tim_brk_cmp1 input disabled
1: tim_brk_cmp1 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 0 BKINE: TIM_BKIN input enable
This bit enables the TIM_BKIN alternate function input for the timer's tim_brk input. TIM_BKIN input is 'ORed' with the other tim_brk sources.
0: TIM_BKIN input disabled
1: TIM_BKIN input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Note: Refer to Section 31.3.2: TIM1/TIM8 pins and internal signals for product specific implementation.
31.6.28 TIM alternate function register 2 (TIM_AF2)
Address offset: 0x064
Reset value: 0x0000 0001
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| BK2CM P20E | BK2CM P19E | BK2CM P18E | BK2CM P17E | BK2CM P16E | BK2CM P15E | BK2CM P14E | BK2CM P13E | BK2CM P12E | BK2CM P11E | BK2CM P10E | BK2CM P9E | OCRSEL[3:0] | |||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | BK2CM P4P | BK2CM P3P | BK2CM P2P | BK2CM P1P | BK2IN P | BK2CM P8E | BK2CM P7E | BK2CM P6E | BK2CM P5E | BK2CM P4E | BK2CM P3E | BK2CM P2E | BK2CM P1E | BK2IN E |
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | ||
Bit 31 BK2CMP20E: tim_brk2_cmp20 enable
This bit enables the tim_brk2_cmp20 for the timer's tim_brk2 input. tim_brk2_cmp20 output is 'ORed' with the other tim_brk2 sources.
- 0: tim_brk2_cmp20 input disabled
- 1: tim_brk2_cmp20 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 30 BK2CMP19E: tim_brk2_cmp19 enable
This bit enables the tim_brk2_cmp19 for the timer's tim_brk2 input. tim_brk2_cmp19 output is 'ORed' with the other tim_brk2 sources.
- 0: tim_brk2_cmp19 input disabled
- 1: tim_brk2_cmp19 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 29 BK2CMP18E: tim_brk2_cmp18 enable
This bit enables the tim_brk2_cmp18 for the timer's tim_brk2 input. tim_brk2_cmp18 output is 'ORed' with the other tim_brk2 sources.
- 0: tim_brk2_cmp18 input disabled
- 1: tim_brk2_cmp18 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 28 BK2CMP17E: tim_brk2_cmp17 enable
This bit enables the tim_brk2_cmp17 for the timer's tim_brk2 input. tim_brk2_cmp17 output is 'ORed' with the other tim_brk2 sources.
- 0: tim_brk2_cmp17 input disabled
- 1: tim_brk2_cmp17 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
- Bit 27 BK2CMP16E: tim_brk2_cmp16 enable
This bit enables the tim_brk2_cmp16 for the timer's tim_brk2 input. tim_brk2_cmp16 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp16 input disabled
1: tim_brk2_cmp16 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 26 BK2CMP15E: tim_brk2_cmp15 enable
This bit enables the tim_brk2_cmp15 for the timer's tim_brk2 input. tim_brk2_cmp15 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp15 input disabled
1: tim_brk2_cmp15 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 25 BK2CMP14E: tim_brk2_cmp14 enable
This bit enables the tim_brk2_cmp14 for the timer's tim_brk2 input. tim_brk2_cmp14 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp14 input disabled
1: tim_brk2_cmp14 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 24 BK2CMP13E: tim_brk2_cmp13 enable
This bit enables the tim_brk2_cmp13 for the timer's tim_brk2 input. tim_brk2_cmp13 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp13 input disabled
1: tim_brk2_cmp13 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 23 BK2CMP12E: tim_brk2_cmp12 enable
This bit enables the tim_brk2_cmp12 for the timer's tim_brk2 input. tim_brk2_cmp12 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp12 input disabled
1: tim_brk2_cmp12 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 22 BK2CMP11E: tim_brk2_cmp11 enable
This bit enables the tim_brk2_cmp11 for the timer's tim_brk2 input. tim_brk2_cmp11 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp11 input disabled
1: tim_brk2_cmp11 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 21 BK2CMP10E: tim_brk2_cmp10 enable
This bit enables the tim_brk2_cmp10 for the timer's tim_brk2 input. tim_brk2_cmp10 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp10 input disabled
1: tim_brk2_cmp10 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
- Bit 20 BK2CMP9E: tim_brk2_cmp9 enable
This bit enables the tim_brk2_cmp9 for the timer's tim_brk2 input. tim_brk2_cmp9 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp9 input disabled
1: tim_brk2_cmp9 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bits 19:16 OCRSEL[3:0]: ocref_clr source selection
These bits select the ocref_clr input source.
0000:tim_ocref_clr0
0001:tim_ocref_clr1
...
1111: tim_ocref_clr15
Refer to Section 31.3.2: TIM1/TIM8 pins and internal signals for product specific information.
Note: These bits can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bits 15:14 Reserved, must be kept at reset value.
- Bit 13 BK2CMP4P: tim_brk2_cmp4 input polarity
This bit selects the tim_brk2_cmp4 input sensitivity. It must be programmed together with the BK2P polarity bit.
0: tim_brk2_cmp4 input polarity is not inverted (active low if BK2P = 0, active high if BK2P = 1)
1: tim_brk2_cmp4 input polarity is inverted (active high if BK2P = 0, active low if BK2P = 1)
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 12 BK2CMP3P: tim_brk2_cmp3 input polarity
This bit selects the tim_brk2_cmp3 input sensitivity. It must be programmed together with the BK2P polarity bit.
0: tim_brk2_cmp3 input polarity is not inverted (active low if BK2P = 0, active high if BK2P = 1)
1: tim_brk2_cmp3 input polarity is inverted (active high if BK2P = 0, active low if BK2P = 1)
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 11 BK2CMP2P: tim_brk2_cmp2 input polarity
This bit selects the tim_brk2_cmp2 input sensitivity. It must be programmed together with the BK2P polarity bit.
0: tim_brk2_cmp2 input polarity is not inverted (active low if BK2P = 0, active high if BK2P = 1)
1: tim_brk2_cmp2 input polarity is inverted (active high if BK2P = 0, active low if BK2P = 1)
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 10 BK2CMP1P: tim_brk2_cmp1 input polarity
This bit selects the tim_brk2_cmp1 input sensitivity. It must be programmed together with the BK2P polarity bit.
0: tim_brk2_cmp1 input polarity is not inverted (active low if BK2P = 0, active high if BK2P = 1)
1: tim_brk2_cmp1 input polarity is inverted (active high if BK2P = 0, active low if BK2P = 1)
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
- Bit 9 BK2INP: TIM_BKIN2 input polarity
This bit selects the TIM_BKIN2 alternate function input sensitivity. It must be programmed together with the BK2P polarity bit.
0: TIM_BKIN2 input polarity is not inverted (active low if BK2P = 0, active high if BK2P = 1)
1: TIM_BKIN2 input polarity is inverted (active high if BK2P = 0, active low if BK2P = 1)
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 8 BK2CMP8E: tim_brk2_cmp8 enable
This bit enables the tim_brk2_cmp8 for the timer's tim_brk2 input. tim_brk2_cmp8 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp8 input disabled
1: tim_brk2_cmp8 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 7 BK2CMP7E: tim_brk2_cmp7 enable
This bit enables the tim_brk2_cmp7 for the timer's tim_brk2 input. tim_brk2_cmp7 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp7 input disabled
1: tim_brk2_cmp7 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 6 BK2CMP6E: tim_brk2_cmp6 enable
This bit enables the tim_brk2_cmp6 for the timer's tim_brk2 input. tim_brk2_cmp6 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp6 input disabled
1: tim_brk2_cmp6 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 5 BK2CMP5E: tim_brk2_cmp5 enable
This bit enables the tim_brk2_cmp5 for the timer's tim_brk2 input. tim_brk2_cmp5 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp5 input disabled
1: tim_brk2_cmp5 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 4 BK2CMP4E: tim_brk2_cmp4 enable
This bit enables the tim_brk2_cmp4 for the timer's tim_brk2 input. tim_brk2_cmp4 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp4 input disabled
1: tim_brk2_cmp4 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register). - Bit 3 BK2CMP3E: tim_brk2_cmp3 enable
This bit enables the tim_brk2_cmp3 for the timer's tim_brk2 input. tim_brk2_cmp3 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp3 input disabled
1: tim_brk2_cmp3 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 2 BK2CMP2E: tim_brk2_cmp2 enable
This bit enables the tim_brk2_cmp2 for the timer's tim_brk2 input. tim_brk2_cmp2 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp2 input disabled
1: tim_brk2_cmp2 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 1 BK2CMP1E: tim_brk2_cmp1 enable
This bit enables the tim_brk2_cmp1 for the timer's tim_brk2 input. tim_brk2_cmp1 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp1 input disabled
1: tim_brk2_cmp1 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 0 BK2INE: TIM_BKIN2 input enable
This bit enables the TIM_BKIN2 alternate function input for the timer's tim_brk2 input. TIM_BKIN2 input is 'ORed' with the other tim_brk2 sources.
0: TIM_BKIN2 input disabled
1: TIM_BKIN2 input enabled
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Note: Refer to Section 31.3.2: TIM1/TIM8 pins and internal signals for product specific implementation.
31.6.29 TIM capture/compare register 7 (TIM_CCR7)
Address offset: 0x070
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CCR7[19:16] | |||
| rw | rw | rw | rw | ||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| CCR7[15:0] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:20 Reserved, must be kept at reset value.
Bits 19:0 CCR7[19:0]: Capture/compare 7 value
CCR7 is the value to be loaded in the actual compare 7 register (preload value).
It is loaded permanently if the preload feature is not selected in the TIM_CCMR4 register (bit OC7PE). Else the preload value is copied in the active compare 7 register when an update event occurs.
The active compare register contains the value to be compared to the counter TIM_CNT and signaled on tim_oc7 output.
Non-dithering mode (DITHEN = 0)
The register holds the compare value in CCR7[15:0]. The CCR7[19:16] bits are reset.
Dithering mode (DITHEN = 1)
The register holds the integer part in CCR7[19:4]. The CCR7[3:0] bitfield contains the dithered part.
31.6.30 TIM capture/compare mode register 4 (TIM_CCMR4)
Address offset: 0x078
Reset value: 0x0000 0000
Refer to the above CCMR1 register description. Channel 7 can only be configured in output.
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | OC7M[4:3] | |
| rw | rw | ||||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | OC7CE | OC7M[2:0] | OC7PE | OC7FE | Res. | Res. | ||
| rw | rw | rw | rw | rw | rw | ||||||||||
Bits 31:18 Reserved, must be kept at reset value.
Bits 15:8 Reserved, must be kept at reset value.
Bit 7 OC7CE: Output compare 7 clear enable
- 0: tim_oc7ref is not affected by the tim_ocref_clr_int signal
- 1: tim_oc7ref is cleared as soon as a High level is detected on tim_ocref_clr_int signal
(tim_ocref_clr input or tim_etrf input)
Note: This mode is not available for all PWM modes. Refer to Section 31.3.23: Clearing the tim_ocxref signal on an external event for the list of forbidden configurations.

Bits 17:16, 6:4 OC7M[4:0]: Output compare 7 mode
These bits define the behavior of the output reference signal tim_ocref7. tim_oc7ref is active high whereas tim_oc7 active level depends on CC7P bit.
00000:Frozen - The comparison between the output compare register TIM_CCR7 and the counter TIM_CNT has no effect on the outputs.(this mode is used to generate a timing base).
00001:Set channel 7 to active level on match. tim_oc7ref signal is forced high when the counter TIM_CNT matches the capture/compare register 7 (TIM_CCR7).
00010:Set channel 7 to inactive level on match. tim_oc7ref signal is forced low when the counter TIM_CNT matches the capture/compare register 7 (TIM_CCR7).
00011:Toggle - tim_oc7ref toggles when TIM_CNT= TIM_CCR7.
00100:Force inactive level - tim_oc7ref is forced low.
00101:Force active level - tim_oc7ref is forced high.
00110:PWM mode 1 - In upcounting, channel 7 is active as long as TIM_CNT< TIM_CCR7 else inactive. In downcounting, channel 7 is inactive (tim_oc7ref= 0) as long as TIM_CNT> TIM_CCR7 else active (tim_oc7ref= 1).
00111:PWM mode 2 - In upcounting, channel 7 is inactive as long as TIM_CNT< TIM_CCR7 else active. In downcounting, channel 7 is active as long as TIM_CNT> TIM_CCR7 else inactive.
01000:Retrigerrable OPM mode 1 - In up-counting mode, the channel is active until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 1 and the channels becomes active again at the next update. In down-counting mode, the channel is inactive until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 1 and the channels becomes inactive again at the next update.
01001:Retrigerrable OPM mode 2 - In up-counting mode, the channel is inactive until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 2 and the channels becomes inactive again at the next update. In down-counting mode, the channel is active until a trigger event is detected (on tim_trgi signal). Then, a comparison is performed as in PWM mode 1 and the channels becomes active again at the next update.
Others: Reserved
Note: These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIM_BDTR register) and CC1S= 00 (the channel is configured in output).
Note: In PWM mode, the OCREF level changes only when the result of the comparison changes or when the output compare mode switches from “frozen” mode to “PWM” mode.
Bit 3 OC7PE: Output compare 7 preload enable
0: Preload register on TIM_CCR7 disabled. TIM_CCR7 can be written at anytime, the new value is taken in account immediately.
1: Preload register on TIM_CCR7 enabled. Read/Write operations access the preload register. TIM_CCR7 preload value is loaded in the active register at each update event.
These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIM_BDTR register) and CC1S = 00 (the channel is configured in output).
Bit 2 OC7FE: Output compare 7 fast enable
This bit decreases the latency between a trigger event and a transition on the timer output. It must be used in one-pulse mode (OPM bit set in TIM_CR1 register), to have the output pulse starting as soon as possible after the starting trigger.
0: CC7 behaves normally depending on counter and CCR7 values even when the trigger is ON. The minimum delay to activate CC7 output when an edge occurs on the trigger input is 5 clock cycles.
1: An active edge on the trigger input acts like a compare match on CC7 output. Then, OC is set to the compare level independently from the result of the comparison. Delay to sample the trigger input and to activate CC7 output is reduced to 3 clock cycles. OCFE acts only if the channel is configured in PWM1 or PWM2 mode.
Bits 1:0 Reserved, must be kept at reset value.
31.6.31 TIM multilevel protection register 1 (TIM_MPR1)
Address offset: 0x090
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| BK4NM[1:0] | BK4M[1:0] | BK3NM[1:0] | BK3M[1:0] | BK2NM[1:0] | BK2M[1:0] | BK1NM[1:0] | BK1M[1:0] | ||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:16 Reserved, must be kept at reset value.
Bits 15:14 BK4NM[1:0]: Break mode for tim_oc4n output
This bit must be modified only when CEN=0 in TIM_CR1.
00: Immediate break
01: Delayed 1 break
10: Delayed 2 break
11: Reserved
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bits 13:12 BK4M[1:0]: Break mode for tim_oc4 output
This bit must be modified only when CEN=0 in TIM_CR1.
00: Immediate break
01: Delayed 1 break
10: Delayed 2 break
11: Reserved
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bits 11:10 BK3NM[1:0]: Break mode for tim_oc3n output
This bit must be modified only when CEN=0 in TIM_CR1.
00: Immediate break
01: Delayed 1 break
10: Delayed 2 break
11: Reserved
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bits 9:8 BK3M[1:0]: Break mode for tim_oc3 output
This bit must be modified only when CEN=0 in TIM_CR1.
00: Immediate break
01: Delayed 1 break
10: Delayed 2 break
11: Reserved
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bits 7:6 BK2NM[1:0]: Break mode for tim_oc2n output
This bit must be modified only when CEN=0 in TIM_CR1.
00: Immediate break
01: Delayed 1 break
10: Delayed 2 break
11: Reserved
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bits 5:4 BK2M[1:0]: Break mode for tim_oc2 output
This bit must be modified only when CEN=0 in TIM_CR1.
00: Immediate break
01: Delayed 1 break
10: Delayed 2 break
11: Reserved
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bits 3:2 BK1NM[1:0]: Break mode for tim_oc1n output
This bit must be modified only when CEN=0 in TIM_CR1.
00: Immediate break
01: Delayed 1 break
10: Delayed 2 break
11: Reserved
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bits 1:0 BK1M[1:0]: Break mode for tim_oc1 output
This bit must be modified only when CEN=0 in TIM_CR1.
00: Immediate break
01: Delayed 1 break
10: Delayed 2 break
11: Reserved
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
31.6.32 TIM multilevel protection register 2 (TIM_MPR2)
Address offset: 0x094
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | DBK2[7:0] | |||||||
| rw | rw | rw | rw | rw | rw | rw | rw | ||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | DBK1[7:0] | |||||||
| rw | rw | rw | rw | rw | rw | rw | rw | ||||||||
Bits 31:24 Reserved, must be kept at reset value.
Bits 23:16 DBK2[7:0]: Delayed 2 Break duration
This bitfield defines the duration of the delay in Delayed 2 Break mode.
It is partially preloaded and can be updated during timer operation (new value taken into account after an update event), at the exception of the bits coding for \(t_{DTG}\) selection, which are not preloaded.
It is thus recommended to update only the least significant bits to have the expected duration value:
- • DBK2[6:0] if DBK2[7] = 0
- • DBK2[5:0] if DBK2[7:6] = 10
- • DBK2[4:0] if DBK2[7:5] = 110 or 111
DBK2[7:5]=0xx => Delay2=DBK2[7:0]\(\times t_{DTG}\) with \(t_{DTG}=t_{DTS}\).
DBK2[7:5]=10x => Delay2=(64+DBK2[5:0])\(\times t_{DTG}\) with \(t_{DTG}=2t_{DTS}\).
DBK2[7:5]=110 => Delay2=(32+DBK2[4:0])\(\times t_{DTG}\) with \(t_{DTG}=8t_{DTS}\).
DBK2[7:5]=111 => Delay2=(32+DBK2[4:0])\(\times t_{DTG}\) with \(t_{DTG}=16t_{DTS}\).
Note: This bit can not be modified as long as LOCK level 2 or 3 has been programmed (LOCK bits in TIM_BDTR register).
Bits 15:8 Reserved, must be kept at reset value.
Bits 7:0 DBK1[7:0]: Delayed 1 Break duration
This bitfield defines the duration of the delay in Delayed 1 Break mode.
It is partially preloaded and can be updated during timer operation (new value taken into account after an update event), at the exception of the bits coding for \(t_{DTG}\) selection, which are not preloaded.
It is thus recommended to update only the least significant bits to have the expected duration value:
- • DBK1[6:0] if DBK1[7] = 0
- • DBK1[5:0] if DBK1[7:6] = 10
- • DBK1[4:0] if DBK1[7:5] = 110 or 111
DBK1[7:5]=0xx => Delay1=DBK1[7:0]\(\times t_{DTG}\) with \(t_{DTG}=t_{DTS}\).
DBK1[7:5]=10x => Delay1=(64+DBK1[5:0])\(\times t_{DTG}\) with \(t_{DTG}=2t_{DTS}\).
DBK1[7:5]=110 => Delay1=(32+DBK1[4:0])\(\times t_{DTG}\) with \(t_{DTG}=8t_{DTS}\).
DBK1[7:5]=111 => Delay1=(32+DBK1[4:0])\(\times t_{DTG}\) with \(t_{DTG}=16t_{DTS}\).
Note: This bit can not be modified as long as LOCK level 2 or 3 has been programmed (LOCK bits in TIM_BDTR register).
31.6.33 TIM output override register (TIM_OOR)
Address offset: 0x0A0
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | OOC | Res. | Res. | Res. | Res. | OOS4N | OOS4 | OOS3N | OOS3 | OOS2N | OOS2 | OOS1N | OOS1 |
| rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:13 Reserved, must be kept at reset value.
Bit 12 OOC: Output override control
This bit forces the idle state of the tim_ocx and tim_ocxn outputs to the values defined with OOSx and OOSxN bits.
0: tim_ocx and tim_ocxn outputs are in the default idle state
1: tim_ocx and tim_ocxn outputs are forced in an idle state defined with OOSx/OOSxN bits
Note: This bit can only be modified when the outputs are in idle state (MOE = 0). It is cleared when the MOE bit is set.
Bits 11:8 Reserved, must be kept at reset value.
Bit 7 OOS4N: Output override state for output tim_oc4n
This bit defines the state for output tim_oc4n when OOC = 1
0: tim_oc4n = 0
1: tim_oc4n = 1
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 6 OOS4: Output override state for output tim_oc4
This bit defines the state for output tim_oc4 when OOC = 1
0: tim_oc4 = 0
1: tim_oc4 = 1
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 5 OOS3N: Output override state for output tim_oc3n
This bit defines the state for output tim_oc3n when OOC = 1
0: tim_oc3n = 0
1: tim_oc3n = 1
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 4 OOS3: Output override state for output tim_oc3
This bit defines the state for output tim_oc3 when OOC = 1
0: tim_oc3 = 0
1: tim_oc3 = 1
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 3 OOS2N: Output override state for output tim_oc2n
This bit defines the state for output tim_oc2n when OOC = 1
0: tim_oc2n = 0
1: tim_oc2n = 1
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 2 OOS2: Output override state for output tim_oc2
This bit defines the state for output tim_oc2 when OOC = 1
0: tim_oc2 = 0
1: tim_oc2 = 1
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 1 OOS1N: Output override state for output tim_oc1n
This bit defines the state for output tim_oc1n when OOC = 1
0: tim_oc1n = 0
1: tim_oc1n = 1
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
Bit 0 OOS1: Output override state for output tim_oc1
This bit defines the state for output tim_oc1 when OOC = 1
0: tim_oc1 = 0
1: tim_oc1 = 1
Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).
31.6.34 TIM DMA control register (TIM_DCR)
Address offset: 0x3DC
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | DBSS[3:0] | |||
| rw | rw | rw | rw | ||||||||||||
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Res. | Res. | Res. | DBL[4:0] | Res. | Res. | Res. | DBA[4:0] | ||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | ||||||
Bits 31:20 Reserved, must be kept at reset value.
Bits 19:16 DBSS[3:0]: DMA burst source selection
This bitfield defines the interrupt source that triggers the DMA burst transfers (the timer recognizes a burst transfer when a read or a write access is done to the TIM_DMAR address).
0000: Disabled
0001: Update
0010: CC1
0011: CC2
0100: CC3
0101: CC4
0110: COM
0111: Trigger
Others: reserved
Bits 15:13 Reserved, must be kept at reset value.
Bits 12:8 DBL[4:0]: DMA burst length
This 5-bit vector defines the length of DMA transfers (the timer recognizes a burst transfer when a read or a write access is done to the TIM_DMAR address), i.e. the number of transfers.
00000: 1 transfer
00001: 2 transfers
00010: 3 transfers
...
11111: 32 transfers
Example: Let us consider the following transfer: DBL = 6 & DBA = TIM2_CR1.
–If DBL = 6 and DBA = TIM2_CR1 represents the address of the byte to be transferred, the address of the transfer is given by the following equation:
\((\text{TIM\_CR1 address}) + \text{DBA} + (\text{DMA index})\), where DMA index = DBL
In this example, 7 bytes are added to (TIM\_CR1 address)+DBA, which gives us the address from/to which the data are copied. In this case, the transfer is done to 7 registers starting from the following address: (TIM\_CR1 address)+DBA
According to the configuration of the DMA Data Size, several cases may occur:
–If the DMA Data Size is configured in half-words, 16-bit data are transferred to each of the 7 registers.
–If the DMA Data Size is configured in bytes, the data are also transferred to 7 registers: the first register contains the first MSB byte, the second register, the first LSB byte and so on. So with the transfer Timer, one also has to specify the size of data transferred by DMA.
Bits 7:5 Reserved, must be kept at reset value.
Bits 4:0 DBA[4:0]: DMA base address
This 5-bits vector defines the base-address for DMA transfers (when read/write access are done through the TIM_DMAR address). DBA is defined as an offset starting from the address of the TIM_CR1 register.
Example:
00000: TIM_CR1
00001: TIM_CR2
00010: TIM_SMCR
...
31.6.35 TIM DMA address for full transfer (TIM_DMAR)
Address offset: 0x3E0
Reset value: 0x0000 0000
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| DMAB[31:16] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| DMAB[15:0] | |||||||||||||||
| rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw | rw |
Bits 31:0 DMAB[31:0]: DMA register for burst accesses
A read or write operation to the DMAR register accesses the register located at the address (TIM_CR1 address) + (DBA + DMA index) x 4
where TIM_CR1 address is the address of the control register 1, DBA is the DMA base address configured in TIM_DCR register, DMA index is automatically controlled by the DMA transfer, and ranges from 0 to DBL (DBL configured in TIM_DCR).
31.6.36 TIM1/TIM8 register map
TIM1/TIM8 registers are mapped as 16-bit addressable registers as described in the table below:
Table 305. TIM1/TIM8 register map and reset values
| Offset | Register | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0x000 | TIM_CR1 | Res. | Res. | Res. | Res. | CKD2[3:0] | Res. | Res. | Res. | TGO2PSC[4:0] | Res. | Res. | Res. | Res. | DITHEN | UIFREMA | Res. | CKD [1:0] | ARPE | CMS [1:0] | DIR | OPM | URS | UDIS | CEN | |||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||
| 0x004 | TIM_CR2 | TI3INV | TI2INV | TI1INV | ADSYNC | XORPS | Res. | MMS[3] | MMS2[4:0] | OIS7 | OIS6 | Res. | OIS5 | OIS4N | OIS4 | OIS3N | OIS3 | OIS2N | OIS2 | OIS1N | OIS1 | TI1S | MMS [2:0] | CCDS | CCUS | Res. | CCPC | |||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||
| 0x008 | TIM_SMCR | Res. | Res. | SETPS[3:0] | SMSPS | SMSP | Res. | Res. | Res. | TS [4:3] | Res. | Res. | Res. | Res. | Res. | ETP | ECE | ETPS [1:0] | ETF[3:0] | MSM | TS[2:0] | OCCS | SMS[2:0] | |||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||
| 0x00C | TIM_DIER | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | TERRIE | IERRIE | DIRIE | IDXIE | Res. | Res. | Res. | Res. | TDE | COMDE | CC4DE | CC3DE | CC2DE | CC1DE | UDE | BIE | TIE | COMIE | CC4IE | CC3IE | CC2IE | CC1IE | UIE | ||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||
| 0x010 | TIM_SR | TI4FS | TI3FS | TI2FS | TI1FS | Res. | Res. | ODS | UIOVRF | TERRF | IERRF | DIRF | IDXF | Res. | Res. | CC7IF | CC6IF | CC5IF | B2GF | BGF | SBIF | CC4OF | CC3OF | CC2OF | CC1OF | B2IF | BIF | TIF | COMIF | CC4IF | CC3IF | CC2IF | CC1IF | UIF |
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||
| 0x014 | TIM_EGR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | B2G | BG | TG | COMG | CC4G | CC3G | CC2G | CC1G | UG | ||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||||||||||||
| 0x018 | TIM_CCMR1 Input Capture mode | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | IC2F[3:0] | IC2 PSC [1:0] | CC2 S [1:0] | IC1F[3:0] | IC1 PSC [1:0] | CC1 S [1:0] | ||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||
| TIM_CCMR1 Output Compare mode | Res. | Res. | Res. | Res. | Res. | Res. | OC2M[3] | Res. | Res. | Res. | Res. | Res. | Res. | Res. | OC1M[3] | OC2CE | OC2M [2:0] | OC2PE | OC2FE | CC2 S [1:0] | OC1CE | OC1M [2:0] | OC1PE | OC1FE | CC1 S [1:0] | |||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||
Table 305. TIM1/TIM8 register map and reset values (continued)
| Offset | Register | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0x01C | TIM_CCMR2 | Res. | Res. | Res. | Res. | Res. | Res. | Res. | OC4M[4:3] | Res. | Res. | Res. | Res. | Res. | Res. | OC3M[4:3] | OC4CE | OC4M[2:0] | OC4PE | OC4FE | CC4S[1:0] | OC3CE | OC3M[2:0] | OC3PE | OC3FE | CC3S[1:0] | |||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||
| TIM_CCMR2 | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | IC4F[3:0] | IC4PSC[1:0] | CC4S[1:0] | IC3F[3:0] | IC3PSC[1:0] | CC3S[1:0] | ||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||
| 0x020 | TIM_CCER | Res. | Res. | Res. | Res. | Res. | Res. | CC7P | CC7E | Res. | Res. | CC6P | CC6E | Res. | Res. | CC5P | CC5E | CC4NP | CC4NE | CC4P | CC4E | CC3NP | CC3NE | CC3P | CC3E | CC2NP | CC2NE | CC2P | CC2E | CC1NP | CC1NE | CC1P | CC1E |
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||
| 0x024 | TIM_CNT | UIFCPY | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CNT[15:0] | ||||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||
| 0x028 | TIM_PSC | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | PSC[15:0] | ||||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||||
| 0x02C | TIM_ARR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | ARR[19:0] | ||||||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | ||||||||||||||
| 0x030 | TIM_RCR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | REP[15:0] | ||||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||||
| 0x034 | TIM_CCR1 | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CCR1[19:0] | ||||||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||
| 0x038 | TIM_CCR2 | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CCR2[19:0] | ||||||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||
| 0x03C | TIM_CCR3 | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CCR3[19:0] | ||||||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||
| 0x040 | TIM_CCR4 | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CCR4[19:0] | ||||||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||
| 0x044 | TIM_BDTR | Res. | Res. | BK2BID | BK2BID | BK2DSRM | BK2DSRM | BK2P | BK2E | BK2F[3:0] | BKF[3:0] | MOE | AOE | BKP | BKE | OSSR | OSSI | LOCK[1:0] | DT[7:0] | ||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||
| 0x048 | TIM_CCR5 | GC5C3 | GC5C2 | GC5C1 | GC5C4 | GC5C4O | GC5C3O | GC5C2O | GC5C1O | Res. | Res. | Res. | Res. | CCR5[19:0] | |||||||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Table 305. TIM1/TIM8 register map and reset values (continued)
| Offset | Register | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0x04C | TIM_CCR6 | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CCR6[19:0] | ||||||||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||
| 0x050 | TIM_CCMR3 | Res. | Res. | Res. | Res. | Res. | Res. | OC6M[4:3] | Res. | Res. | Res. | Res. | Res. | Res. | OC5M[4:3] | OC6CE | OC6M[2:0] | OC6PE | OC6FE | Res. | Res. | Res. | OC5CE | OC5M[2:0] | OC5PE | OC5FE | Res. | Res. | ||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||
| 0x054 | TIM_DTR2 | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | DTPE | DTAE | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | DTGF[7:0] | ||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||||||||
| 0x058 | TIM_ECR | Res. | Res. | Res. | Res. | PWPR SC[2:0] | PW[7:0] | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | IPOS [1:0] | FIDX | IBLK [1:0] | IDIR [1:0] | IE | Res. | |||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||
| 0x05C | TIM_TISEL | Res. | Res. | Res. | Res. | TI4SEL[3:0] | Res. | Res. | Res. | Res. | TI3SEL[3:0] | Res. | Res. | Res. | Res. | TI2SEL[3:0] | Res. | Res. | Res. | Res. | TI1SEL[3:0] | |||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||
| 0x060 | TIM_AF1 | BKCMP20E | BKCMP19E | BKCMP18E | BKCMP17E | BKCMP16E | BKCMP15E | BKCMP14E | BKCMP13E | BKCMP12E | BKCMP11E | BKCMP10E | BKCMP9E | Res. | ETRSEL [4:0] | BKCMP4P | BKCMP3P | BKCMP2P | BKCMP1P | BKINP | BKCMP8E | BKCMP7E | BKCMP6E | BKCMP5E | BKCMP4E | BKCMP3E | BKCMP2E | BKCMP1E | BKINE | |||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | |||
| 0x064 | TIM_AF2 | BK2CMP20E | BK2CMP19E | BK2CMP18E | BK2CMP17E | BK2CMP16E | BK2CMP15E | BK2CMP14E | BK2CMP13E | BK2CMP12E | BK2CMP11E | BK2CMP10E | BK2CMP9E | OCRSEL[3:0] | Res. | Res. | BK2CMP4P | BK2CMP3P | BK2CMP2P | BK2CMP1P | BK2INP | BK2CMP8E | BK2CMP7E | BK2CMP6E | BK2CMP5E | BK2CMP4E | BK2CMP3E | BK2CMP2E | BK2CMP1E | BK2INE | ||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | ||||
| 0x068.. 0x06C | Reserved | Res. | ||||||||||||||||||||||||||||||||
| 0x070 | TIM_CCR7 | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | CCR7[19:0] | ||||||||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||
| 0x074 | Reserved | Res. | ||||||||||||||||||||||||||||||||
| 0x078 | TIM_CCMR4 | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | OC7M[4:3] | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | OC7CE | OC7M [2:0] | OC7PE | OC7FE | Res. | Res. | ||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||||||||||
| 0x07C.. 0x8C | Reserved | Res. | ||||||||||||||||||||||||||||||||
| 0x090 | TIM_MPR1 | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | BK4NM[1:0] | BK4M[1:0] | BK3NM[1:0] | BK3M[1:0] | BK2NM[1:0] | BK2M[1:0] | BK1NM[1:0] | BK1M[1:0] | |||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||
| 0x094 | TIM_MPR2 | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | DBK2[7:0] | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | DBK1[7:0] | |||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||
Table 305. TIM1/TIM8 register map and reset values (continued)
| Offset | Register | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0x098.. 0x09C | Reserved | Res. | |||||||||||||||||||||||||||||||
| 0x0A0 | TIM_OOR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | OOC | Res. | Res. | Res. | Res. | OOS4N | OOS4 | OOS3N | OOS3 | OOS2N | OOS2 | OOS1N | OOS1 |
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||||||||||||
| 0x0A4.. 0x3D8 | Reserved | Res. | |||||||||||||||||||||||||||||||
| 0x3DC | TIM_DCR | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | Res. | DBSS[3:0] | Res. | Res. | Res. | DBL[4:0] | Res. | Res. | Res. | DBA[4:0] | |||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |||||||||||||||||||
| 0x3E0 | TIM_DMAR | DMAB[31:0] | |||||||||||||||||||||||||||||||
| Reset value | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
Refer to Section 2.2: Memory organization for the register boundary addresses.