35. General purpose timers (TIM15/TIM16/TIM17)

35.1 TIM15/TIM16/TIM17 introduction

The TIM15/TIM16/TIM17 timers consist of a 16-bit autoreload counter driven by a programmable prescaler.

They 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 TIM15/TIM16/TIM17 timers are completely independent, and do not share any resources. TIM15 can be synchronized as described in Section 35.5.33: Timer synchronization (TIM15 only).

35.2 TIM15 main features

TIM15 includes the following features:

35.3 TIM16/TIM17 main features

The TIM16/TIM17 timers include the following features:

35.4 TIM15/TIM16/TIM17 implementation

Table 344. Timer instance implementation on STM32C5

Timer instanceSTM32C53x/C54xSTM32C55x/C56xSTM32C59x/C5Ax
TIM15XXX
TIM16-XX
TIM17-XX

35.5 TIM15/TIM16/TIM17 functional description

35.5.1 Block diagram

Figure 464. TIM15 block diagram

Figure 464. TIM15 block diagram. This is a detailed block diagram of the TIM15 timer peripheral showing internal architecture including the Trigger controller, Slave controller mode, IRQ interface, DMA interface, input filter and edge detectors for two channels, prescalers, capture/compare registers, a central CNT counter, repetition counter, DTG registers, output control, and break circuitry. A legend at the bottom left explains symbols for preload registers, events, and interrupt & DMA output. The diagram is labeled MSv75868V1 at the bottom right.

Notes:

MSv75868V1

Figure 464. TIM15 block diagram. This is a detailed block diagram of the TIM15 timer peripheral showing internal architecture including the Trigger controller, Slave controller mode, IRQ interface, DMA interface, input filter and edge detectors for two channels, prescalers, capture/compare registers, a central CNT counter, repetition counter, DTG registers, output control, and break circuitry. A legend at the bottom left explains symbols for preload registers, events, and interrupt & DMA output. The diagram is labeled MSv75868V1 at the bottom right.

1. Refer to Section 35.5.17: Using the break function for details.

Figure 465. TIM16/TIM17 block diagram

Block diagram of TIM16/TIM17 showing internal components like Counter Enable (CEN), Auto-reload register, CNT counter, Prescaler, and various interfaces (IRQ, DMA).

The diagram illustrates the internal architecture of the TIM16/TIM17 timer. Key components include:

Block diagram of TIM16/TIM17 showing internal components like Counter Enable (CEN), Auto-reload register, CNT counter, Prescaler, and various interfaces (IRQ, DMA).
  1. 1. Refer to Section 35.5.17: Using the break function for details.
  2. 2. This signal can be used as trigger for some slave timer (see internal trigger connection table in next section). See Section 35.5.34: Using timer output as trigger for other timers (TIM16/TIM17 only) for details.

35.5.2 TIM15/TIM16/TIM17 pins and internalsignals

Table 345 and Table 346 in this section summarize the TIM inputs and outputs.

Table 345. TIM input/output pins

Pin nameSignal typeDescription
TIM_CH1
TIM_CH2
Input/OutputTimer multi-purpose channels.
Each channel 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_CH1NOutputTimer complementary outputs, derived from TIM_CH1 output with the possibility to have deadtime insertion.
TIM_BKINInput / OutputBreak input. This input can also be configured in bidirectional mode.

Table 346. TIM internal input/output signals

Internal signal nameSignal typeDescription
tim_ti1_in[15:0]
tim_ti2_in[15:0]
InputInternal timer inputs bus. These 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_itr[27:0]InputInternal 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_trgoOutputInternal trigger output. This trigger can trigger other on-chip peripherals.
tim_ocx (x = 1 to 2)OutputInternal output compare signals of channels 1 to 2. These outputs can trigger or synchronize other internal peripherals.
tim_oc1nOutputInternal timer complementary output derived from tim_oc1 internal output, with the option to insert dead time.
tim_oref_clr[15:0]InputTimer tim_oref_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]InputBreak input for internal signals
tim_sys_brk[5:0]InputSystem break input. This input gathers the MCU's system level errors.
tim_pclkInputTimer APB clock
tim_ker_ckInputTimer kernel clock. This clock must be synchronous with tim_pclk (derived from the same source). The clock ratio tim_ker_ck/tim_pclk must be an integer: 1, 2, 3,..., 16 (maximum value)
tim_itOutputGlobal Timer interrupt, gathering capture/compare, update, break trigger and commutation requests
tim_cc1_dmaOutputTimer capture / compare 1 dma request
tim_cc2_dmaOutputTimer capture / compare 2 dma request
tim_upd_dmaOutputTimer update dma request
tim_trgi_dmaOutputTimer trigger dma request
tim_com_dmaOutputTimer commutation dma request

Table 347 and Table 348 list the sources connected to the tim_ti[2:1] input multiplexers.

Table 347. Interconnect to the tim_ti1 input multiplexer

tim_ti1 inputsSources
TIM15TIM16TIM17
tim_ti1_in0TIM15_CH1TIM16_CH1TIM17_CH1
tim_ti1_in1comp1_outcomp1_outcomp1_out
tim_ti1_in2comp2_outReserved
tim_ti1_in3ReservedLSIReserved
tim_ti1_in4ReservedLSEhse_1M_ck
tim_ti1_in5LSErtc_wut_trgMCO1
tim_ti1_in6fdcan2_rxeof_evtMCO1MCO2
tim_ti1_in7ReservedMCO2i3c1_iblack
tim_ti1_in[15:8]Reserved

Table 348. Interconnect to the tim_ti2 input multiplexer

tim_ti2 inputsSources
TIM15
tim_ti2_in0TIM15_CH2
tim_ti2_in[6:1]Reserved
tim_ti2_in7fdcan2_txeof_evt
tim_ti2_in[15:8]Reserved

Table 349 lists the internal sources connected to the tim_itr input multiplexer.

Table 349. TIMx internal trigger connection

tim_itrx inputsTIM15
tim_itr0tim1_trgo
tim_itr1tim1_trgo2
tim_itr2tim2_trgo
tim_itr3tim3_trgo
tim_itr4tim4_trgo
tim_itr5tim5_trgo
tim_itr6tim8_trgo
tim_itr7tim8_trgo2
tim_itr8tim12_trgo
tim_itr9Reserved
Table 349. TIMx internal trigger connection (continued)
tim_itr inputsTIM15
tim_itr10tim16_oc1
tim_itr11tim17_oc1
tim_itr[27:12]Reserved
Table 350. Interconnect to the tim_brk_cmp multiplexer
tim_brk inputsTIM15TIM16TIM17
TIM_BKINTIM15_BKIN pinTIM16_BKIN pinTIM17_BKIN pin
tim_brk_cmp1comp1_out
tim_brk_cmp2comp2_outReserved
tim_brk_cmp[4:3]Reserved
tim_brk_cmp5TIM1_BKIN
tim_brk_cmp6TIM8_BKIN
tim_brk_cmp7Reserved
tim_brk_cmp8ReservedTIM15_BKIN
tim_brk_cmp9TIM16_BKIN1ReservedTIM16_BKIN
tim_brk_cmp10TIM17_BKIN1Reserved

Table 351 lists the internal sources connected to the tim_oref_clr input multiplexer.

Table 351. Interconnect to the oref_clr input multiplexer
Timer OREF clear signalTimer OREF clear signals assignment
TIM15TIM16TIM17
tim_oref_clr0comp1_outcomp1_outcomp1_out
tim_oref_clr1comp2_outReserved
tim_oref_clr[7:2]Reserved
Table 352. System break interconnect
tim_sys_brk inputsTIM15/TIM16/TIM17Enable bit in SBS_CFGR2 register
tim_sys_brk0Cortex-M33 LOCKUPCLL
tim_sys_brk1SRAM double ECC errorSEL
tim_sys_brk2Programmable Voltage Detector (PVD)PVDL
tim_sys_brk3Non-Volatile memory double ECC errorECCL
tim_sys_brk4Clock Security System (CSS)None (always enabled)

35.5.3 Time-base unit

The main block of the programmable advanced-control timer is a 16-bit upcounter 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. This is true even when the counter is running.

The time-base unit includes:

The autoreload register is preloaded. Writing to or reading from the autoreload register accesses the preload register. The content of the preload register is 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 that the counter starts counting one clock cycle after setting the CEN bit in the TIM_CR1 register.

Prescaler description

The prescaler can divide the counter clock frequency by any factor between 1 and 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 466 and Figure 467 give some examples of the counter behavior when the prescaler ratio is changed on the fly:

Figure 466. Counter timing diagram with prescaler division change from 1 to 2

Timing diagram for Figure 466 showing the transition of prescaler division from 1 to 2. It includes waveforms for tim_psc_ck, CEN, tim_cnt_ck, Counter register, Update event (UEV), Prescaler control register, Prescaler buffer, and Prescaler counter.

Figure 466 illustrates the timing sequence for changing the prescaler division from 1 to 2. The diagram shows the following signals and their states:

MSv79792V1

Timing diagram for Figure 466 showing the transition of prescaler division from 1 to 2. It includes waveforms for tim_psc_ck, CEN, tim_cnt_ck, Counter register, Update event (UEV), Prescaler control register, Prescaler buffer, and Prescaler counter.

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

Timing diagram for Figure 467 showing the transition of prescaler division from 1 to 4. It includes waveforms for tim_psc_ck, CEN, tim_cnt_ck, Counter register, Update event (UEV), Prescaler control register, Prescaler buffer, and Prescaler counter.

Figure 467 illustrates the timing sequence for changing the prescaler division from 1 to 4. The diagram shows the following signals and their states:

MSv79793V1

Timing diagram for Figure 467 showing the transition of prescaler division from 1 to 4. It includes waveforms for tim_psc_ck, CEN, tim_cnt_ck, Counter register, Update event (UEV), Prescaler control register, Prescaler buffer, and Prescaler counter.

35.5.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). 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 following figures show some examples of the counter behavior for different clock frequencies when TIM_ARR = 0x36.

Figure 468. Counter timing diagram, internal clock divided by 1

Timing diagram for counter with internal clock divided by 1. It shows the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

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 square wave. The CEN signal is low initially and transitions high. Upon the rising edge of CEN, the counter starts incrementing. The tim_cnt_ck signal is a square wave with the same frequency as tim_psc_ck. The Counter register shows the count values: it starts at 31, increments to 32, 33, 34, 35, and 36. On the next rising edge of tim_cnt_ck, the counter wraps around to 00, then increments to 01, 02, 03, 04, 05, 06, and 07. A Counter overflow pulse occurs on the rising edge of tim_cnt_ck that would have caused the count to exceed 07. This overflow triggers an Update event (UEV) pulse. The Update interrupt flag (UIF) transitions from low to high on the rising edge of the UEV and remains high.

MSv50997V1

Timing diagram for counter with internal clock divided by 1. It shows the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

Figure 469. Counter timing diagram, internal clock divided by 2

Timing diagram for counter with internal clock divided by 2. It shows the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

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 square wave. The CEN signal is low initially and transitions high. Upon the rising edge of CEN, the counter starts incrementing. The tim_cnt_ck signal is a square wave with half the frequency of tim_psc_ck. The Counter register shows the count values: it starts at 0034, increments to 0035, and 0036. On the next rising edge of tim_cnt_ck, the counter wraps around to 0000, then increments to 0001, 0002, and 0003. A Counter overflow pulse occurs on the rising edge of tim_cnt_ck that would have caused the count to exceed 0003. This overflow triggers an Update event (UEV) pulse. The Update interrupt flag (UIF) transitions from low to high on the rising edge of the UEV and remains high.

MSv62300V1

Timing diagram for counter with internal clock divided by 2. It shows the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

Figure 470. Counter timing diagram, internal clock divided by 4

Timing diagram for counter with internal clock divided by 4. It shows the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

This timing diagram illustrates the operation of a counter when the internal clock is divided by 4. The tim_psc_ck signal is a high-frequency clock. The CEN (Counter Enable) signal is active low; when it transitions from high to low, the counter starts. The tim_cnt_ck signal is the divided clock, with a period four times that of tim_psc_ck. The Counter register increments on each rising edge of tim_cnt_ck. The sequence of values shown is 0035, 0036, 0000, and 0001. A Counter overflow occurs when the counter wraps from 0036 to 0000. This event triggers an Update event (UEV), which in turn sets the Update interrupt flag (UIF) to high. The diagram is labeled MSv62301V1.

Timing diagram for counter with internal clock divided by 4. It shows the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

Figure 471. Counter timing diagram, internal clock divided by N

Timing diagram for counter with internal clock divided by N. It shows the relationship between tim_psc_ck, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

This timing diagram shows the counter operation with an internal clock divided by an arbitrary factor N. The tim_psc_ck signal is the input clock. The tim_cnt_ck signal is the divided clock. The Counter register increments on each rising edge of tim_cnt_ck. The sequence of values shown is 1F, 20, and 00. A Counter overflow occurs when the counter wraps from 20 to 00. This event triggers an Update event (UEV), which sets the Update interrupt flag (UIF) to high. The diagram is labeled MSv62302V1.

Timing diagram for counter with internal clock divided by N. It shows the relationship between tim_psc_ck, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

Figure 472. Counter timing diagram, update event when ARPE = 0
(TIM_ARR not preloaded)

Timing diagram for a counter showing the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), Update interrupt flag (UIF), and Auto-reload preload register.

The diagram illustrates the timing of a counter when ARPE = 0 and TIM_ARR is not preloaded. The counter register is 36 bits wide, with bits 31-36 and 00-07 explicitly shown. The counter overflow occurs when the counter reaches 36, triggering an update event (UEV) and setting the update interrupt flag (UIF). The auto-reload preload register is shown with a value of FF, and a note indicates that a new value can be written to TIM_ARR.

SignalValue / State
tim_psc_ckPeriodic clock signal
CENCounter enable signal
tim_cnt_ckCounter clock signal
Counter register31, 32, 33, 34, 35, 36, 00, 01, 02, 03, 04, 05, 06, 07
Counter overflowHigh pulse at bit 36
Update event (UEV)High pulse at bit 36
Update interrupt flag (UIF)High pulse at bit 36
Auto-reload preload registerFF, 36

Write a new value in TIM_ARR

MSv79794V1

Timing diagram for a counter showing the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), Update interrupt flag (UIF), and Auto-reload preload register.

Figure 473. Counter timing diagram, update event when ARPE = 1
(TIM_ARR preloaded)

Timing diagram for a counter with ARPE = 1 and TIM_ARR preloaded. The diagram shows the relationship between the prescaler clock (tim_psc_ck), the counter enable signal (CEN), the counter clock (tim_cnt_ck), the counter register values, the counter overflow, the update event (UEV), the update interrupt flag (UIF), and the auto-reload preload and shadow registers. The counter register counts from F0 to F5, then wraps to 00-07. The counter overflow occurs at the transition from F5 to 00. The update event (UEV) is generated at the counter overflow. The auto-reload preload register is updated from F5 to 36. The auto-reload shadow register is updated from F5 to 36. A note indicates 'Write a new value in TIM_ARR' at the point of shadow register update.

The diagram illustrates the timing of a counter when ARPE = 1 and TIM_ARR is preloaded. The counter register counts from F0 to F5, then wraps to 00-07. The counter overflow occurs at the transition from F5 to 00. The update event (UEV) is generated at the counter overflow. The auto-reload preload register is updated from F5 to 36. The auto-reload shadow register is updated from F5 to 36. A note indicates 'Write a new value in TIM_ARR' at the point of shadow register update.

Timing diagram for a counter with ARPE = 1 and TIM_ARR preloaded. The diagram shows the relationship between the prescaler clock (tim_psc_ck), the counter enable signal (CEN), the counter clock (tim_cnt_ck), the counter register values, the counter overflow, the update event (UEV), the update interrupt flag (UIF), and the auto-reload preload and shadow registers. The counter register counts from F0 to F5, then wraps to 00-07. The counter overflow occurs at the transition from F5 to 00. The update event (UEV) is generated at the counter overflow. The auto-reload preload register is updated from F5 to 36. The auto-reload shadow register is updated from F5 to 36. A note indicates 'Write a new value in TIM_ARR' at the point of shadow register update.

MSv79795V1

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 following figures show some examples of the counter behavior for different clock frequencies when TIM_ARR = 0x36.

Figure 474. Counter timing diagram, internal clock divided by 1

Timing diagram for a counter showing tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter underflow (cnt_udf), Update event (UEV), and Update interrupt flag (UIF). The counter register shows values 05, 04, 03, 02, 01, 00, 36, 35, 34, 33, 32, 31, 30, 2F. The diagram shows the counter decrementing from 05 to 00, then reloading to 36 and decrementing to 2F. A counter underflow occurs at 00, followed by an update event and the setting of the update interrupt flag.

The diagram illustrates the timing of a counter with an internal clock divided by 1. It shows the following signals and register values over time:

MSv62305V1

Timing diagram for a counter showing tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter underflow (cnt_udf), Update event (UEV), and Update interrupt flag (UIF). The counter register shows values 05, 04, 03, 02, 01, 00, 36, 35, 34, 33, 32, 31, 30, 2F. The diagram shows the counter decrementing from 05 to 00, then reloading to 36 and decrementing to 2F. A counter underflow occurs at 00, followed by an update event and the setting of the update interrupt flag.

Figure 475. Counter timing diagram, internal clock divided by 2

Timing diagram for counter with internal clock divided by 2. Shows tim_psc_ck, CEN, tim_cnt_ck, Counter register (0002 to 0033), Counter underflow, Update event (UEV), and Update interrupt flag (UIF).

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 (CEN) signal is active high. The counter clock (tim_cnt_ck) is derived from tim_psc_ck and has a frequency half that of the prescaler clock. The counter register counts down from 0002 to 0000. When the counter reaches 0000, a counter underflow occurs, which generates an update event (UEV) and sets the update interrupt flag (UIF). The counter then reloads with the initial value 0036 and continues counting down. The diagram is labeled MSv62306V1.

Timing diagram for counter with internal clock divided by 2. Shows tim_psc_ck, CEN, tim_cnt_ck, Counter register (0002 to 0033), Counter underflow, Update event (UEV), and Update interrupt flag (UIF).

Figure 476. Counter timing diagram, internal clock divided by 4

Timing diagram for counter with internal clock divided by 4. Shows tim_psc_ck, CEN, tim_cnt_ck, Counter register (0001 to 0001), Counter underflow, Update event (UEV), and Update interrupt flag (UIF).

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 (CEN) signal is active high. The counter clock (tim_cnt_ck) has a frequency one-quarter that of the prescaler clock. The counter register counts down from 0001 to 0000. When the counter reaches 0000, a counter underflow occurs, generating an update event (UEV) and setting the update interrupt flag (UIF). The counter then reloads with 0001 and continues. The diagram is labeled MSv62307V1.

Timing diagram for counter with internal clock divided by 4. Shows tim_psc_ck, CEN, tim_cnt_ck, Counter register (0001 to 0001), Counter underflow, Update event (UEV), and Update interrupt flag (UIF).

Figure 477. Counter timing diagram, internal clock divided by N

Timing diagram for Figure 477 showing tim_psc_ck, tim_cnt_ck, Counter register, Counter underflow, Update event (UEV), and Update interrupt flag (UIF).

This timing diagram illustrates the operation of a counter when the internal clock is divided by N. It shows the relationship between the prescaler clock (tim_psc_ck), the counter clock (tim_cnt_ck), the counter register value, and various status signals.

SignalInitial StateEvent at tim_psc_ck rising edgeEvent at tim_psc_ck falling edge
tim_psc_ckLowTransitions to HighTransitions to Low
tim_cnt_ckLowTransitions to HighTransitions to Low
Counter register20Transitions to 1FTransitions to 00
Counter underflowLowLowTransitions to High
Update event (UEV)LowLowTransitions to High
Update interrupt flag (UIF)LowLowTransitions to High

MSv62308V1

Timing diagram for Figure 477 showing tim_psc_ck, tim_cnt_ck, Counter register, Counter underflow, Update event (UEV), and Update interrupt flag (UIF).

Figure 478. Counter timing diagram, update event when repetition counter is not used

Timing diagram for Figure 478 showing tim_pasc_ck, CEN, tim_cnt_ck, Counter register, Counter underflow, Update event (UEV), Update interrupt flag (UIF), and Auto-reload preload register.

This timing diagram shows the counter behavior when the repetition counter is not used. It includes the prescaler clock (tim_pasc_ck), the counter enable signal (CEN), the counter clock (tim_cnt_ck), the counter register values, the auto-reload preload register, and status signals.

SignalInitial StateEvent at tim_pasc_ck rising edgeEvent at tim_pasc_ck falling edge
tim_pasc_ckLowTransitions to HighTransitions to Low
CENLowTransitions to HighTransitions to Low
tim_cnt_ckLowTransitions to HighTransitions to Low
Counter register05Transitions to 04, 03, 02, 01, 00Transitions to 36, 35, 34, 33, 32, 31, 30, 2F
Counter underflowLowLowTransitions to High
Update event (UEV)LowLowTransitions to High
Update interrupt flag (UIF)LowLowTransitions to High
Auto-reload preload registerFFTransitions to 36Transitions to 36

Note: Write a new value in TIM_ARR

MSv79796V1

Timing diagram for Figure 478 showing tim_pasc_ck, CEN, tim_cnt_ck, Counter register, Counter underflow, Update event (UEV), Update interrupt flag (UIF), and Auto-reload preload register.

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 following figures show some examples of the counter behavior for different clock frequencies.

Figure 479. Counter timing diagram, internal clock divided by 1, TIM_ARR = 0x6

Figure 479: Counter timing diagram, internal clock divided by 1, TIM_ARR = 0x6. Signals shown: tim_psc_ck, CEN, tim_cnt_ck, Counter register (counting down from 04 to 00, then up to 06, then down to 03), Counter underflow pulse at 00, Counter overflow pulse at 06, Update event (UEV) pulses at 00 and 06, and Update interrupt flag (UIF) going high after 00.

MSv62310V1

Figure 479: Counter timing diagram, internal clock divided by 1, TIM_ARR = 0x6. Signals shown: tim_psc_ck, CEN, tim_cnt_ck, Counter register (counting down from 04 to 00, then up to 06, then down to 03), Counter underflow pulse at 00, Counter overflow pulse at 06, Update event (UEV) pulses at 00 and 06, and Update interrupt flag (UIF) going high after 00.

Figure 480. Counter timing diagram, internal clock divided by 2

Figure 480: Counter timing diagram, internal clock divided by 2. Signals shown: tim_psc_ck, CEN, tim_cnt_ck (divided by 2), Counter register (counting down 0003, 0002, 0001, 0000, then up 0001, 0002, 0003), Counter underflow pulse at 0000, Update event (UEV) pulse at 0000, and Update interrupt flag (UIF) going high after 0000.

MSv62311V1

Figure 480: Counter timing diagram, internal clock divided by 2. Signals shown: tim_psc_ck, CEN, tim_cnt_ck (divided by 2), Counter register (counting down 0003, 0002, 0001, 0000, then up 0001, 0002, 0003), Counter underflow pulse at 0000, Update event (UEV) pulse at 0000, and Update interrupt flag (UIF) going high after 0000.

Figure 481. Counter timing diagram, internal clock divided by 4, TIM_ARR = 0x36

Timing diagram for Figure 481 showing counter overflow and update events with TIM_ARR = 0x36.

The diagram shows the following signals over time:

Note: Here, center_aligned mode 2 or 3 is updated with an UIF on overflow

MSv62312V1

Timing diagram for Figure 481 showing counter overflow and update events with TIM_ARR = 0x36.

Figure 482. Counter timing diagram, internal clock divided by N

Timing diagram for Figure 482 showing counter underflow and update events with internal clock divided by N.

The diagram shows the following signals over time:

MSv62313V1

Timing diagram for Figure 482 showing counter underflow and update events with internal clock divided by N.

Figure 483. Counter timing diagram, update event with ARPE = 1 (counter underflow)

Timing diagram for counter underflow with ARPE = 1. It shows the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter underflow, Update event (UEV), Update interrupt flag (UIF), Auto-reload preload register, and Auto-reload active register. The counter register counts from 06 to 00, then wraps to 01. A write to TIM_ARR occurs during the count from 05 to 04. The counter underflows at 00, triggering the UEV and UIF.

The diagram illustrates the timing of a counter underflow event when ARPE is set to 1. It shows the following signals and events over time:

MSv79797V1

Timing diagram for counter underflow with ARPE = 1. It shows the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter underflow, Update event (UEV), Update interrupt flag (UIF), Auto-reload preload register, and Auto-reload active register. The counter register counts from 06 to 00, then wraps to 01. A write to TIM_ARR occurs during the count from 05 to 04. The counter underflows at 00, triggering the UEV and UIF.

Figure 484. Counter timing diagram, Update event with ARPE = 1 (counter overflow)

Timing diagram for counter overflow with ARPE = 1. It shows the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), Update interrupt flag (UIF), Auto-reload preload register, and Auto-reload active register. The Counter register shows values F7, F8, F9, FA, FB, FC, 36, 35, 34, 33, 32, 31, 30, 2F. The Auto-reload preload register shows FD and 36. The Auto-reload active register shows FD and 36. A write to TIM_ARR is indicated.

The diagram illustrates the timing of a counter overflow event when ARPE = 1. It shows the following signals and registers over time:

A note indicates "Write a new value in TIM_ARR" at the point where the Auto-reload preload register is updated.

MSv79798V1

Timing diagram for counter overflow with ARPE = 1. It shows the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), Update interrupt flag (UIF), Auto-reload preload register, and Auto-reload active register. The Counter register shows values F7, F8, F9, FA, FB, FC, 36, 35, 34, 33, 32, 31, 30, 2F. The Auto-reload preload register shows FD and 36. The Auto-reload active register shows FD and 36. A write to TIM_ARR is indicated.

35.5.5 Repetition counter

Section 35.5.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:

The repetition counter is an autoreload type; the repetition rate is maintained as defined by the TIM_RCR register value (refer to Figure 485). 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.

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.

For example, for RCR = 3, the UEV is generated each 4th overflow or underflow event depending on when the RCR was written.

Figure 485. Update rate examples depending on mode and TIM_RCR register settings

Figure 485: Update rate examples depending on mode and TIM_RCR register settings. The figure shows timing diagrams for Counter-aligned mode and Edge-aligned mode (Upcounting and Downcounting) for various TIM_RCR values (0, 1, 2, 3) and a re-synchronization case. It illustrates the relationship between the counter (TIM_CNT) and the Update Event (UEV) indicated by arrows.

The figure illustrates the timing of Update Events (UEV) relative to the counter (TIM_CNT) for different TIM_RCR settings and modes.

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.

MSv79799V1

Figure 485: Update rate examples depending on mode and TIM_RCR register settings. The figure shows timing diagrams for Counter-aligned mode and Edge-aligned mode (Upcounting and Downcounting) for various TIM_RCR values (0, 1, 2, 3) and a re-synchronization case. It illustrates the relationship between the counter (TIM_CNT) and the Update Event (UEV) indicated by arrows.

35.5.6 Clock selection

The counter clock can be provided by the following clock sources:

Internal clock source (tim_ker_ck)

If the slave mode controller is disabled (SMS = 00000), then the CEN (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 486 shows the behavior of the control circuit and the upcounter in normal mode, without prescaler.

Figure 486. Control circuit in normal mode, internal clock divided by 1

Timing diagram for Figure 486 showing the behavior of the control circuit and upcounter in normal mode without a prescaler. The diagram includes signals for tim_ker_ck, CEN, UG, counter initialization (internal), tim_cnt_ck, tim_psc_ck, and the Counter register. The Counter register shows bits 31 down to 00, with bits 32-36 being updated during the initialization phase.

The diagram illustrates the timing relationship between various signals in normal mode with an internal clock divided by 1. The signals shown are:

The diagram is labeled MSv62317V2.

Timing diagram for Figure 486 showing the behavior of the control circuit and upcounter in normal mode without a prescaler. The diagram includes signals for tim_ker_ck, CEN, UG, counter initialization (internal), tim_cnt_ck, tim_psc_ck, and the Counter register. The Counter register shows bits 31 down to 00, with bits 32-36 being updated during the initialization phase.

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 487. tim_ti2 external clock connection example Block diagram of the tim_ti2 external clock connection example. The diagram shows the signal flow from the TIM_CH2 input (tim_ti2_in0 and tim_ti2_in[15:1]) through a multiplexer controlled by TIM_TISEL (TI2SEL[3:0]). The output tim_ti2 passes through a Filter (controlled by ICF[3:0] in TIM_CCMR1) and an Edge detector. The Edge detector outputs tim_ti2f_rising and tim_ti2f_falling to a 0/1 multiplexer controlled by CC2P in TIM_CCER. The output tim_ti2_fp2 goes to a 4-to-1 multiplexer controlled by TS[4:0] in TIM_SMCR. This multiplexer has inputs for tim_itrx, tim_ti1f_ed, tim_ti1fp2, and tim_ti2_fp2. The output tim_trgi is then fed into a mode selection block. This block can be in External clock mode 1 (controlled by SMS[4:0] in TIM_SMCR) or Internal clock mode (tim_ker_ck). The final output is tim_psc_ck. The diagram is labeled MSv80000V1.
Block diagram of the tim_ti2 external clock connection example. The diagram shows the signal flow from the TIM_CH2 input (tim_ti2_in0 and tim_ti2_in[15:1]) through a multiplexer controlled by TIM_TISEL (TI2SEL[3:0]). The output tim_ti2 passes through a Filter (controlled by ICF[3:0] in TIM_CCMR1) and an Edge detector. The Edge detector outputs tim_ti2f_rising and tim_ti2f_falling to a 0/1 multiplexer controlled by CC2P in TIM_CCER. The output tim_ti2_fp2 goes to a 4-to-1 multiplexer controlled by TS[4:0] in TIM_SMCR. This multiplexer has inputs for tim_itrx, tim_ti1f_ed, tim_ti1fp2, and tim_ti2_fp2. The output tim_trgi is then fed into a mode selection block. This block can be in External clock mode 1 (controlled by SMS[4:0] in TIM_SMCR) or Internal clock mode (tim_ker_ck). The final output is tim_psc_ck. The diagram is labeled MSv80000V1.

For example, to configure the upcounter to count in response to a rising edge on the tim_ti2 input, use the following procedure:

  1. 1. Select the proper tim_ti2_in[15:0] source (internal or external) with the TI2SEL[3:0] bits in the TIM_TISEL register.
  2. 2. Configure channel 2 to detect rising edges on the tim_ti2 input by writing CC2S = 01 in the TIM_CCMR1 register.
  3. 3. Configure the input filter duration by writing the IC2F[3:0] bits in the TIM_CCMR1 register (if no filter is needed, keep IC2F = 0000).
  4. 4. Select rising edge polarity by writing CC2P = 0 in the TIM_CCER register.
  5. 5. Configure the timer in external clock mode 1 by writing SMS = 00111 in the TIM_SMCR register.
  6. 6. Select tim_ti2 as the trigger input source by writing TS = 00110 in the TIM_SMCR register.
  7. 7. Enable the counter by writing CEN = 1 in the TIM_CR1 register.

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 488. Control circuit in external clock mode 1

Timing diagram for Figure 488 showing the relationship between tim_ti2, CEN, tim_cnt_ck, tim_psc_ck, Counter register, and TIF. The diagram illustrates how the counter register increments on the falling edge of tim_ti2 when CEN is high. The TIF flag is set when the counter reaches a specific value and cleared by writing TIF=0.

MSv62319V1

Timing diagram for Figure 488 showing the relationship between tim_ti2, CEN, tim_cnt_ck, tim_psc_ck, Counter register, and TIF. The diagram illustrates how the counter register increments on the falling edge of tim_ti2 when CEN is high. The TIF flag is set when the counter reaches a specific value and cleared by writing TIF=0.

35.5.7 Capture/compare channels

Each capture/compare channel is built around a capture/compare register (including a shadow register), a input stage for capture (with digital filter, multiplexing and prescaler) and an output stage (with comparator and output control).

Figure 489 to Figure 492 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 489. Capture/compare channel (example: channel 1 input stage)

Block diagram of the capture/compare channel input stage for channel 1. It shows the signal flow from TIM_CH1 through a multiplexer, filter downcounter, edge detector, and polarity selection logic to produce tim_ti1_fp1, tim_ti1f_ed, and tim_ic1f. This signal is then used by a slave mode controller or as a capture command. The diagram also shows the control registers involved: TIM_TISEL, TIM_CCMR1, and TIM_CCER.

MSv80001V1

Block diagram of the capture/compare channel input stage for channel 1. It shows the signal flow from TIM_CH1 through a multiplexer, filter downcounter, edge detector, and polarity selection logic to produce tim_ti1_fp1, tim_ti1f_ed, and tim_ic1f. This signal is then used by a slave mode controller or as a capture command. The diagram also shows the control registers involved: TIM_TISEL, TIM_CCMR1, and TIM_CCER.

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 490. Capture/compare channel 1 main circuit

Block diagram of Capture/compare channel 1 main circuit showing input and output modes, preload register, shadow register, and counter.

This diagram illustrates the main circuit for Capture/compare channel 1. It is divided into Input mode and Output mode. In Input mode, signals CC1S[1], CC1S[0], IC1PS, and CC1E are processed through logic gates to trigger a 'Capture' event into the Capture/compare preload register. The TIM_EGR signal is also involved. In Output mode, the preload register transfers data to a compare shadow register, which then compares it with the Counter. The Comparator outputs CNT>CCR1 and CNT=CCR1 signals. The output mode also involves logic gates processing CC1S[1], CC1S[0], OC1PE, and UEV (from time base unit) to control the OC1PE output. The MCU-peripheral interface connects to the preload register via a 16/32-bit bus. The APB Bus is connected to the MCU-peripheral interface. The Counter is connected to both the preload and shadow registers.

Block diagram of Capture/compare channel 1 main circuit showing input and output modes, preload register, shadow register, and counter.

MSv80002V1

Figure 491. Output stage of capture/compare channel (channel 1)

Block diagram of the output stage of capture/compare channel 1, showing the output mode controller, output selector, dead-time generator, and output enable circuits.

This diagram shows the output stage for capture/compare channel 1. It includes an Output mode controller that receives CNT>CCR1 and CNT=CCR1 signals and outputs tim_oc1ref and tim_oc2ref. An Output selector chooses between these references. A Dead-time generator (DTG[7:0]) produces tim_oc1_dt and tim_oc1n_dt. These signals, along with '0' and '1' control signals, feed into multiplexers. The multiplexers select between signals based on CC1P and CC1NE/CC1E inputs. The selected signals are then processed by Output enable circuits to produce the final tim_oc1 and tim_oc1n outputs. The diagram also shows connections to the master mode controller and various registers: TIM_CCMR1 (OC1CE, OC1M[4:0]), TIM_BDTR (DTG[7:0]), TIM_CCER (CC1NE, CC1E, CC1NP), and TIM_CR2 (MOE, OSSR, OIS1, OIS1N).

Block diagram of the output stage of capture/compare channel 1, showing the output mode controller, output selector, dead-time generator, and output enable circuits.

MSv80003V1

Figure 492. Output stage of capture/compare channel (channel 2 for TIM15)

Block diagram of the output stage of capture/compare channel (channel 2 for TIM15). The diagram shows the flow from the Output mode controller to the Output selector, then through multiplexers controlled by TIM_CCR and TIM_CR2 registers, and finally to the Output enable circuit. Key signals include tim_ocref_clr_int, tim_oc2ref, tim_oc2refc, tim_oc1ref, and tim_oc2. Registers involved are TIM_CCMR1 (OC2CE, OC2M[3:0]) and TIM_CR2 (OIS2).

The diagram illustrates the output stage for channel 2 of a timer. It starts with an 'Output mode controller' block that receives 'CNT > CCR2' and 'CNT = CCR2' signals and outputs 'tim_ocref_clr_int'. This controller is also linked to 'OC2CE' and 'OC2M[3:0]' bits in the 'TIM_CCMR1' register. The 'Output mode controller' provides 'tim_oc2ref' to an 'Output selector' block. The 'Output selector' also receives 'tim_oc1ref' and outputs 'tim_oc2refc' to a multiplexer. This multiplexer, controlled by 'CC2E' in 'TIM_CCRER', selects between a constant '0' and 'tim_oc2refc'. The output of this multiplexer passes through an inverter and another multiplexer (controlled by 'CC2P' in 'TIM_CCRER') before reaching an 'Output enable circuit'. This final circuit, controlled by 'OIS2' in 'TIM_CR2', produces the 'tim_oc2' output signal. A connection labeled 'To the master mode controller' is also shown.

Block diagram of the output stage of capture/compare channel (channel 2 for TIM15). The diagram shows the flow from the Output mode controller to the Output selector, then through multiplexers controlled by TIM_CCR and TIM_CR2 registers, and finally to the Output enable circuit. Key signals include tim_ocref_clr_int, tim_oc2ref, tim_oc2refc, tim_oc1ref, and tim_oc2. Registers involved are TIM_CCMR1 (OC2CE, OC2M[3:0]) and TIM_CR2 (OIS2).

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.

35.5.8 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 tim_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:

  1. 1. Select the proper tim_ti1_in[15:1] source (internal or external) with the TI1SEL[3:0] bits in the TIM_TISEL register.
  2. 2. 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.
  3. 3. 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 least 5 internal clock cycles. The user must program a filter duration longer than these five clock cycles. The user can validate a transition on tim_ti1 when eight consecutive samples with the new

level have been detected (sampled at \(f_{DTS}\) frequency). Then write IC1F bits to 0011 in the TIM_CCMR1 register.

  1. 4. Select the edge of the active transition on the tim_ti1 channel by writing CC1P bit to 0 in the TIM_CCER register (rising edge in this case).
  2. 5. Program the input prescaler. In this example, the user wants the capture to be performed at each valid transition, so the prescaler is disabled (write IC1PS bits to 00 in the TIM_CCMR1 register).
  3. 6. Enable capture from the counter into the capture register by setting the CC1E bit in the TIM_CCER register.
  4. 7. 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:

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.

35.5.9 PWM input mode (only for TIM15)

This mode is used to measure both the period and the duty cycle of a PWM signal connected to single tim_tix input:

This mode is a particular case of input capture mode. The set-up procedure is similar with the following differences:

For example, one can measure the period (in TIM_CCR1 register) and the duty cycle (in TIM_CCR2 register) of the PWM applied on tim_ti1 using the following procedure (depending on tim_ker_ck frequency and prescaler value):

  1. 1. Select the proper tim_ti1_in[15:0] source (internal or external) with the TI1SEL[3:0] bits in the TIM_TISEL register.
  2. 2. Select the active input for TIM_CCR1: write the CC1S bits to 01 in the TIM_CCMR1 register (tim_ti1 selected).
  3. 3. 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).
  4. 4. Select the active input for TIM_CCR2: write the CC2S bits to 10 in the TIM_CCMR1 register (tim_ti1 selected).
  5. 5. Select the active polarity for tim_ti1fp2(used for capture in TIM_CCR2): write the CC2P and CC2NP bits to 10 (active on falling edge).
  6. 6. Select the valid trigger input: write the TS bits to 00101 in the TIM_SMCR register (tim_ti1fp1 selected).
  7. 7. Configure the slave mode controller in reset mode: write the SMS bits to 00100 in the TIM_SMCR register.
  8. 8. Enable the captures: write the CC1E and CC2E bits to 1 in the TIM_CCER register.

Figure 493. PWM input mode timing

Timing diagram for PWM input mode showing the relationship between tim_ti1, TIM_CNT, TIM_CCR1, and TIM_CCR2. The diagram illustrates three capture events: 1. IC1 capture, IC2 capture, and reset counter, which occurs when tim_ti1 transitions from low to high. 2. IC2 capture pulse width measurement, which occurs when tim_ti1 transitions from high to low. 3. IC1 capture pulse width measurement, which occurs when tim_ti1 transitions from low to high again. The TIM_CNT register shows values 0004, 0000, 0001, 0002, 0003, 0004, and 0000. The TIM_CCR1 register shows a value of 0004, and the TIM_CCR2 register shows a value of 0002. The diagram is labeled MSv80005V1.
Timing diagram for PWM input mode showing the relationship between tim_ti1, TIM_CNT, TIM_CCR1, and TIM_CCR2. The diagram illustrates three capture events: 1. IC1 capture, IC2 capture, and reset counter, which occurs when tim_ti1 transitions from low to high. 2. IC2 capture pulse width measurement, which occurs when tim_ti1 transitions from high to low. 3. IC1 capture pulse width measurement, which occurs when tim_ti1 transitions from low to high again. The TIM_CNT register shows values 0004, 0000, 0001, 0002, 0003, 0004, and 0000. The TIM_CCR1 register shows a value of 0004, and the TIM_CCR2 register shows a value of 0002. The diagram is labeled MSv80005V1.
  1. 1. The PWM input mode can be used only with the TIMx_CH1/TIMx_CH2 signals due to the fact that only tim_ti1fp1 and tim_ti2fp2 are connected to the slave mode controller.

35.5.10 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, one 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.

35.5.11 Output compare mode

This function is used to control an output waveform or indicating when a period of time has elapsed.

When a match is found between the capture/compare register and the counter, the output compare function:

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. 1. Select the counter clock (internal, external, prescaler).
  2. 2. Write the desired data in the TIM_ARR and TIM_CCRx registers.
  3. 3. Set the CCxIE bit if an interrupt request is to be generated.
  4. 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. 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 494.

Figure 494. Output compare mode, toggle on tim_oc1

Timing diagram for Output compare mode, toggle on tim_oc1. The diagram shows the Counter register, CCRx=4, CCRx=8, CCRx>8, and CCRx=0, each with tim_ocxref and CCxIF signals. The Counter register counts from 0 to 8, then wraps to 0 and 1. CCRx=4 toggles at counter value 4. CCRx=8 toggles at counter value 8. CCRx>8 is a constant '1'. CCRx=0 is a constant '0'. CCxIF is a pulse at each toggle event.

The diagram illustrates the timing of the output compare mode, toggle on tim_oc1. It shows the Counter register counting from 0 to 8, then wrapping to 0 and 1. The CCRx=4 signal toggles at counter value 4, and the CCRx=8 signal toggles at counter value 8. The CCRx>8 signal is a constant '1', and the CCRx=0 signal is a constant '0'. The CCxIF signal is a pulse at each toggle event.

Timing diagram for Output compare mode, toggle on tim_oc1. The diagram shows the Counter register, CCRx=4, CCRx=8, CCRx>8, and CCRx=0, each with tim_ocxref and CCxIF signals. The Counter register counts from 0 to 8, then wraps to 0 and 1. CCRx=4 toggles at counter value 4. CCRx=8 toggles at counter value 8. CCRx>8 is a constant '1'. CCRx=0 is a constant '0'. CCxIF is a pulse at each toggle event.

35.5.12 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 TIM15/TIM16/TIM17 are 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 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 495 shows some edge-aligned PWM waveforms in an example where TIM_ARR = 8.

Figure 495. Edge-aligned PWM waveforms (ARR = 8)

Timing diagram for edge-aligned PWM waveforms with TIM_ARR = 8. The diagram shows the Counter register counting from 0 to 8 and then wrapping to 0. It illustrates four cases for CCRx: CCRx=4, CCRx=8, CCRx>8, and CCRx=0. For each case, the tim_ocxref signal and the CCxIF flag are shown. Vertical dashed lines indicate the start of each counter cycle.

The diagram illustrates the edge-aligned PWM waveforms for different compare values (CCRx) when the autoreload value (ARR) is 8. The Counter register counts from 0 to 8 and then wraps back to 0. The tim_ocxref signal is high when the counter is less than the compare value and low otherwise. The CCxIF flag is set when the counter matches the compare value.

MSv62327V1

Timing diagram for edge-aligned PWM waveforms with TIM_ARR = 8. The diagram shows the Counter register counting from 0 to 8 and then wrapping to 0. It illustrates four cases for CCRx: CCRx=4, CCRx=8, CCRx>8, and CCRx=0. For each case, the tim_ocxref signal and the CCxIF flag are shown. Vertical dashed lines indicate the start of each counter cycle.

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 496 shows some center-aligned PWM waveforms in an example where:

Figure 496. Center-aligned PWM waveforms (ARR = 8)

Timing diagram for center-aligned PWM waveforms with ARR = 8. It shows the counter register counting up from 0 to 8 and then down from 7 to 0. Four PWM channels are shown: CCRx=4, CCRx=7, CCRx=8, and CCRx>8. For each channel, the tim_ocxref signal and the CCxIF flag status are indicated for different CMS settings (01, 10, 11).

The diagram illustrates the timing of center-aligned PWM waveforms for a timer with an auto-reload register (ARR) value of 8. The counter register counts up from 0 to 8 and then counts down from 7 to 0. Four channels are shown, each with its own compare register (CCRx) and capture/compare interrupt flag (CCxIF).

MSv62328V2

Timing diagram for center-aligned PWM waveforms with ARR = 8. It shows the counter register counting up from 0 to 8 and then down from 7 to 0. Four PWM channels are shown: CCRx=4, CCRx=7, CCRx=8, and CCRx>8. For each channel, the tim_ocxref signal and the CCxIF flag status are indicated for different CMS settings (01, 10, 11).

Hints on using center-aligned mode:

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. The Figure 497 below presents the dithering principle applied to four consecutive PWM cycles.

Figure 497. Dithering principle

Figure 497: Dithering principle showing waveforms with average duty cycles DC = 7/5, DC = (7+1/4)/5, DC = (7+1/2)/5, DC = (7+3/4)/5, and DC = 8/5 over consecutive PWM cycles.

The diagram illustrates the dithering principle applied across four consecutive PWM cycles to achieve fractional duty cycles. A base pulse width has a high-time of 7 and low-time of 5. Shaded areas represent 1 clock cycle additions on specific periods among the four consecutive cycles to generate intermediate duty cycle values (DC = 7/5, DC = (7+¼)/5, DC = (7+½)/5, DC = (7+¾)/5, and DC = 8/5).

Figure 497: Dithering principle showing waveforms with average duty cycles DC = 7/5, DC = (7+1/4)/5, DC = (7+1/2)/5, DC = (7+3/4)/5, and DC = 8/5 over consecutive PWM cycles.

When the dithering mode is enabled, the register coding is changed as follows (see Figure 498 for example):

Note: The following sequence must be followed when resetting the DITHER bit:

  1. 1. CEN and ARPE bits must be reset
  2. 2. The ARR[3:0] bits must be reset
  3. 3. The CCIF flags must be cleared
  4. 4. The CEN bit can be set (eventually with ARPE = 1).

Figure 498. Data format and register coding in dithering mode

Figure 498: Data format and register coding in dithering mode. The diagram shows two register formats. The top format, 'Register format in dithering mode', is a 20-bit register (b19 to b0) divided into a 16-bit MSB integer part and a 4-bit LSB fractional part. The bottom format, 'Example', shows a 326-bit register (b19 to b0) divided into a 20-bit integer part and a 6-bit fractional part. Arrows point from the example values to text below: 'Base compare value is 20 during 16 periods' and 'Additional 6 cycles are spread over the 16 periods'. The reference 'MSv45753V2' is at the bottom right.

Register format in dithering mode

b19 b0

MSB: 16-bits, integer part

LSB: 4-bits fractional part

Example

b19 b0

326

20 6

Base compare value is 20 during 16 periods

Additional 6 cycles are spread over the 16 periods

MSv45753V2

Figure 498: Data format and register coding in dithering mode. The diagram shows two register formats. The top format, 'Register format in dithering mode', is a 20-bit register (b19 to b0) divided into a 16-bit MSB integer part and a 4-bit LSB fractional part. The bottom format, 'Example', shows a 326-bit register (b19 to b0) divided into a 20-bit integer part and a 6-bit fractional part. Arrows point from the example values to text below: 'Base compare value is 20 during 16 periods' and 'Additional 6 cycles are spread over the 16 periods'. The reference 'MSv45753V2' is at the bottom right.

The minimum frequency is given by the following formula:

\[\text{Resolution} = \frac{F_{\text{Tim}}}{F_{\text{pwm}}} \Rightarrow F_{\text{pwmMin}} = \frac{F_{\text{Tim}}}{\text{Max}_{\text{Resolution}}}\]

\[\text{Dithering mode disabled: } F_{\text{pwmMin}} = \frac{F_{\text{Tim}}}{65536}\]

\[\text{Dithering mode enabled: } F_{\text{pwmMin}} = \frac{F_{\text{Tim}}}{65535 + \frac{15}{16}}\]

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 the Figure 499 below, the dithering mode is used to increase the PWM resolution whatever the PWM frequency.

Figure 499. PWM resolution vs frequency

Graph showing PWM resolution (20-bit and 16-bit) vs PWM frequency. Two curves are shown: 'Dithering' and 'No Dithering'. The x-axis is labeled 'PWM frequency' and the y-axis is 'PWM resolution'. A vertical dashed line marks 'FPWM min'.

The graph illustrates the relationship between PWM resolution and PWM frequency. The y-axis represents PWM resolution, with markers for 20-bit and 16-bit. The x-axis represents PWM frequency. Two curves are plotted: 'Dithering' and 'No Dithering'. Both curves show that resolution decreases as frequency increases. The 'Dithering' curve starts at a higher resolution (20-bit) at the minimum frequency \(\mathrm{F_{PWM\ min}}\), while the 'No Dithering' curve starts at 16-bit. The 'Dithering' curve remains above the 'No Dithering' curve across the frequency range shown. A vertical dashed line indicates the minimum PWM frequency \(\mathrm{F_{PWM\ min}}\).

Graph showing PWM resolution (20-bit and 16-bit) vs PWM frequency. Two curves are shown: 'Dithering' and 'No Dithering'. The x-axis is labeled 'PWM frequency' and the y-axis is 'PWM resolution'. A vertical dashed line marks 'FPWM min'.

MSv47464V2

The duty cycle and/or period changes are spread over 16 consecutive periods, as described in the Figure 500 below.

Figure 500. PWM dithering pattern

Timing diagram showing Counter period (1-16), CCR1 value (322), Compare1 value (sequence of 21 and 20), CCR2 value (326), Compare2 value (sequence of 21 and 20), ARR value (643), and Auto-Reload value (sequence of 41 and 40).

The diagram shows the dithering pattern over 16 counter periods. The parameters and their values across the 16 periods are as follows:

ParameterPeriod 1Period 2Period 3Period 4Period 5Period 6Period 7Period 8Period 9Period 10Period 11Period 12Period 13Period 14Period 15Period 16
Counter period12345678910111213141516
CCR1 value322
Compare1 value21202020202020202120202020202020
CCR2 value326
Compare2 value21202120212020202120212021202020
ARR value643
Auto-Reload value41404040414040404140404040404040
Timing diagram showing Counter period (1-16), CCR1 value (322), Compare1 value (sequence of 21 and 20), CCR2 value (326), Compare2 value (sequence of 21 and 20), ARR value (643), and Auto-Reload value (sequence of 41 and 40).

MSv47467V1

The autoreload and compare values increments are spread following specific patterns described in the Table 353 below. The dithering sequence is done to have increments distributed as evenly as possible and minimize the overall ripple.

Table 353. CCR and ARR register change dithering pattern

-PWM period
12345678910111213141516
LSB value12345678910111213141516
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---
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 501.

Figure 501. Dithering effect on duty cycle in center-aligned PWM mode

Figure 501: Dithering effect on duty cycle in center-aligned PWM mode. The figure shows three diagrams illustrating the dithering effect on the duty cycle in center-aligned PWM mode. Each diagram shows a triangular carrier wave and a PWM signal. The first diagram, 'No dithering', shows a standard PWM signal. The second diagram, 'Dithering up', shows the PWM signal shifted upwards by one step. The third diagram, 'Dithering down', shows the PWM signal shifted downwards by one step. The diagrams are labeled 'No dithering', 'Dithering up', and 'Dithering down' respectively. The reference ID 'MSv50904V1' is located at the bottom right of the figure area.
Figure 501: Dithering effect on duty cycle in center-aligned PWM mode. The figure shows three diagrams illustrating the dithering effect on the duty cycle in center-aligned PWM mode. Each diagram shows a triangular carrier wave and a PWM signal. The first diagram, 'No dithering', shows a standard PWM signal. The second diagram, 'Dithering up', shows the PWM signal shifted upwards by one step. The third diagram, 'Dithering down', shows the PWM signal shifted downwards by one step. The diagrams are labeled 'No dithering', 'Dithering up', and 'Dithering down' respectively. The reference ID 'MSv50904V1' is located at the bottom right of the figure area.

Table 354 shows how the dithering pattern is added in center-aligned PWM mode.

Table 354. CCR register change dithering pattern in center-aligned PWM mode

LSB valuePWM period
12345678
UpDnUpDnUpDnUpDnUpDnUpDnUpDnUpDn
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---
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-

35.5.13 Asymmetric PWM mode (TIM15 only)

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 registers. 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.

Figure 502 represents an example of signal that can be generated using asymmetric PWM mode (channels 1 and 2 are configured in asymmetric PWM mode 2).

Figure 502. Generation of a phase-shifted PWM signal with 50% duty cycle

Timing diagram showing the generation of a phase-shifted PWM signal with 50% duty cycle. The diagram includes a counter register sequence (0 to 7, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1) and a PWM signal (tim_oc1refc) that is high from counter value 0 to 4 and low from 5 to 8, with a phase shift indicated by a dashed line.

The diagram illustrates the generation of a phase-shifted PWM signal with a 50% duty cycle. The counter register sequence is shown as a series of boxes labeled 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1. The PWM signal (tim_oc1refc) is high from counter value 0 to 4 and low from 5 to 8. A dashed line indicates the phase shift between the counter and the PWM signal. The parameters CCR1=0 and CCR2=8 are specified.

MSv75876V1

Timing diagram showing the generation of a phase-shifted PWM signal with 50% duty cycle. The diagram includes a counter register sequence (0 to 7, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1) and a PWM signal (tim_oc1refc) that is high from counter value 0 to 4 and low from 5 to 8, with a phase shift indicated by a dashed line.

Multiple asymmetric PWM modes are available to combine different pairs of TIM_CCRx registers and generate the required waveform, as listed in Table 355. 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 (for example 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 and 2, 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] = 01110 for the asymmetric PWM mode 1 on oc1refc.

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 a 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 355. Asymmetric PWM modes

Output compare modeOCxM[4:0]oc1refcoc2refcPWM Mode(1)
Asymmetric PWM mode 101110oc1ref (up-counting)1
Asymmetric PWM mode 201111oc2ref (down-counting)2
  1. 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.

35.5.14 Combined PWM mode (TIM15 only)

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. Both signals, tim_oc1refc and tim_oc2refc, are made of an OR or AND logical combination of two reference PWMs controlled respectively by TIM_CCR1 and TIM_CCR2.

Combined PWM mode can be selected independently on two channels (one tim_ocx output per pair of CCR registers) by writing 01100 (Combined PWM mode 1) or 01101 (Combined PWM mode 2) in the OCxM bits in the TIM_CCMRx register.

When a given channel is used as a combined PWM channel, its complementary channel must be configured in the opposite PWM mode (for instance, one in Combined PWM mode 1 and the other in Combined PWM mode 2).

Note: The OCxM[4:0] bitfield is split into two parts for compatibility reasons, the most significant bit is not contiguous with the three least significant ones.

Figure 503 represents an example of signals that can be generated using Combined PWM mode, obtained with the following configuration:

Figure 503. Combined PWM mode on channel 1 and 2

Timing diagrams for combined PWM mode on channel 1 and 2. The top diagram shows tim_oc1refc = tim_oc1ref AND tim_oc2ref, and the bottom diagram shows tim_oc1refc = tim_oc1ref OR tim_oc2ref. Both diagrams include waveforms for CCR2, CCR1, tim_oc1ref, tim_oc2ref, and tim_oc1refc.

The figure contains two timing diagrams illustrating combined PWM mode on channel 1 and 2. Both diagrams show a sawtooth carrier wave and two reference levels, CCR1 and CCR2, indicated by horizontal dashed lines. The output signals are tim_oc1ref, tim_oc2ref, and tim_oc1refc.

In the top diagram, the equation \(tim\_oc1refc = tim\_oc1ref \text{ AND } tim\_oc2ref\) is shown. The tim_oc1refc signal is high only when both tim_oc1ref and tim_oc2ref are high.

In the bottom diagram, the equation \(tim\_oc1refc = tim\_oc1ref \text{ OR } tim\_oc2ref\) is shown. The tim_oc1refc signal is high when either tim_oc1ref or tim_oc2ref is high.

The reference ID MSv62330V2 is located in the bottom right corner of the diagram area.

Timing diagrams for combined PWM mode on channel 1 and 2. The top diagram shows tim_oc1refc = tim_oc1ref AND tim_oc2ref, and the bottom diagram shows tim_oc1refc = tim_oc1ref OR tim_oc2ref. Both diagrams include waveforms for CCR2, CCR1, tim_oc1ref, tim_oc2ref, and tim_oc1refc.

35.5.15 Complementary outputs and dead-time insertion

The TIM15/TIM16/TIM17 general-purpose timers can output one complementary signal and manage the switching-off and switching-on 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 and 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, OSSI and OSSR bits in the TIM_BDTR and TIM_CR2 registers. Refer to Table 362: Output control bits for complementary tim_ocx and tim_ocxn channels with break feature (TIM15) on page 1431 and Table 364: Output control bits for complementary tim_oc1 and tim_oc1n channels with break feature (TIM16/TIM17) on page 1463 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:

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. (in these examples CCxP = 0, CCxNP = 0, MOE = 1, CCxE = 1 and CCxNE = 1)

Figure 504. Complementary output with symmetrical dead-time insertion.

Timing diagram for Figure 504 showing symmetrical dead-time insertion. The diagram displays three signals: tim_ocxref, tim_ocx, and tim_ocxn. tim_ocxref is a square wave. tim_ocx is a square wave that is high when tim_ocxref is high, with a delay on its rising edge relative to tim_ocxref. tim_ocxn is a square wave that is high when tim_ocxref is low, with a delay on its rising edge relative to the falling edge of tim_ocxref. The delays are indicated by horizontal arrows labeled 'delay'.

MSv62332V1

Timing diagram for Figure 504 showing symmetrical dead-time insertion. The diagram displays three signals: tim_ocxref, tim_ocx, and tim_ocxn. tim_ocxref is a square wave. tim_ocx is a square wave that is high when tim_ocxref is high, with a delay on its rising edge relative to tim_ocxref. tim_ocxn is a square wave that is high when tim_ocxref is low, with a delay on its rising edge relative to the falling edge of tim_ocxref. The delays are indicated by horizontal arrows labeled 'delay'.

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 505.

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 505. Asymmetrical deadtime

Timing diagram for asymmetrical deadtime showing tim_ocxref, tim_ocx, and tim_ocxn signals for DTAE = 0 and DTAE = 1 cases.

The diagram illustrates the relationship between the reference signal (tim_ocxref) and the output signals (tim_ocx and tim_ocxn) under two deadtime settings:

MSv62333V1

Timing diagram for asymmetrical deadtime showing tim_ocxref, tim_ocx, and tim_ocxn signals for DTAE = 0 and DTAE = 1 cases.

Figure 506. Dead-time waveforms with delay greater than the negative pulse.

Timing diagram for dead-time waveforms where the delay is greater than the negative pulse.

This diagram shows the case where the deadtime delay is longer than the negative pulse width of the reference signal (tim_ocxref). The output signals (tim_ocx and tim_ocxn) are shown with a significant delay relative to the reference signal's transitions. A horizontal arrow labeled 'delay' indicates the time difference between the end of the reference signal's negative pulse and the start of the output signal's transition.

MSv62334V1

Timing diagram for dead-time waveforms where the delay is greater than the negative pulse.

Figure 507. Dead-time waveforms with delay greater than the positive pulse.

Timing diagram for dead-time waveforms where the delay is greater than the positive pulse.

This diagram shows the case where the deadtime delay is longer than the positive pulse width of the reference signal (tim_ocxref). The output signals (tim_ocx and tim_ocxn) are shown with a significant delay relative to the reference signal's transitions. A horizontal arrow labeled 'delay' indicates the time difference between the end of the reference signal's positive pulse and the start of the output signal's transition.

MSv62335V1

Timing diagram for dead-time waveforms where the delay is greater than the positive pulse.

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 35.8.16: TIM break and dead-time register (TIM_BDTR) on page 1435 and Section 35.9.14: TIM break and dead-time register (TIM_BDTR) on page 1467 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.

35.5.16 Clock dividers for dead-time generators and digital filters

The dead-time generators and the digital filters (for 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 508. Clock prescalers for dead-time and digital filters

Block diagram showing the clock prescalers for dead-time and digital filters. The input tim_ker_ck (with period t_tim_ker_ck) enters a Prescaler block. This block is controlled by CKD[1:0] from the TIM_CR1 register. The output of this prescaler is DTS_ck (with period t_DTS), which feeds into the 'Deadtime generator and break filters'. A second Prescaler block, controlled by CKD2[3:0] from the TIM_CR1 register, takes DTS_ck as input and produces DTS2_ck (with period t_DTS2), which feeds into the 'Digital filters (tim_tix)'. The diagram is labeled MSv80007V1 in the bottom right corner.
Block diagram showing the clock prescalers for dead-time and digital filters. The input tim_ker_ck (with period t_tim_ker_ck) enters a Prescaler block. This block is controlled by CKD[1:0] from the TIM_CR1 register. The output of this prescaler is DTS_ck (with period t_DTS), which feeds into the 'Deadtime generator and break filters'. A second Prescaler block, controlled by CKD2[3:0] from the TIM_CR1 register, takes DTS_ck as input and produces DTS2_ck (with period t_DTS2), which feeds into the 'Digital filters (tim_tix)'. The diagram is labeled MSv80007V1 in the bottom right corner.

35.5.17 Using the break function

The purpose of the break function is to protect power switches driven by PWM signals generated with the timers. The break input is 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.

The break channel gathers both system-level fault (such as clock failure, ECC/parity, and 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.

The output enable signal and output levels during break are depending on several control bits:

When exiting from reset, the break circuit is disabled and the MOE bit is low. The break function is enabled by setting the BKE bit in the TIM_BDTR register. The break input polarity can be selected by configuring the BKP bit in the same register. BKE and BKP can be modified at the same time. When the BKE and BKP 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 break is generated by the tim_brk inputs which have:

The break can be generated from multiple sources which can be individually enabled and with programmable edge sensitivity, using the TIM_AF1 register.

The sources for break (tim_brk) channel are:

Break events can also be generated by software using BG bit in the TIM_EGR register. All sources are ORed before entering the timer tim_brk inputs, as per Figure 509 below.

Figure 509. Break circuitry overview

Figure 509: Break circuitry overview. Logic diagram detailing inputs tim_sys_brk0 to tim_sys_brkx gated by Enable signals and CSS entering an OR gate to generate tim_sys_brk and SBIF flag. The bottom part details inputs TIMx_BKIN, tim_brk_cmp[4:1], tim_brk_cmp[20:5] through inversion, multiplexing/enables, BKF[3:0] filter, BKP polarity selection, BKE enable, combined with Software break requests BG to set BIF flag and output tim_brk. Labeled MSv75871V1.
Figure 509: Break circuitry overview. Logic diagram detailing inputs tim_sys_brk0 to tim_sys_brkx gated by Enable signals and CSS entering an OR gate to generate tim_sys_brk and SBIF flag. The bottom part details inputs TIMx_BKIN, tim_brk_cmp[4:1], tim_brk_cmp[20:5] through inversion, multiplexing/enables, BKF[3:0] filter, BKP polarity selection, BKE enable, combined with Software break requests BG to set BIF flag and output tim_brk. Labeled MSv75871V1.

Caution: An asynchronous (clockless) operation is only guaranteed when the programmable filter is disabled. If it is enabled, a fail-safe clock mode (for example, using the internal PLL and/or the CSS) must be used to guarantee that break events are handled.

When a break occurs (selected level on the break input):

the dead-time duration is a bit longer than usual (around 2 tim_cker_ck clock cycles).

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 acting 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 cannot be cleared.

The break can be generated by the tim_brk input which has a programmable polarity and an enable bit BKE in the TIM_BDTR register.

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 protection can be selected among 3 levels with the LOCK bits in the TIM_BDTR register. Refer to Section 35.8.16: TIM break and dead-time register (TIM_BDTR) and Section 35.9.14: TIM break and dead-time register (TIM_BDTR). The LOCK bits can be written only once after an MCU reset.

The Figure 510 shows an example of behavior for the outputs in response to a break.

Figure 510. Output behavior in response to a break event on tim_brk

Timing diagram showing output behavior of tim_ocx and tim_ocxref in response to a BREAK (MOE) event. The diagram includes multiple signal lines for tim_ocxref, tim_ocx, and tim_ocxn under various configuration conditions. It shows the timing of the break event and the subsequent delays for the output signals.

The diagram illustrates the output behavior of general-purpose timers (TIM15/TIM16/TIM17) in response to a break event (BREAK (MOE)). The signals shown are tim_ocxref, tim_ocx, and tim_ocxn under various configuration conditions.

Delays are indicated by horizontal double-headed arrows between the break event and the output transitions.

Timing diagram showing output behavior of tim_ocx and tim_ocxref in response to a BREAK (MOE) event. The diagram includes multiple signal lines for tim_ocxref, tim_ocx, and tim_ocxn under various configuration conditions. It shows the timing of the break event and the subsequent delays for the output signals.

MSv62337V1

35.5.18 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_oc2/tim_oc2n), as show on Figure 511 below:

Figure 511. Immediate break and Delayed 1/2 break modes

Timing diagram showing the behavior of tim_brk, tim_ocx, MOE, and I/O state during a break event. The diagram illustrates three modes: Immediate break (BKMx[1:0] = 00), Delayed 1 break (BKMx[1:0] = 01), and Delayed 2 break (BKMx[1:0] = 10). In all cases, a falling edge on tim_brk triggers the break. For Immediate break, tim_ocx goes low immediately. For Delayed 1 and 2 breaks, tim_ocx remains high for a specified delay before going low. MOE is cleared at the start of the break. The I/O state transitions from Active to Disabled at the start of the break.

The diagram illustrates the timing of various signals during a break event. A falling edge on the tim_brk signal triggers the break. The tim_ocx signal behavior depends on the BKMx[1:0] setting:

The MOE signal is cleared (transitions to low) at the same time as the tim_brk falling edge. The I/O state transitions from Active to Disabled at the start of the break event. The diagram is labeled MSv75802V1.

Timing diagram showing the behavior of tim_brk, tim_ocx, MOE, and I/O state during a break event. The diagram illustrates three modes: Immediate break (BKMx[1:0] = 00), Delayed 1 break (BKMx[1:0] = 01), and Delayed 2 break (BKMx[1:0] = 10). In all cases, a falling edge on tim_brk triggers the break. For Immediate break, tim_ocx goes low immediately. For Delayed 1 and 2 breaks, tim_ocx remains high for a specified delay before going low. MOE is cleared at the start of the break. The I/O state transitions from Active to Disabled at the start of the break.

The delayed break mode is triggered when:

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 512 below. Still, the Delayed

break circuitry guarantees that the tim_ocx/tim_ocxn signals cannot be set again once the break event occurred.

Figure 512. Pulse termination during delayed break

Figure 512: Pulse termination during delayed break timing diagram showing tim_brk and three cases for tim_ocx output with delayed break completion and pulse termination behavior.
Figure 512: Pulse termination during delayed break timing diagram showing tim_brk and three cases for tim_ocx output with delayed break completion and pulse termination behavior.

The Figure 513 depicts the behavior when the deadtime generator is enabled, for the 3 cases:

Figure 513. Delayed break with deadtime insertion

Figure 513: Delayed break with deadtime insertion diagram showing tim_brk, tim_ocx, and tim_ocxn signals when delayed break occurs during high-side on, low-side on, and deadtime interval.
Figure 513: Delayed break with deadtime insertion diagram showing tim_brk, tim_ocx, and tim_ocxn signals when delayed break occurs during high-side on, low-side on, and deadtime interval.

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.

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:

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.

35.5.19 Bidirectional break input

The TIM15/TIM16/TIM17 are featuring bidirectional break I/Os, as represented on Figure 514.

They are used to have:

The tim_brk input is configured in bidirectional mode using the BKBID bit in the TIM_BDTR register. The BKBID programming bit 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 requires the I/O to be configured in open-drain mode with active low polarity (using BKINP and BKP 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 event (triggered by setting the BG bit) also causes the break I/O to be forced to '0' to indicate to the external components that the timer has entered in break state. However, this is valid only if the break is enabled (BKE = 1). When a software break event is generated with BKE = 0, the outputs are put in safe state and the break flag is set, but there is no effect on the TIM_BKIN I/O.

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 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:

Table 356. Break protection disarming conditions

MOEBKBIDBKDSRMBreak protection state
00XArmed
010Armed
011Disarmed
1XXArmed

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 event:

From this point, the break circuitry is armed and active, and the MOE bit can be set to re-enable the PWM outputs.

Figure 514. Output redirection

Block diagram of output redirection logic for General Purpose Timers (TIM15/TIM16/TIM17).

The diagram illustrates the output redirection logic for General Purpose Timers (TIM15/TIM16/TIM17). It shows the flow of break signals and control logic.

Inputs and Control Signals:

Logic and Output Generation:

MSv62340V2

Block diagram of output redirection logic for General Purpose Timers (TIM15/TIM16/TIM17).

35.5.20 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:

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).

35.5.21 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.

The tim_ocref_clr_int input can be selected among several inputs, as shown on Figure 515 below.

Figure 515. tim_ocref_clr input selection multiplexer

Block diagram of the tim_ocref_clr input selection multiplexer. It shows a multiplexer selecting from inputs tim_ocref_clr0 through tim_ocref_clr15 based on the OCRSEL[3:0] bits from the TIM_AF2 register. The output is the tim_ocref_clr_int signal.

The diagram illustrates a multiplexer for selecting the tim_ocref_clr_int input. The selection is controlled by the OCRSEL[3:0] bits from the TIM_AF2 register. The multiplexer has 16 input lines labeled tim_ocref_clr0, tim_ocref_clr1, tim_ocref_clr2, followed by an ellipsis, and then tim_ocref_clr13, tim_ocref_clr14, and tim_ocref_clr15. The output of the multiplexer is the tim_ocref_clr_int signal. The diagram is labeled with the reference MSv80009V1 in the bottom right corner.

Block diagram of the tim_ocref_clr input selection multiplexer. It shows a multiplexer selecting from inputs tim_ocref_clr0 through tim_ocref_clr15 based on the OCRSEL[3:0] bits from the TIM_AF2 register. The output is the tim_ocref_clr_int signal.

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 (for example OC2CE = X for oc2ref in Figure 516) is ignored in this case.

Figure 516 to Figure 518 are describing the output waveforms for some use cases, when the ocref_clr_int signal is asserted.

Figure 516. Asymmetric PWM mode 1

Timing diagram for Asymmetric PWM mode 1 showing CC1, CC2, oc1ref, oc2ref, and oc1refc signals.

The diagram illustrates the timing of various signals for Asymmetric PWM mode 1. At the top, two triangular carrier waves, CC1 and CC2, are shown, with CC2 having a higher peak. Below these are the output reference signals, oc1ref and oc2ref, which are generated by comparing the carriers to their respective comparison levels. The oc1refc signal is shown for two cases: when OC1CE = OC2CE = 0, it is a low-level pulse; when OC1CE = 1 and OC2CE = X, it is a high-level pulse. An arrow labeled ocref_clr_int points to a specific transition on the oc1refc signal in the second case. The diagram is labeled MSv76623V1 in the bottom right corner.

Timing diagram for Asymmetric PWM mode 1 showing CC1, CC2, oc1ref, oc2ref, and oc1refc signals.

Figure 517. Asymmetric PWM mode 2

Timing diagram for Asymmetric PWM mode 2 showing CC1, CC2, oc1ref, oc2ref, and oc1refc signals.

The diagram illustrates the timing of various signals for Asymmetric PWM mode 2. It features the same triangular carrier waves CC1 and CC2 as Figure 516. The output reference signals oc1ref and oc2ref are shown, with their levels determined by the comparison of the carriers to their levels. The oc1refc signal is shown for two cases: when OC1CE = OC2CE = 0, it is a low-level pulse; when OC1CE = 1 and OC2CE = X, it is a high-level pulse. An arrow labeled ocref_clr_int points to a specific transition on the oc1refc signal in the second case. The diagram is labeled MSv76624V1 in the bottom right corner.

Timing diagram for Asymmetric PWM mode 2 showing CC1, CC2, oc1ref, oc2ref, and oc1refc signals.

Figure 518. Combined PWM mode 1

Timing diagram for Combined PWM mode 1 showing counter reset, CC1 and CC2 ramps, and various output signals (oc1ref, oc2ref, oc1refc) under different OC1CE and OC2CE configurations.

The diagram illustrates the timing relationships for Combined PWM mode 1. It shows a counter ramping up and resetting. Two capture/compare signals, CC1 and CC2, are shown as dashed lines. The output signals are:

MSv76626V2

Timing diagram for Combined PWM mode 1 showing counter reset, CC1 and CC2 ramps, and various output signals (oc1ref, oc2ref, oc1refc) under different OC1CE and OC2CE configurations.

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:

35.5.22 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).

The Figure 519 describes the behavior of the tim_ocx and tim_ocxn outputs when a COM event occurs, in 3 different examples of programmed configurations.

Figure 519. 6-step generation, COM example (OSSR = 1)

Timing diagram for 6-step generation, COM example (OSSR = 1). The diagram shows the relationship between Counter (CNT), tim_ocxref, COM event, and three examples of tim_ocx and tim_ocxn signals. It includes annotations for writing to COM, OCxM, and CCxNE registers.

The diagram illustrates the 6-step generation process for a COM example where OSSR = 1. It shows the timing of the Counter (CNT), tim_ocxref, COM event, and three examples of tim_ocx and tim_ocxn signals.

Counter (CNT) (CCRx): A sawtooth waveform representing the counter value.

tim_ocxref: A square wave signal that controls the output compare mode.

COM event: A pulse signal that occurs when the counter reaches the COM value.

Example 1: Shows the tim_ocx and tim_ocxn signals. The tim_ocx signal is high when the counter is between 0 and the COM value, and low otherwise. The tim_ocxn signal is high when the counter is between the COM value and the period, and low otherwise. Annotations indicate writing to the COM register and the OCxM register.

Example 2: Shows the tim_ocx and tim_ocxn signals. The tim_ocx signal is high when the counter is between 0 and the COM value, and low otherwise. The tim_ocxn signal is high when the counter is between the COM value and the period, and low otherwise. Annotations indicate writing to the CCxNE and OCxM registers.

Example 3: Shows the tim_ocx and tim_ocxn signals. The tim_ocx signal is high when the counter is between 0 and the COM value, and low otherwise. The tim_ocxn signal is high when the counter is between the COM value and the period, and low otherwise. Annotations indicate writing to the CCxNE and OCxM registers.

Annotations:

Registers:

MSv75877V1

Timing diagram for 6-step generation, COM example (OSSR = 1). The diagram shows the relationship between Counter (CNT), tim_ocxref, COM event, and three examples of tim_ocx and tim_ocxn signals. It includes annotations for writing to COM, OCxM, and CCxNE registers.

35.5.23 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:

Figure 520. Example of one pulse mode

Timing diagram for One-pulse mode showing the relationship between trigger, reference, output, counter, and time intervals.

The diagram illustrates the operation of one-pulse mode. It shows four signals over time: tim_ti2 (trigger), tim_oc1ref (reference output), tim_oc1 (output compare), and the Counter value. The Counter starts at 0 and increments in steps. A positive edge on tim_ti2 triggers the counter. The counter reaches the TIM_CCR1 level after a delay tDELAY. At this point, tim_oc1 switches to the tim_oc1ref level. The counter continues to increment until it reaches the TIM_ARR level, which occurs after a pulse width tPULSE. At this point, the counter resets to 0 and tim_oc1 returns to its initial level. The diagram is labeled MSv80010V1.

Timing diagram for One-pulse mode showing the relationship between trigger, reference, output, counter, and time intervals.

For example one may want to generate a positive pulse on tim_oc1 with a length of tPULSE and after a delay of tDELAY as soon as a positive edge is detected on the tim_ti2 input pin.

Let's use tim_ti2fp2 as trigger 1:

  1. 1. Select the proper tim_ti2_in[15:1] source (internal or external) with the TI2SEL[3:0] bits in the TIM_TISEL register.
  2. 2. Map tim_ti2fp2 to tim_ti2 by writing CC2S = 01 in the TIM_CCMR1 register.
  3. 3. tim_ti2fp2 must detect a rising edge, write CC2P = 0 and CC2NP = 0 in the TIM_CCER register.
  4. 4. Configure tim_ti2fp2 as trigger for the slave mode controller (tim_trgi) by writing TS = 00110 in the TIM_SMCR register.
  5. 5. tim_ti2fp2 is used to start the counter by writing SMS to 00110 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).

Since only one pulse 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).

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 \(t_{\text{DELAY min}}\) that can be obtained.

If one wants 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.

35.5.24 Retriggerable one pulse mode (TIM15 only)

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 non-retriggerable one pulse mode described in Section 35.5.23:

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] bit fields 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 521. Retriggerable one pulse mode

Timing diagram for Retriggerable one pulse mode showing tim_trgi, Counter, and tim_ocx signals.

The diagram illustrates the retriggerable one pulse mode. It shows three signals over time: tim_trgi (trigger input), Counter (sawtooth waveform), and tim_ocx (output compare signal). The tim_trgi signal has three pulses. The first pulse starts a counter ramp from 0 to a maximum value. The second pulse occurs while the counter is still ramping, causing it to reset and start a new ramp. The third pulse occurs after the counter has reached its maximum value and reset, starting another ramp. The tim_ocx signal is a rectangular pulse that starts at the beginning of each counter ramp and ends when the counter reaches its maximum value.

Timing diagram for Retriggerable one pulse mode showing tim_trgi, Counter, and tim_ocx signals.

35.5.25 Encoder interface mode

Quadrature encoder

To select Encoder Interface mode write SMS = 00001 in the TIM_SMCR register if the counter is counting on tim_ti1 edges only, SMS = 00010 if it is counting on tim_ti2 edges only and SMS = 00011 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 357. 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 357. Counting direction versus encoder signals (CC1P = CC2P = 0)

Active edgeSMS[4:0]Level on opposite signal
(tim_ti1fp1 for tim_ti2,
tim_ti2fp2 for tim_ti1)
tim_ti1fp1 signaltim_ti2fp2 signal
RisingFallingRisingFalling
Counting on tim_ti1 only
x1 mode
01110HighDownUpNo countNo count
LowNo countNo countNo countNo count
Counting on tim_ti2 only
x1 mode
01111HighNo countNo countUpDown
LowNo countNo countNo countNo count
Counting on tim_ti1 only
x2 mode
00001HighDownUpNo countNo count
LowUpDownNo countNo count
Counting on tim_ti2 only
x2 mode
00010HighNo countNo countUpDown
LowNo countNo countDownUp
Counting on tim_ti1 and
tim_ti2
x4 mode
00011HighDownUpUpDown
LowUpDownDownUp

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 522 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:

Figure 522. Example of counter operation in encoder interface mode.

Timing diagram for Figure 522 showing tim_ti1, tim_ti2, and Counter signals across forward, jitter, backward, and forward phases. The counter increments during forward and decrements during backward phases.

The diagram shows three signals over time, divided into five phases: forward, jitter, backward, jitter, and forward.
- tim_ti1 and tim_ti2 are square wave inputs.
- The Counter signal is a staircase waveform.
- In the first forward phase, the counter increments (labeled 'up').
- In the jitter phase, the counter holds its value.
- In the backward phase, the counter decrements (labeled 'down').
- In the second jitter phase, the counter holds its value.
- In the final forward phase, the counter increments again (labeled 'up').
The reference code MSv62349V1 is in the bottom right corner.

Timing diagram for Figure 522 showing tim_ti1, tim_ti2, and Counter signals across forward, jitter, backward, and forward phases. The counter increments during forward and decrements during backward phases.

Figure 523 gives an example of counter behavior when tim_ti1fp1 polarity is inverted (same configuration as above except CC1P = 1).

Figure 523. Example of encoder interface mode with tim_ti1fp1 polarity inverted.

Timing diagram for Figure 523 showing tim_ti1, tim_ti2, and Counter signals with inverted polarity for tim_ti1fp1. The counter decrements during the first forward phase and increments during the backward phase.

The diagram shows the same signals and phases as Figure 522, but with inverted polarity for tim_ti1fp1.
- In the first forward phase, the counter decrements (labeled 'down').
- In the jitter phase, the counter holds its value.
- In the backward phase, the counter increments (labeled 'up').
- In the second jitter phase, the counter holds its value.
- In the final forward phase, the counter decrements again (labeled 'down').
The reference code MSv62350V1 is in the bottom right corner.

Timing diagram for Figure 523 showing tim_ti1, tim_ti2, and Counter signals with inverted polarity for tim_ti1fp1. The counter decrements during the first forward phase and increments during the backward phase.

Figure 524 shows the timer counter value during a speed reversal, for various counting modes.

Figure 524. Quadrature encoder counting modes

Timing diagram for Quadrature encoder counting modes showing tim_ti1, tim_ti2, DIR bit, Counter x4, Counter x2, and Counter x1 signals.

The diagram illustrates the timing relationship between the quadrature encoder signals and the counter values. The signals are shown as follows:

MSv62351V1

Timing diagram for Quadrature encoder counting modes showing tim_ti1, tim_ti2, DIR bit, Counter x4, Counter x2, and Counter x1 signals.

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 525, 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:

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 525. Direction plus clock encoder mode

Timing diagram for Direction plus clock encoder mode showing tim_ti1, tim_ti2, Counter x2 mode, and Counter x1 mode signals.

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 square wave. 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.

Timing diagram for Direction plus clock encoder mode showing tim_ti1, tim_ti2, Counter x2 mode, and Counter x1 mode signals.

Directional clock encoder mode

In the directional clock mode on Figure 526, 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:

Figure 526. Directional clock encoder mode (CC1P = CC2P = 0)

Timing diagram for Directional clock encoder mode (CC1P = CC2P = 0) showing tim_ti1, tim_ti2, DIR bit, Counter x2 mode, and Counter x1 mode signals.

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 square waves. The DIR bit is high when tim_ti1 is high and low when tim_ti1 is low. 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 high to low.

Timing diagram for Directional clock encoder mode (CC1P = CC2P = 0) showing tim_ti1, tim_ti2, DIR bit, Counter x2 mode, and Counter x1 mode signals.

Figure 527. Directional clock encoder mode (CC1P = CC2P = 1)

Timing diagram for Directional clock encoder mode (CC1P = CC2P = 1). It shows five signals: tim_ti1, tim_ti2, DIR bit, Counter x2 mode, and Counter x1 mode. tim_ti1 and tim_ti2 are quadrature signals. The DIR bit is derived from them. The Counter x2 mode shows a sequence of counts: 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5. The Counter x1 mode shows a sequence of counts: 7, 8, 9, 8, 7, 6. The diagram illustrates how the counter increments or decrements based on the direction of the quadrature signals.

MSv62354V1

Timing diagram for Directional clock encoder mode (CC1P = CC2P = 1). It shows five signals: tim_ti1, tim_ti2, DIR bit, Counter x2 mode, and Counter x1 mode. tim_ti1 and tim_ti2 are quadrature signals. The DIR bit is derived from them. The Counter x2 mode shows a sequence of counts: 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5. The Counter x1 mode shows a sequence of counts: 7, 8, 9, 8, 7, 6. The diagram illustrates how the counter increments or decrements based on the direction of the quadrature signals.

Table 358 here-below details how the directional clock mode operates, for any input transition.

Table 358. Counting direction versus encoder signals and polarity settings

Directional clock modeSMS[4:0]Level on opposite signal
(tim_ti1fp1 for tim_ti2,
tim_ti2fp2 for tim_ti1)
tim_ti1fp1 signaltim_ti2fp2 signal
RisingFallingRisingFalling
x2 mode
CCxP = 0
01100HighDownDownUpUp
LowNo countNo countNo countNo count
x2 mode
CCxP = 1
01100HighNo countNo countNo countNo count
LowDownDownUpUp
x1 mode
CCxP = 0
01101HighNo countDownNo countUp
LowNo countNo countNo countNo count
x1 mode
CCxP = 1
01101HighNo countNo countNo countNo count
LowDownNo countUpNo count

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 528. 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 528. State diagram for quadrature encoded signals

State diagram for quadrature encoded signals showing transitions between 00, 01, 10, and 11 states. Correct transitions are shown with solid double-headed arrows, and erroneous transitions are shown with dashed double-headed arrows.
graph TD
    00((00)) <-->|Correct| 01((01))
    00 <-->|Correct| 10((10))
    01 <-->|Correct| 11((11))
    10 <-->|Correct| 11
    00 <-->|Erroneous| 11
    01 <-->|Erroneous| 10
  

Legend:
———— Correct transitions
- - - - Erroneous transitions

MSv45779V1

State diagram for quadrature encoded signals showing transitions between 00, 01, 10, and 11 states. Correct transitions are shown with solid double-headed arrows, and erroneous transitions are shown with dashed double-headed arrows.

Functional encoder interrupts

The following interrupt is also available in encoder mode

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 529.

For this purpose, the SMS[4:0] bit can be preloaded. The transfer is triggered by the update event (UEV) occurring when the counter overflows when upcounting, and underflows when downcounting.

Figure 529. Encoder mode change with preload transferred on update

Timing diagram showing counter value, update events, preload values, and active values across x4, x2, and x1 modes. It illustrates how the preload value is transferred to the active value upon an update event.

MSv75879V1

Timing diagram showing counter value, update events, preload values, and active values across x4, x2, and x1 modes. It illustrates how the preload value is transferred to the active value upon an update event.

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, 10101, 01110, 01111. Any other SMS[4:0] code is not allowed and may lead to unexpected behavior.

35.5.26 Encoder with built-in debouncer (TIM15 only)

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 530 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 531 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 530. Encoder with built-in debouncer, x2 mode Timing diagram for Figure 530 showing encoder with built-in debouncer, x2 mode, with signals Input 1, Input 2, Input 1 Debounced, Direction, and Counter x2 values.

MSv75806V1

Timing diagram for Figure 530 showing encoder with built-in debouncer, x2 mode, with signals Input 1, Input 2, Input 1 Debounced, Direction, and Counter x2 values.
Figure 531. Encoder with built-in debouncer, x4 mode Timing diagram for Figure 531 showing encoder with built-in debouncer, x4 mode, with signals Input 1, Input 2, Input 1 Debounced, Input 2 Debounced, Direction, and Counter x4 values.

MSv75807V2

Timing diagram for Figure 531 showing encoder with built-in debouncer, x4 mode, with signals Input 1, Input 2, Input 1 Debounced, Input 2 Debounced, Direction, and Counter x4 values.

35.5.27 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 532, 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:

Figure 532. Clock drift measure using directional clock mode

Figure 532: Clock drift measure using directional clock mode. The diagram shows three waveforms: tim_ti1, tim_ti2, and Counter value. The top section shows tim_ti1 and tim_ti2 signals. The bottom section shows the Counter value waveform. The counter value is shown for three cases: 1) F_tim_ti1 > F_tim_ti2, where the counter value increases from 0x0000 to 0x0002. 2) F_tim_ti1 = F_tim_ti2, where the counter value dithers between 0x0000 and 0x0001. 3) F_tim_ti1 < F_tim_ti2, where the counter value decreases from 0x0000 to 0xFFFF and then to 0xFFFE. The counter value is shown as a digital signal with levels 0x0002, 0x0001, 0x0000, 0xFFFF, and 0xFFFE. The diagram is labeled MSv67593V1.
Figure 532: Clock drift measure using directional clock mode. The diagram shows three waveforms: tim_ti1, tim_ti2, and Counter value. The top section shows tim_ti1 and tim_ti2 signals. The bottom section shows the Counter value waveform. The counter value is shown for three cases: 1) F_tim_ti1 > F_tim_ti2, where the counter value increases from 0x0000 to 0x0002. 2) F_tim_ti1 = F_tim_ti2, where the counter value dithers between 0x0000 and 0x0001. 3) F_tim_ti1 < F_tim_ti2, where the counter value decreases from 0x0000 to 0xFFFF and then to 0xFFFE. The counter value is shown as a digital signal with levels 0x0002, 0x0001, 0x0000, 0xFFFF, and 0xFFFE. The diagram is labeled MSv67593V1.

35.5.28 UIF bit remapping

The IUFREMAP bit in the TIM_CR1 register forces a continuous copy of the update interrupt flag UIF into bit 31 of the timer counter register (TIM_CNT[31]). This is used to atomically read both the counter value and a potential roll-over condition signaled by the UIFCPY flag. 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 assertions of the UIF and UIFCPY flags.

35.5.29 Timer input XOR function (TIM15 only)

The TI1S bit in the TIM_CR2 register, allows the input filter of channel 1 to be connected to the output of a XOR gate, combining the two input pins tim_ti1 and tim_ti2.

The XOR output can be used with all the timer input functions such as trigger or input capture. It is useful for measuring the interval between the edges on two input signals, as shown in Figure 533.

Figure 533. Measuring time interval between edges on 2 signals

Timing diagram showing the measurement of time intervals between edges on 2 signals: tim_ti1, tim_ti2, tim_ti1 XOR tim_ti2, and Counter (MSv63068V1)

The diagram shows the relationship between waveforms of tim_ti1 and tim_ti2, the resulting tim_ti1 XOR tim_ti2 signal, and the Counter ramp resets at each edge transition. Reference ID: MSv63068V1.

Timing diagram showing the measurement of time intervals between edges on 2 signals: tim_ti1, tim_ti2, tim_ti1 XOR tim_ti2, and Counter (MSv63068V1)

The XORPS control bit selects the position of the XOR gate, as shown in the Figure 534 and Figure 535 below, when the TI1S bit is set.

Figure 534. XOR gate connection with TI1S = 1 and XORPS = 0

Block diagram of XOR gate connection with TI1S = 1 and XORPS = 0 (MSv80011V1)

Block diagram showing TIM_CR2 bits TI1INV and TI2INV controlling multiplexers/inverters feeding an XOR gate that produces tim_ti1f_ed. Signals tim_ti1 and tim_ti2 also pass through Filter blocks to generate tim_ti1fp1/2 and tim_ti2fp1/2 respectively, with status flags TI1FS and TI2FS in TIM_SR. Reference ID: MSv80011V1.

Block diagram of XOR gate connection with TI1S = 1 and XORPS = 0 (MSv80011V1)

Figure 535. XOR gate connection with TI1S = 1 and XORPS = 1

Block diagram of the XOR gate connection for general purpose timers. Two input signals, tim_ti1 and tim_ti2, each pass through a Filter block. The outputs of the filters are connected to an XOR gate. The inputs to the XOR gate are also connected to TI1INV and TI2INV control bits from the TIM_CR2 register. The output of the XOR gate is connected to an Edge detector block. The Edge detector output, labeled tim_ti1f_ed, is connected to the TI1FS and TI2FS status bits in the TIM_SR register. The Edge detector also provides two outputs: tim_ti1fp1/2 and tim_ti2fp1/2. The diagram is labeled MSv80012V1 in the bottom right corner.
Block diagram of the XOR gate connection for general purpose timers. Two input signals, tim_ti1 and tim_ti2, each pass through a Filter block. The outputs of the filters are connected to an XOR gate. The inputs to the XOR gate are also connected to TI1INV and TI2INV control bits from the TIM_CR2 register. The output of the XOR gate is connected to an Edge detector block. The Edge detector output, labeled tim_ti1f_ed, is connected to the TI1FS and TI2FS status bits in the TIM_SR register. The Edge detector also provides two outputs: tim_ti1fp1/2 and tim_ti2fp1/2. The diagram is labeled MSv80012V1 in the bottom right corner.

Two control bits TI1INV and TI2INV in the TIM_CR2 register can invert the tim_in1 and tim_in2 signals prior entering the XOR gate.

The status of the tim_in1 and tim_in2 signals can be software polled using the TI1FS and TI2FS bits in the TIM_SR register.

35.5.30 External trigger synchronization (TIM15 only)

The TIM timers are linked together internally for timer synchronization or chaining.

The TIM15 timer can be synchronized with an external trigger 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:

  1. 1. Configure the channel 1 to detect rising edges on tim_ti1. Configure the input filter duration (in this example, no need for any filter, so IC1F is kept at 0000). The capture prescaler is not used for triggering, so it does not need to be configured. The CC1S bits select the input capture source only, CC1S = 01 in the TIM_CCMR1 register. Write CC1P = 0 and CC1NP = 0 in the TIM_CCER register to validate the polarity (and detect rising edges only).
  2. 2. Configure the timer in reset mode by writing SMS = 00100 in TIM_SMCR register. Select tim_ti1 as the input source by writing TS = 00101 in TIM_SMCR register.
  3. 3. Start the counter by writing CEN = 1 in the TIM_CR1 register.

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 536. Control circuit in reset mode

Timing diagram illustrating Figure 536: Control circuit in reset mode. It shows signals: tim_ti1 (active high pulse), Counter reset and update (pulse at reset), tim_cnt_ck, tim_psc_ck (clock waveform), Counter register counting hex sequence 30, 31, 32, 33, 34, 35, 36, 00, 01, 02, 03, then reset to 00, 01, 02, 03, and TIF (trigger interrupt flag asserting high upon ti1 trigger). Reference MSv62361V1.
Timing diagram illustrating Figure 536: Control circuit in reset mode. It shows signals: tim_ti1 (active high pulse), Counter reset and update (pulse at reset), tim_cnt_ck, tim_psc_ck (clock waveform), Counter register counting hex sequence 30, 31, 32, 33, 34, 35, 36, 00, 01, 02, 03, then reset to 00, 01, 02, 03, and TIF (trigger interrupt flag asserting high upon ti1 trigger). Reference MSv62361V1.

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:

  1. 1. Configure the channel 1 to detect low levels on tim_ti1. Configure the input filter duration (in this example, no need for any filter, so IC1F is kept at 0000). The capture prescaler is not used for triggering, so it does not need to be configured. The CC1S bits select the input capture source only, CC1S = 01 in TIM_CCMR1 register. Write CC1P = 1 and CC1NP = 0 in the TIM_CCER register to validate the polarity (and detect low level only).
  2. 2. Configure the timer in gated mode by writing SMS = 00101 in TIM_SMCR register. Select tim_ti1 as the input source by writing TS = 00101 in TIM_SMCR register.
  3. 3. Enable the counter by writing CEN = 1 in the TIM_CR1 register (in gated mode, the counter does not start if CEN = 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 537. Control circuit in gated mode

Timing diagram for Figure 537: Control circuit in gated mode. The diagram shows five signals over time: tim_ti1, Counter enable, tim_cnt_ck, tim_psc_ck, Counter register, and TIF. tim_ti1 is a square wave that starts high, goes low, then high again. Counter enable is a constant high signal. tim_cnt_ck and tim_psc_ck are square waves that are active (high) only when tim_ti1 is low. The Counter register shows bits 30-33 incrementing from 0 to 33 while tim_ti1 is low, then freezing at 34 when tim_ti1 goes high. The TIF signal is low initially, then goes high at the rising edge of tim_ti1 (when the counter starts), and goes high again at the rising edge of tim_ti1 (when the counter stops). Arrows from 'Write TIF = 0' point to the falling edges of the TIF signal.

MSv62362V1

Timing diagram for Figure 537: Control circuit in gated mode. The diagram shows five signals over time: tim_ti1, Counter enable, tim_cnt_ck, tim_psc_ck, Counter register, and TIF. tim_ti1 is a square wave that starts high, goes low, then high again. Counter enable is a constant high signal. tim_cnt_ck and tim_psc_ck are square waves that are active (high) only when tim_ti1 is low. The Counter register shows bits 30-33 incrementing from 0 to 33 while tim_ti1 is low, then freezing at 34 when tim_ti1 goes high. The TIF signal is low initially, then goes high at the rising edge of tim_ti1 (when the counter starts), and goes high again at the rising edge of tim_ti1 (when the counter stops). Arrows from 'Write TIF = 0' point to the falling edges of the TIF signal.

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:

  1. 1. Configure the channel 2 to detect rising edges on tim_ti2. Configure the input filter duration (in this example, no need for any filter, so IC2F is kept at 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 the TIM_CCER register to validate the polarity (and detect low level only).
  2. 2. Configure the timer in trigger mode by writing SMS = 00110 in the TIM_SMCR register. Select tim_ti2 as the input source by writing TS = 00110 in the 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 538. Control circuit in trigger mode

Timing diagram for Figure 538: Control circuit in trigger mode. The diagram shows five signals over time: tim_ti2, Counter enable, tim_cnt_ck, tim_psc_ck, Counter register, and TIF. A vertical dashed line marks the rising edge of tim_ti2. Before this edge, tim_ti2 is low, Counter enable is low, tim_cnt_ck and tim_psc_ck are low, Counter register shows value 34, and TIF is low. At the rising edge of tim_ti2, Counter enable transitions to high. tim_cnt_ck and tim_psc_ck transition to a high-frequency square wave. The Counter register value increments from 34 to 35, 36, 37, and 38. TIF transitions to high. The diagram is labeled MSv62363V1 in the bottom right corner.
Timing diagram for Figure 538: Control circuit in trigger mode. The diagram shows five signals over time: tim_ti2, Counter enable, tim_cnt_ck, tim_psc_ck, Counter register, and TIF. A vertical dashed line marks the rising edge of tim_ti2. Before this edge, tim_ti2 is low, Counter enable is low, tim_cnt_ck and tim_psc_ck are low, Counter register shows value 34, and TIF is low. At the rising edge of tim_ti2, Counter enable transitions to high. tim_cnt_ck and tim_psc_ck transition to a high-frequency square wave. The Counter register value increments from 34 to 35, 36, 37, and 38. TIF transitions to high. The diagram is labeled MSv62363V1 in the bottom right corner.

Slave mode selection preload for run-time encoder mode update

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 is the update event (UEV) occurring when the counter overflows.

35.5.31 Slave mode – combined reset + trigger mode (TIM15 only)

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.

35.5.32 Slave mode – combined reset + gated mode (TIM15 only)

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).

35.5.33 Timer synchronization (TIM15 only)

The TIMx timers are linked together internally for timer synchronization or chaining. Refer to Section 32.4.27: Timer synchronization for details.

Note: The clock of the slave peripherals (such as timer and ADC) receiving the tim_trgo signal 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.

35.5.34 Using timer output as trigger for other timers (TIM16/TIM17 only)

The timers with one channel only do not feature a master mode. However, the OC1 output signal can be used to trigger some other timers (including timers described in other sections of this document). Check the “TIMx internal trigger connection” table of any timer on the device to identify which timers can be targeted as slave.

The OC1 signal pulse width must be programmed to be at least two clock cycles of the destination timer, to make sure the slave timer detects the trigger.

For instance, if the destination's timer CK_INT clock is four times slower than the source timer, the OC1 pulse width must be eight clock cycles.

35.5.35 ADC triggers (TIM15 only)

The timer can generate an ADC triggering event with various internal signals, such as reset, enable or compare events.

Note: The clock of the slave peripherals (such as timer, ADC) receiving the tim_trgo signal 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.

35.5.36 ADC synchronization (TIM15 only)

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 semi-synchronous clocks (clocks derived from a same source with integer ratio tim_ker_ck/ad_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 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 2 requirements below is met (depending on the selected trigger source):

  1. 1. The counter period must be a multiple of the ADC clock period

\[(TIM\_PSC + 1) \times (TIM\_ARR + 1) \times T_{tim\_ker\_ck} = n \times T_{adc\_ker\_ck}\]

  1. 2. The compare value must be a multiple of the ADC clock period

\[(TIM\_PSC + 1) \times TIM\_CCRx \times T_{tim\_ker\_ck} = m \times T_{adc\_ker\_ck}\]

If none of the 2 above requirement 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. 1. Enable the destination ADC clock
  2. 2. Configure the timer and set the ADSYNC bit
  3. 3. Configure the ADC and enable it (using ADSTART and/or JADSTART bits)
  4. 4. Start the timer (with the CEN counter enable bit)

35.5.37 DMA burst mode

The TIMx timers have the capability to generate multiple DMA requests on a single event. The main purpose is to be able to reprogram several timer registers 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 (either in half-words or in bytes).

The DBA[4:0] bits in the TIM_DCR registers define the DMA base address for DMA transfers (when read/write accesses 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 35.8.23: TIM output override register (TIM_OOR) and Section 35.9.21: TIM output override register (TIM_OOR) for details).

For example, the timer DMA burst feature can be used to update the contents of the CCRx registers (x = 2,3,4) on an update event, with the DMA transferring half words into the CCRx registers.

This is done in the following steps:

  1. 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 the CCRx registers.
    • – Number of data to transfer = 3 (See note below).
    • – Circular mode disabled.
  2. 2. Configure the DCR register by configuring the DBA and DBL bit fields as follows: DBL = 2, DBA = 0xE and DBSS[3:0] = 1.
  3. 3. Enable the TIMx update DMA request (set the UDE bit in the DIER register).
  4. 4. Enable TIMx
  5. 5. Enable the DMA channel

This example is for the case where every CCRx register is 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.

35.5.38 TIM15/TIM16/TIM17 DMA requests

The TIM15/TIM16/TIM17 can generate a DMA request, as shown in Table 359.

Table 359. DMA request

DMA request signalDMA requestEnable control bit
tim_upd_dmaUpdateUDE
tim_cc1_dmaCapture/compare 1CC1DE
tim_cc2_dmaCapture/compare 2CC2DE
tim_com_dmaCommutation (COM)COMDE
tim_trgi_dmaTriggerTDE

35.5.39 Debug mode

When the microcontroller enters debug mode (Cortex-M33 core halted), the TIMx counter can either continue to work normally or stop.

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) to force them to Hi-Z.

For more details, refer to the debug section.

35.6 TIM15/TIM16/TIM17 low-power modes

Table 360. Effect of low-power modes on TIM15/TIM16/TIM17

ModeDescription
SleepNo effect, peripheral is active. The interrupts can cause the device to exit from Sleep mode.
StopThe timer operation is stopped and the register content is kept. No interrupt can be generated.
StandbyThe timer is powered-down and must be reinitialized after exiting the Standby mode.

35.7 TIM15/TIM16/TIM17 interrupts

The TIM15/TIM16/TIM17 can generate multiple interrupts, as shown in Table 361.

Table 361. Interrupt requests

Interrupt acronymInterrupt eventEvent flagEnable control bitInterrupt clear methodExit from Sleep modeExit from Stop and Standby mode
TIM_UPUpdateUIFUIEwrite 0 in UIFYesNo
TIM_CCCapture/compare 1CC1IFCC1IEwrite 0 in CC1IFYesNo
Capture/compare 2(1)CC2IFCC2IEwrite 0 in CC2IFYesNo
TIM_TRG_COMCommutation (COM)COMIFCOMIEwrite 0 in COMIFYesNo
Trigger(1)TIFTIEwrite 0 in TIFYesNo
TIM_DIRDirectionDIRFDIRIEwrite 0 in DIRFYesNo
TIM_BRKBreakBIFBIEwrite 0 in BIFYesNo
System BreakSBIFwrite 0 in SBIFYesNo
TIM_TERTransition ErrorTERRFTERRIEwrite 0 in TERRFYesNo

1. Available for TIM15 only.

35.8 TIM15 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).

35.8.1 TIM control register 1 (TIM_CR1)

Address offset: 0x00

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.CKD2[3:0]Res.Res.Res.Res.Res.Res.Res.Res.
rwrwrwrw
1514131211109876543210
Res.Res.Res.DITHE
N
UIFRE
MAP
Res.CKD[1:0]ARPECMS[1:0]DIROPMURSUDISCEN
rwrwrwrwrwrwrwrwrwrwrwrw

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:13 Reserved, must be kept at reset value.

Bit 12 DITHE: Dithering enable

0: Dithering disabled

1: Dithering enabled

Note: The DITHE 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 (\(t_{\text{tim\_ker\_ck}}\)) frequency and the dead-time and sampling clock (\(t_{\text{DTS}}\)) used by the dead-time generators and the digital filters (\(t_{\text{tim\_tix}}\))

Bit 7 ARPE: Auto-reload preload enable

Bits 6:5 CMS[1:0]: Center-aligned mode selection

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

Note: This bit is read only when the timer is configured in Center-aligned mode or Encoder mode.

Bit 3 OPM: One-pulse mode

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 if enabled. These events can be:

1: Only counter overflow/underflow generates an update interrupt 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:

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 and gated 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.

35.8.2 TIM control register 2 (TIM_CR2)

Address offset: 0x04

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.TI2INVTI1INVADSYN
C
XORPSRes.MMS[3]Res.Res.Res.Res.Res.Res.Res.Res.Res.
rwrwrwrwrw
1514131211109876543210
Res.Res.Res.Res.Res.OIS2OIS1NOIS1TI1SMMS[2:0]CCDSCCUSRes.CCPC
rwrwrwrwrwrwrwrwrwrw

Bit 31 Reserved, must be kept at reset value.

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

Bits 25, 6:4 MMS[3:0]: Master mode selection

These bits are used to select the information to be sent in master mode to slave timers for synchronization (tim_trgo). The combination is as follows:

Others: reserved.

Bit 3 CCDS: Capture/compare DMA selection

Bit 2 CCUS: Capture/compare control update selection

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

Note: This bit acts only on channels that have a complementary output.

35.8.3 TIM slave mode control register (TIM_SMCR)

Address offset: 0x08

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.SMSPERes.Res.TS[4:3]Res.Res.SMS[4:3]
rwrwrwrwrw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.MSMTS[2:0]Res.SMS[2:0]
rwrwrwrwrwrwrw

Bits 31:25 Reserved, must be kept at reset value.

Bit 24 SMSPE: SMS preload enable

This bit selects whether the SMS[4: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 19:18 Reserved, must be kept at reset value.

Bits 15:8 Reserved, must be kept at reset value.

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 the user wants to synchronize several timers on a single external event.

Bits 21, 20, 6, 5, 4 TS[4:0]: Trigger selection

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: Reserved
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)
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)

Others: Reserved

See Section 35.5.2: TIM15/TIM16/TIM17 pins and internal signals for more details on tim_itrx 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 Reserved, must be kept at reset value.

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.

Others: Reserved.

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 tim_ti1f, whereas the gated mode checks the level of the trigger signal.

The clock of the slave peripherals (such as timer and ADC) receiving the tim_trgo signal 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.

35.8.4 TIM DMA/interrupt enable register (TIM_DIER)

Address offset: 0x0C

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.TERRI
E
Res.DIRIERes.Res.Res.Res.Res.
rwrw
1514131211109876543210
Res.TDECOMD
E
Res.Res.CC2DECC1DEUDEBIETIECOMIERes.Res.CC2IECC1IEUIE
rwrwrwrwrwrwrwrwrwrwrw

Bits 31:24 Reserved, must be kept at reset value.

Bit 23 TERRIE: Transition error interrupt enable

Bit 22 Reserved, must be kept at reset value.

Bit 21 DIRIE: Direction change interrupt enable

Bits 20:15 Reserved, must be kept at reset value.

Bit 14 TDE: Trigger DMA request enable

Bit 13 COMDE: COM DMA request enable

Bits 12:11 Reserved, must be kept at reset value.

Bit 10 CC2DE: Capture/compare 2 DMA request enable

Bit 9 CC1DE: Capture/compare 1 DMA request enable

Bit 8 UDE: Update DMA request enable

Bit 7 BIE: Break interrupt enable

Bit 6 TIE: Trigger interrupt enable

Bit 5 COMIE: COM interrupt enable

0: COM interrupt disabled

1: COM interrupt enabled

Bits 4:3 Reserved, must be kept at reset value.

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

35.8.5 TIM status register (TIM_SR)

Address offset: 0x10

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.TI2FSTI1FSRes.Res.Res.UIOVR
F
TERRFRes.DIRFRes.Res.Res.Res.Res.
rrrc_w0rc_w0rc_w0
1514131211109876543210
Res.BGFSBIFRes.Res.CC2OFCC1OFRes.BIFTIFCOMIFRes.Res.CC2IFCC1IFUIF
rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0

Bits 31:30 Reserved, must be kept at reset value.

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:25 Reserved, must be kept at reset value.

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 5 COMIF: COM interrupt flag

This flag is set by hardware on a COM event (once the capture/compare control bits –CCxE, CCxNE, OCxM– have been updated). It is cleared by software.

Bits 4:3 Reserved, must be kept at reset value.

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).

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.

35.8.6 TIM event generation register (TIM_EGR)

Address offset: 0x14

Reset value: 0x0000

1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.BGTGCOMGRes.Res.CC2GCC1GUG
wwrwwww

Bits 15:8 Reserved, must be kept at reset value.

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: When the CCPC bit is set, it is possible to update the CCxE, CCxNE and OCxM bits

Note: This bit acts only on channels that have a complementary output.

Bits 4:3 Reserved, must be kept at reset value.

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).

35.8.7 TIM capture/compare mode register 1 (TIM_CCMR1)

Address offset: 0x18

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).

RM0522column_2column_3column_4column_5column_6column_7column_8column_9column_10column_11column_12column_13column_14column_15column_16
31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
IC2F[3:0]IC2PSC[1:0]CC2S[1:0]IC1F[3:0]IC1PSC[1:0]CC1S[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
Bits 15:12IC2F[3:0]:Input capture 2 filter
Bits 11:10IC2PSC[1:0]: Input capture 2 prescaler
Bits 9:8CC2S[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

Bits 11:10 IC2PSC[1:0]: Input capture 2 prescaler

Bits 9:8 CC2S[1:0]: Capture/compare 2 selection

Note: CC2S bits are writable only when the channel is OFF (CC2E = 0 in TIM_CCER).

ST logo
ST logo

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_{DTS}\)

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_{DTS}/2\), N = 6

0101: \(f_{SAMPLING} = f_{DTS}/2\), N = 8

0110: \(f_{SAMPLING} = f_{DTS}/4\), N = 6

0111: \(f_{SAMPLING} = f_{DTS}/4\), N = 8

1000: \(f_{SAMPLING} = f_{DTS}/8\), N = 6

1001: \(f_{SAMPLING} = f_{DTS}/8\), N = 8

1010: \(f_{SAMPLING} = f_{DTS}/16\), N = 5

1011: \(f_{SAMPLING} = f_{DTS}/16\), N = 6

1100: \(f_{SAMPLING} = f_{DTS}/16\), N = 8

1101: \(f_{SAMPLING} = f_{DTS}/32\), N = 5

1110: \(f_{SAMPLING} = f_{DTS}/32\), N = 6

1111: \(f_{SAMPLING} = f_{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).

35.8.8 TIM capture/compare mode register 1 [alternate] (TIM_CCMR1)

Address offset: 0x18

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).

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.OC2M[4:3]Res.Res.Res.Res.Res.Res.OC1M[4:3]
rwrwrwrw
1514131211109876543210
OC2CEOC2M[2:0]OC2PEOC2FECC2S[1:0]OC1CEOC1M[2:0]OC1PEOC1FECC1S[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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
Refer to OC1CE description on bit 7.

Bits 25:24, 14:12 OC2M[4:0]: Output compare 2 mode
Refer to OC1M description on bits 6:4.

Bit 11 OC2PE: Output compare 2 preload enable
Refer to OC1PE description on bit 3.

Bit 10 OC2FE: Output compare 2 fast enable
Refer to OC1FE description on bit 2.

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 input.

1: tim_oc1ref is cleared as soon as a High level is detected on tim_ocref_clr_int input.

Note: This mode is not available for all PWM modes. Refer to Section 35.5.21: 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 - Channel 1 is active as long as TIM_CNT< TIM_CCR1 else inactive.

00111: PWM mode 2 - Channel 1 is inactive as long as TIM_CNT< TIM_CCR1 else active.

01000: Retriggerable 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: Retriggerable 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: Reserved

01011: Reserved

01100: Combined PWM mode 1 - tim_oc1ref has the same behavior as in PWM mode 1. tim_oc1refc is the logical OR between tim_oc1ref and tim_oc2ref.

01101: Combined PWM mode 2 - tim_oc1ref has the same behavior as in PWM mode 2. tim_oc1refc is the logical AND between tim_oc1ref and tim_oc2ref.

01110: Asymmetric PWM mode 1 - tim_oc1ref has the same behavior as in PWM mode 1. tim_oc1refc outputs tim_oc1ref when the counter is counting up, tim_oc2ref when it is counting down.

01111: Asymmetric PWM mode 2 - tim_oc1ref has the same behavior as in PWM mode 2. tim_oc1refc outputs tim_oc1ref when the counter is counting up, tim_oc2ref when it is counting down.

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).

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.

On channels that have 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, tim_ocx is set to the compare level independently of 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).

35.8.9 TIM capture/compare enable register (TIM_CCER)

Address offset: 0x20

Reset value: 0x0000

1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.CC2NPRes.CC2PCC2ECC1NPCC1NECC1PCC1E
rwrwrwrwrwrwrw

Bits 15:8 Reserved, must be kept at reset value.

Bit 7 CC2NP: Capture/compare 2 complementary output polarity

Refer to CC1NP description

Bit 6 Reserved, must be kept at reset value.

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 (the channel is configured in output). On channels that have 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.

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.

Bit 1 CC1P: Capture/compare 1 output polarity

CC1 channel configured as output:

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: this 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). On channels that have 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.

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 362 for details. Table 362. Output control bits for complementary tim_ocx and tim_ocxn channels with break feature (TIM15)
Control bitsOutput states(1)
MOE bitOSSI bitOSSR bitCCxE bitCCxNE bittim_ocx output statetim_ocxn output state
1XX00Output Disabled (not driven by the timer: Hi-Z)
tim_ocx = 0
tim_ocxn = 0
100Off-State (output enabled with inactive state)
tim_ocx=CCxP, tim_ocxn=CCxNP
001Output Disabled (not driven by the timer: Hi-Z)
tim_ocx = 0
tim_ocxref + Polarity
tim_ocxn = tim_ocxref XOR CCxNP
010tim_ocxref + Polarity
tim_ocx = tim_ocxref XOR CCxP
Output Disabled (not driven by the timer: Hi-Z)
tim_ocxn = 0
X11tim_ocxref + Polarity + dead-timeComplementary to tim_ocxref (not OCREf) + Polarity + dead-time
101Off-State (output enabled with inactive state)
tim_ocx = CCxP
tim_ocxref + Polarity
tim_ocxn = tim_ocxref XOR CCxNP
110tim_ocxref + Polarity
tim_ocx = tim_ocxref xor CCxP
Off-State (output enabled with inactive state)
tim_ocxn = CCxNP
00XXXOutput disabled (not driven by the timer: Hi-Z)
100
01Off-State (output enabled with inactive state)
Asynchronously: tim_ocx = CCxP, tim_ocxn = CCxNP
Then 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 tim_ocx and tim_ocxn both in active state
10
11

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 GPIO control and alternate function selection registers.

35.8.10 TIM counter (TIM_CNT)

Address offset: 0x24

Reset value: 0x0000 0000

31302928272625242322212019181716
UIFCP
Y
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
r
1514131211109876543210
CNT[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bit 31 UIFCPY: UIF Copy

This bit is a read-only copy of the UIF bit in the TIM_SR register.

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.

35.8.11 TIM prescaler (TIM_PSC)

Address offset: 0x28

Reset value: 0x0000

1514131211109876543210
PSC[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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”).

35.8.12 TIM autoreload register (TIM_ARR)

Address offset: 0x2C

Reset value: 0x0000 FFFF

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ARR[19:16]
rwrwrwrw
1514131211109876543210
ARR[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:20 Reserved, must be kept at reset value.

Bits 19:0 ARR[19:0]: Auto-reload value

ARR is the value to be loaded in the actual auto-reload register.

Refer to the Section 35.5.3: Time-base unit on page 1341 for more details about ARR update and behavior.

The counter is blocked while the auto-reload value is null.

Non-dithering mode (DITHEN = 0)

The register holds the auto-reload value in ARR[15:0]. The ARR[19:16] bits are reset.

Dithering mode (DITHEN = 1)

The register holds the integer part in ARR[19:4]. The ARR[3:0] bitfield contains the dithered part.

35.8.13 TIM repetition counter register (TIM_RCR)

Address offset: 0x30

Reset value: 0x0000

1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.REP[7:0]
rwrwrwrwrwrwrwrw

Bits 15:8 Reserved, must be kept at reset value.

Bits 7:0 REP[7: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 reptition 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:

35.8.14 TIM capture/compare register 1 (TIM_CCR1)

Address offset: 0x34

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CCR1[19:16]
rwrwrwrw
1514131211109876543210
CCR1[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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.

35.8.15 TIM capture/compare register 2 (TIM_CCR2)

Address offset: 0x38

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CCR2[19:16]
rwrwrwrw
1514131211109876543210
CCR2[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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 signalled 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 1 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.

35.8.16 TIM break and dead-time register (TIM_BDTR)

Address offset: 0x44

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.BKBIDRes.BKDSRMRes.Res.Res.Res.Res.Res.BKF[3:0]
rwrwrwrwrwrw
1514131211109876543210
MOEAOEBKPBKEOSSROSSILOCK[1:0]DTG[7:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Note: As the BKBID, BKDSRM, BKF[3:0], AOE, BKP, BKE, OSSI, OSSR, and DTG[7:0] bits may be write-locked depending on the LOCK configuration, it may be necessary to configure all of them during the first write access to the TIM_BDTR register.

Bits 31:29 Reserved, must be kept at reset value.

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).

Any write operation to this bit takes a delay of 1 APB clock cycle to become effective.

Bit 27 Reserved, must be kept at reset value.

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

Bits 25:20 Reserved, must be kept at reset value.

Bits 19:16 BKF[3:0]: Break filter

This bitfield defines the frequency used to sample the tim_brk input signal and the length of the digital filter applied to tim_brk. The digital filter is made of an event counter in which N events are needed to validate a transition on the output:

0000: No filter, tim_brk acts asynchronously

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

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 the tim_brk input is active. 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: tim_ocx and tim_ocxn outputs are disabled or forced to idle state depending on the OSSI bit.

1: tim_ocx and tim_ocxn outputs are enabled if their respective enable bits are set (CCxE, CCxNE in TIM_CCER register)

See tim_ocx/tim_ocxn enable description for more details (Section 35.8.9: TIM capture/compare enable register (TIM_CCER) on page 1429).

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 the break input is not be 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 when LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register) and when BKE bit is set.

Any write operation to this bit takes a delay of 1 APB clock cycle to become effective.

Bit 12 BKE: Break enable

0: Break inputs (tim_brk and tim_sys_brk clock failure event) disabled

1: Break inputs (tim_brk and tim_sys_brk clock failure event) enabled

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 APB clock cycle to become effective.

Bit 11 OSSR: Off-state selection for Run mode

This bit is used when MOE = 1 on channels that have a complementary output which are configured as outputs. OSSR is not implemented if no complementary output is implemented in the timer.

See tim_ocx/tim_ocxn enable description for more details (Section 35.8.9: TIM capture/compare enable register (TIM_CCER) on page 1429).

0: When inactive, tim_ocx/tim_ocxn outputs are disabled (the timer releases the output control which is taken over by the GPIO, which forces a Hi-Z state)

1: When inactive, tim_ocx/tim_ocxn 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 on channels configured as outputs.

See tim_ocx/tim_ocxn enable description for more details (Section 35.8.9: TIM capture/compare enable register (TIM_CCER) on page 1429).

0: When inactive, tim_ocx/tim_ocxn outputs are disabled (tim_ocx/tim_ocxn enable output signal = 0)

1: When inactive, tim_ocx/tim_ocxn outputs are forced first with their idle level as soon as CCxE = 1 or CCxNE = 1. tim_ocx/tim_ocxn enable output signal = 1)

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/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).

35.8.17 TIM timer deadtime register 2 (TIM_DTR2)

Address offset: 0x054

Reset value: 0x0000 0000

column_1column_2Bits 9:8 Bits 7:0LOCK[1:0] DTG[7:0]DTG[7:5] = 0xx DTG[7:5] = 10x DTG[7:5] = 110 DTG[7:5] = 111→ → → →column_7column_8column_9column_10column_11column_12column_13column_14column_15RM0522
31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DTPE DTAE rw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.DTGF[7:0]
rwrwrwrwrwrwrwrw
Bit 17DTPE : Deadtime preload enable

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).

35.8.18 TIM input selection register (TIM_TISEL)

Address offset: 0x5C

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.TI2SEL[3:0]Res.Res.Res.Res.TI1SEL[3:0]
rwrwrwrwrwrwrwrw

Bits 31:12 Reserved, must be kept at reset value.

Bits 11:8 TI2SEL[3:0]: selects tim_ti2_in[15:0] input

0000: TIM15_CH2 input (tim_ti2_in0)

0001: tim_ti2_in1

...

1111: tim_ti2_in15

Refer to Section 35.5.2: TIM15/TIM16/TIM17 pins and internalsignals for interconnects list.

Bits 7:4 Reserved, must be kept at reset value.

Bits 3:0 TI1SEL[3:0]: selects tim_ti1_in[15:0] input

0000: TIM15_CH1 input (tim_ti1_in0)

0001: tim_ti1_in1

...

1111: tim_ti1_in15

Refer to Section 35.5.2: TIM15/TIM16/TIM17 pins and internalsignals for interconnects list.

35.8.19 TIM alternate function register 1 (TIM_AF1)

Address offset: 0x060

Reset value: 0x0000 0001

31302928272625242322212019181716
BKCM P20EBKCM P19EBKCM P18EBKCM P17EBKCM P16EBKCM P15EBKCM P14EBKCM P13EBKCM P12EBKCM P11EBKCM P10EBKCM P9ERes.Res.Res.Res.
rwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
Res.Res.BKCM P4PBKCM P3PBKCM P2PBKCM P1PBKINPBKCM P8EBKCM P7EBKCM P6EBKCM P5EBKCM P4EBKCM P3EBKCM P2EBKCM P1EBKINE
rwrwrwrwrwrwrwrwrwrwrwrwrwrw

Refer to Section 35.5.2: TIM15/TIM16/TIM17 pins and internal signals for product specific implementation.

Bit 31 BKCM P20E: 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 BKCM P19E: 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 BKCM P18E: 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 BKCM P17E: 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 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).

Bits 19:14 Reserved, must be kept at reset value.

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 is active high

1: tim_brk_cmp4 input is active low

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 is active high

1: tim_brk_cmp3 input is active low

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 is active high

1: tim_brk_cmp2 input is active low

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 is active high

1: tim_brk_cmp1 input is active low

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: TIMx_BKIN input polarity

This bit selects the TIMx_BKIN alternate function input sensitivity. It must be programmed together with the BKP polarity bit.

0: TIMx_BKIN input is active high

1: TIMx_BKIN input is active low

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: TIMx_BKIN input enable

This bit enables the TIMx_BKIN alternate function input for the timer's tim_brk input. TIMx_BKIN input is 'ORed' with the other tim_brk sources.

0: TIMx_BKIN input disabled

1: TIMx_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).

35.8.20 TIM alternate function register 2 (TIM_AF2)

Address offset: 0x064

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OCRSEL[3:0]
rwrwrwrw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.

Bits 31:20 Reserved, must be kept at reset value.

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 35.5.2: TIM15/TIM16/TIM17 pins and internalsignals 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).

Bits 15:0 Reserved, must be kept at reset value.

35.8.21 TIM multilevel protection register 1 (TIM_MPR1)

Address offset: 0x090

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.BK2M[1:0]BK1NM[1:0]BK1M[1:0]
rwrwrwrwrwrw

Bits 31:6 Reserved, must be kept at reset value.

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).

35.8.22 TIM multilevel protection register 2 (TIM_MPR2)

Address offset: 0x094

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.DBK2[7:0]
rwrwrwrwrwrwrwrw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.DBK1[7:0]
rwrwrwrwrwrwrwrw
ST logo
ST logo

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 Tdtg selection, which are not preloaded.

It is thus recommended to update only the least significant bits to have the expected duration value:

DBK2[7:5]=0xx => Delay2=DBK2[7:0]×tDTG with tDTG=tDTS.

DBK2[7:5]=10x => Delay2=(64+DBK2[5:0])×tDTG with tDTG=2tDTS.

DBK2[7:5]=110 => Delay2=(32+DBK2[4:0])×tDTG with tDTG=8tDTS.

DBK2[7:5]=111 => Delay2=(32+DBK2[4:0])×tDTG with tDTG=16tDTS.

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 Tdtg selection, which are not preloaded.

It is thus recommended to update only the least significant bits to have the expected duration value:

DBK1[7:5]=0xx => Delay1=DBK1[7:0]×tDTG with tDTG=tDTS.

DBK1[7:5]=10x => Delay1=(64+DBK1[5:0])×tDTG with tDTG=2tDTS.

DBK1[7:5]=110 => Delay1=(32+DBK1[4:0])×tDTG with tDTG=8tDTS.

DBK1[7:5]=111 => Delay1=(32+DBK1[4:0])×tDTG with tDTG=16tDTS.

Note: This bit can not be modified as long as LOCK level 2 or 3 has been programmed (LOCK bits in TIM_BDTR register).

35.8.23 TIM output override register (TIM_OOR)

Address offset: 0x0A0

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.OOCRes.Res.Res.Res.Res.Res.Res.Res.Res.OOS2OOS1NOOS1
rwrwrwrw

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:3 Reserved, must be kept at reset value.

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).

35.8.24 TIM DMA control register (TIM_DCR)

Address offset: 0x3DC

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DBSS[3:0]
rwrwrwrw
1514131211109876543210
Res.Res.Res.DBL[4:0]Res.Res.Res.DBA[4:0]
rwrwrwrwrwrwrwrwrwrw

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).

Bits 15:13 Reserved, must be kept at reset value.

Bits 12:8 DBL[4:0]: DMA burst length

This 5-bitfield 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).

Bits 7:5 Reserved, must be kept at reset value.

Bits 4:0 DBA[4:0]: DMA base address

This 5-bitfield 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:

35.8.25 TIM DMA address for full transfer (TIM_DMAR)

Address offset: 0x3E0

Reset value: 0x0000 0000

31302928272625242322212019181716
DMAB[31:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
DMAB[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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).

35.8.26 TIM15 register map

TIM15 registers are mapped as 16-bit addressable registers as described in the table below:

Table 363. TIM15 register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x00TIM_CR1Res.Res.Res.Res.CKD2[3:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.UIFREMARes.CKD [1:0]ARPECMS [1:0]DIROPMURSUDISCEN
Reset value000000000000000
0x04TIM_CR2Res.Res.Res.ADSYNCRes.Res.MMS[3]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OIS2OIS1NOIS1TI1SMMS[2:0]CCDSCCUSRes.CCPC
Reset value000000000000
0x08TIM_SMCRRes.Res.Res.Res.Res.Res.Res.SMSPERes.Res.TS [4:3]Res.Res.SMS[4:3]Res.Res.Res.Res.Res.Res.Res.Res.MSMTS[2:0]Res.SMS[2:0]
Reset value000000000000
0x0CTIM_DIERRes.Res.Res.Res.Res.Res.Res.Res.Res.TERRIEDIRIERes.Res.Res.Res.Res.Res.TDECOMDERes.Res.Res.CC2DECC1DEUDEBIETIECOMIERes.CC2IECC1IEUIE
Reset value0000000000000
0x10TIM_SRRes.Res.TI2FSTI1FSRes.Res.Res.UIOVRFTERRFRes.DIRFRes.Res.Res.Res.Res.Res.BGFSBIFRes.Res.CC2OFCC1OFRes.BIFTIFCOMIFRes.CC2IFCC1IFUIFRes.
Reset value000000000000000
0x14TIM_EGRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.BGTGCOMGRes.CC2GCC1GUG
Reset value000000
0x18TIM_CCMR1
Input Capture mode
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.IC2F[3:0]IC2 PSC [1:0]CC2S [1:0]IC1F[3:0]IC1 PSC [1:0]CC1S [1:0]
Reset value0000000000000000
TIM_CCMR1
Output Compare mode
Res.Res.Res.Res.Res.Res.OC2M[4:3]Res.Res.Res.Res.Res.Res.OC1M[4:3]OC2CEOC2M [2:0]OC2PEOC2FECC2S [1:0]OC1CEOC1M [2:0]OC1PEOC1FECC1S [1:0]
Reset value00000000000000000000

Table 363. TIM15 register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x20TIM_CCERResResResResResResResResResResResResResResResResResResResResResResResResCC2NPResCC2PCC2ECC1NPCC1NECC1PCC1E
Reset value0000000
0x24TIM_CNTUIFCPY or Res.CNT[15:0]
Reset value00000000000000000
0x28TIM_PSCResResResResResResResResResResResResResResResResPSC[15:0]
Reset value0000000000000000
0x2CTIM_ARRResResResResResResResResResResResResResARR[19:0]
Reset value000011111111111111
0x30TIM_RCRResResResResResResResResResResResResResResResResREP[7:0]
Reset value000000000000000
0x34TIM_CCR1ResResResResResResResResResResResResResCCR1[19:0]
Reset value000000000000000000
0x38TIM_CCR2ResResResResResResResResResResResResResCCR2[19:0]
Reset value000000000000000000
0x38 - 0x40ReservedRes.
0x44TIM_BDTRResResResBKBIDBKDSRMResResResResResResResBKF[3:0]MOEAOEBKPBKEOSSROSSILOCK [1:0]DT[7:0]
Reset value000000000000000000000
0x48 - 0x50ReservedRes.
0x54TIM_DTR2ResResResResResResResResResResResResResResDTPEDTAEResResResResResResResResDTGF[7:0]
Reset value0000000000
0x58ReservedRes.
0x5CTIM_TISELResResResResResResResResResResResResResResResResResResTI2SEL[3:0]ResResResResTI1SEL[3:0]
Reset value00000000
0x60TIM_AF1BKCMp20EBKCMp19EBKCMp18EBKCMp17EBKCMp16EBKCMp15EBKCMp14EBKCMp13EBKCMp12EBKCMp11EBKCMp10EBKCMp9EResResResResResResBKCMp4PBKCMp3PBKCMp2PBKCMp1PBKINPBKCMp8EBKCMp7EBKCMp6EBKCMp5EBKCMp4EBKCMp3EBKCMp2EBKCMp1E
Reset value00000000000000000000000001

Table 363. TIM15 register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x64TIM_AFR2Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OCR_SEL[3:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value0000
0x68 - 0x08CReservedRes.
0x090TIM_MPR1Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.BK2M[1:0]BK1NM[1:0]BK1M[1:0]
Reset value000000
0x094TIM_MPR2Res.Res.Res.Res.Res.Res.Res.Res.DBK2[7:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.DBK1[7:0]
Reset value0000000000000000
0x98 - 0x09CReservedRes.
0x0A0TIM_OORRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OOCRes.Res.Res.Res.Res.Res.Res.Res.Res.OOS2OOS1NOOS1
Reset value0000
0xA4 - 0x3D8ReservedRes.
0x3DCTIM_DCRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DBSS[3:0]Res.Res.Res.Res.DBL[4:0]Res.Res.Res.Res.DBA[4:0]
Reset value0000000000000
0x3E0TIM_DMARDMAB[31:0]
Reset value00000000000000000000000000000000

Refer to Section 2.2: Memory organization for the register boundary addresses.

35.9 TIM16/TIM17 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).

35.9.1 TIM control register 1 (TIM_CR1)

Address offset: 0x00

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.CKD2[3:0]Res.Res.Res.Res.Res.Res.Res.Res.
rwrwrwrw
1514131211109876543210
Res.Res.Res.DITHE
N
UIFRE
MAP
Res.CKD[1:0]ARPECMS[1:0]DIROPMURSUDISCEN
rwrwrwrwrwrwrwrwrwrwrwrw

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:13 Reserved, must be kept at reset value.

Bit 12 DITHE: Dithering enable

0: Dithering disabled

1: Dithering enabled

Note: The DITHE 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 (\(t_{\text{tim\_ker\_ck}}\)) frequency and the dead-time and sampling clock (\(t_{\text{DTS}}\)) used by the dead-time generators and the digital filters (\(t_{\text{tim\_tix}}\)),

Bit 7 ARPE: Auto-reload preload enable

Bits 6:5 CMS[1:0]: Center-aligned mode selection

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

Note: This bit is read only when the timer is configured in Center-aligned mode or Encoder mode.

Bit 3 OPM: One pulse mode

Bit 2 URS: Update request source

This bit is set and cleared by software to select the UEV event sources.

These events can be:

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:

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 and gated 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.

35.9.2 TIM control register 2 (TIM_CR2)

Address offset: 0x04

Reset value: 0x0000

1514131211109876543210
Res.Res.Res.Res.Res.Res.OIS1NOIS1Res.Res.Res.Res.CCDSCCUSRes.CCPC
rwrwrwrwrw

Bits 15:10 Reserved, must be kept at reset value.

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_BKR 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_BKR register).

Bits 7:4 Reserved, must be kept at reset value.

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 a rising edge occurs on tim_trgi (if available).

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 and OCxM bits are not preloaded

1: CCxE, CCxNE and OCxM bits are preloaded, after having been written, they are updated only when COM bit is set.

Note: This bit acts only on channels that have a complementary output.

35.9.3 TIM DMA/interrupt enable register (TIM_DIER)

Address offset: 0x0C

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DIRIERes.Res.Res.Res.Res.
rw
1514131211109876543210
Res.Res.Res.Res.Res.Res.CC1DEUDEBIERes.COMIERes.Res.Res.CC1IEUIE
rwrwrwrwrwrw

Bits 31:22 Reserved, must be kept at reset value.

Bit 21 DIRIE: Direction change interrupt enable

0: Direction change interrupt disabled

1: Direction change interrupt enabled

Bits 20:10 Reserved, must be kept at reset value.

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 Reserved, must be kept at reset value.

Bit 5 COMIE: COM interrupt enable

0: COM interrupt disabled

1: COM interrupt enabled

Bits 4:2 Reserved, must be kept at reset value.

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

35.9.4 TIM status register (TIM_SR)

Address offset: 0x10

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.TI1FSRes.Res.Res.UIOVRFRes.Res.Res.Res.Res.Res.Res.Res.
rrc_w0
1514131211109876543210
Res.BGFSBIFRes.Res.Res.CC1OFRes.BIFRes.COMIFRes.Res.Res.CC1IFUIF
rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0

Bits 31:29 Reserved, must be kept at reset value.

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:25 Reserved, must be kept at reset value.

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

Bits 23:15 Reserved, must be kept at reset value.

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.

Bits 12:10 Reserved, must be kept at reset value.

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 Reserved, must be kept at reset value.

Bit 7 BIF: Break interrupt flag

This flag is set by hardware as soon as the tim_brk 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

Bit 6 Reserved, must be kept at reset value.

Bit 5 COMIF: COM interrupt flag

This flag is set by hardware on a COM event (once the capture/compare control bits –CCxE, CCxNE, OCxM– have been updated). It is cleared by software.

0: No COM event occurred

1: COM interrupt pending

Bits 4:2 Reserved, must be kept at reset value.

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 down-counting 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:

35.9.5 TIM event generation register (TIM_EGR)

Address offset: 0x14

Reset value: 0x0000

1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.BGRes.COMGRes.Res.Res.CC1GUG
wwww

Bits 15:8 Reserved, must be kept at reset value.

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 Reserved, must be kept at reset value.

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: When the CCPC bit is set, it is possible to update the CCxE, CCxNE and OCxM bits

Note: This bit acts only on channels that have a complementary output.

Bits 4:2 Reserved, must be kept at reset value.

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).

35.9.6 TIM capture/compare mode register 1 (TIM_CCMR1)

Address offset: 0x18

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).

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.IC1F[3:0]IC1PSC[1:0]CC1S[1:0]
rwrwrwrwrwrwrwrw

Input capture mode

Bits 31:8 Reserved, must be kept at reset value.

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_{DTS}\)

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_{DTS}/2\), N =

0101: \(f_{SAMPLING} = f_{DTS}/2\), N = 8

0110: \(f_{SAMPLING} = f_{DTS}/4\), N = 6

0111: \(f_{SAMPLING} = f_{DTS}/4\), N = 8

1000: \(f_{SAMPLING} = f_{DTS}/8\), N = 6

1001: \(f_{SAMPLING} = f_{DTS}/8\), N = 8

1010: \(f_{SAMPLING} = f_{DTS}/16\), N = 5

1011: \(f_{SAMPLING} = f_{DTS}/16\), N = 6

1100: \(f_{SAMPLING} = f_{DTS}/16\), N = 8

1101: \(f_{SAMPLING} = f_{DTS}/32\), N = 5

1110: \(f_{SAMPLING} = f_{DTS}/32\), N = 6

1111: \(f_{SAMPLING} = f_{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

Others: Reserved

Note: CC1S bits are writable only when the channel is OFF (CC1E = 0 in TIM_CCER).

35.9.7 TIM capture/compare mode register 1 [alternate] (TIM_CCMR1)

Address offset: 0x18

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).

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OC1M[4:3]
rwrw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.OC1CEOC1M[2:0]OC1PEOC1FECC1S[1:0]
rwrwrwrwrwrwrwrw

Output compare mode:

Bits 31:18 Reserved, must be kept at reset value.

Bits 15:8 Reserved, must be kept at reset value.

Bit 7 OC1CE: Output Compare 1 clear enable

0: tim_oc1ref is not affected by the tim_ocref_clr input.

1: tim_oc1ref is cleared as soon as a High level is detected on tim_ocref_clr input.

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 - Channel 1 is active as long as TIM_CNT < TIM_CCR1 else inactive.

00111: PWM mode 2 - Channel 1 is inactive as long as TIM_CNT < TIM_CCR1 else active.

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).

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.

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, tim_ocx is set to the compare level independently of the result of the comparison. Delay to sample the trigger input and to activate CC1 output is reduced to 3 clock cycles.
OC1FE 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

Others: Reserved

Note: CC1S bits are writable only when the channel is OFF (CC1E = 0 in TIM_CCER).

35.9.8 TIM capture/compare enable register (TIM_CCER)

Address offset: 0x20

Reset value: 0x0000

1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CC1NPCC1NECC1PCC1E
rwrwrwrw

Bits 15:4 Reserved, must be kept at reset value.

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. Refer to the description of CC1P.

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 (the channel is configured in output).

On channels that have 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.

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.

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: this 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).

On channels that have 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.

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 364 for details.

Table 364. Output control bits for complementary tim_oc1 and tim_oc1n channels with break feature (TIM16/TIM17)
Control bitsOutput states(1)
MOE bitOSSI bitOSSR bitCC1E bitCC1NE bittim_oc1 output statetim_oc1n output state
1XX00Output Disabled (not driven by the timer: Hi-Z)
tim_oc1 = 0
tim_oc1n = 0
001Output Disabled (not driven by the timer: Hi-Z)
tim_oc1 = 0
tim_oc1ref + Polarity
tim_oc1n = tim_oc1ref XOR CC1NP
010tim_oc1ref + Polarity
tim_oc1 = tim_oc1ref XOR CC1P
Output Disabled (not driven by the timer: Hi-Z)
tim_oc1n = 0
X11tim_oc1ref + Polarity + dead-timeComplementary to tim_oc1ref (not tim_oc1ref) + Polarity + dead-time
101Off-State (output enabled with inactive state)
tim_oc1 = CC1P
tim_oc1ref + Polarity
tim_oc1n = tim_oc1ref XOR CC1NP
110tim_oc1ref + Polarity
tim_oc1 = tim_oc1ref XOR CC1P
Off-State (output enabled with inactive state)
tim_oc1n = CC1NP
00XXXOutput disabled (not driven by the timer: Hi-Z)
100
01Off-State (output enabled with inactive state)
10Asynchronously: tim_oc1 = CC1P, tim_oc1n = CC1NP
11Then if the clock is present: tim_oc1 = OIS1 and tim_oc1n = OIS1N after a dead-time, assuming that OIS1 and OIS1N do not correspond to tim_oc1 and tim_oc1n both in active state

Note: The state of the external I/O pins connected to the complementary tim_oc1 and tim_oc1n channels depends on the tim_oc1 and tim_oc1n channel state and GPIO control and alternate function selection registers.

35.9.9 TIM counter (TIM_CNT)

Address offset: 0x24

Reset value: 0x0000 0000

31302928272625242322212019181716
UIFCPYRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
r
1514131211109876543210
CNT[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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 TIM_CR1 is reset, bit 31 is reserved.

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.

35.9.10 TIM prescaler (TIM_PSC)

Address offset: 0x28

Reset value: 0x0000

1514131211109876543210
PSC[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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”).

35.9.11 TIM auto-reautoreload register (TIM_ARR)

Address offset: 0x2C

Reset value: 0x0000 FFFF

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ARR[19:16]
rwrwrwrw
1514131211109876543210
ARR[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:20 Reserved, must be kept at reset value.

Bits 19:0 ARR[19:0]: Auto-reload value

ARR is the value to be loaded in the actual auto-reload register.

Refer to the Section 35.5.3: Time-base unit on page 1341 for more details about ARR update and behavior.

The counter is blocked while the auto-reload value is null.

Non-dithering mode (DITHEN = 0)

The register holds the auto-reload value in ARR[15:0]. The ARR[19:16] bits are reset.

Dithering mode (DITHEN = 1)

The register holds the integer part in ARR[19:4]. The ARR[3:0] bitfield contains the dithered part.

35.9.12 TIM repetition counter register (TIM_RCR)

Address offset: 0x30

Reset value: 0x0000

1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.REP[7:0]
rwrwrwrwrwrwrwrw

Bits 15:8 Reserved, must be kept at reset value.

Bits 7:0 REP[7: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:

35.9.13 TIM capture/compare register 1 (TIM_CCR1)

Address offset: 0x34

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CCR1[19:16]
rwrwrwrw
1514131211109876543210
CCR1[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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:

CCR1 is the counter value transferred by the last input capture 1 event (tim_ic1).

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.

ST logo
ST logo

35.9.14 TIM break and dead-time register (TIM_BDTR)

Address offset: 0x44

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.BKBIDRes.BKDSRMRes.Res.Res.Res.Res.Res.BKF[3:0]
rwrwrwrwrwrw
1514131211109876543210
MOEAOEBKPBKEOSSROSSILOCK[1:0]DTG[7:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Note: As the BKBID, BKDSRM, BKF[3:0], AOE, BKP, BKE, OSSI, OSSR, and DTG[7:0] bits may be write-locked depending on the LOCK configuration, it may be necessary to configure all of them during the first write access to the TIM_BDTR register.

Bits 31:29 Reserved, must be kept at reset value.

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).

Any write operation to this bit takes a delay of 1 APB clock cycle to become effective.

Bit 27 Reserved, must be kept at reset value.

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.

Bits 25:20 Reserved, must be kept at reset value.

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 events are needed to validate a transition on the output:

0000: No filter, tim_brk acts asynchronously

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

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 the tim_brk input is active. 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: tim_oc1 and tim_oc1n outputs are disabled or forced to idle state depending on the OSSI bit.

1: tim_oc1 and tim_oc1n outputs are enabled if their respective enable bits are set (CC1E, CC1NE in TIM_CCER register)

See tim_oc1/tim_oc1n enable description for more details (Section 35.9.8: TIM capture/compare enable register (TIM_CCER) on page 1461).

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 the tim_brk input is not 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.

Any write operation to this bit takes a delay of 1 APB clock cycle to become effective.

Bit 12 BKE: Break enable

0: Break inputs (tim_brk and tim_sys_brk event) disabled

1: Break inputs (tim_brk and tim_sys_brk event) enabled

Note: This bit cannot be modified when LOCK level 1 has been programmed (LOCK bits in TIM_BDTR register).

Any write operation to this bit takes a delay of 1 APB clock cycle to become effective.

Bit 11 OSSR: Off-state selection for Run mode

This bit is used when MOE = 1 on channels that have a complementary output which are configured as outputs. OSSR is not implemented if no complementary output is implemented in the timer.

See tim_oc1/tim_oc1n enable description for more details (Section 35.9.8: TIM capture/compare enable register (TIM_CCER) on page 1461).

0: When inactive, tim_oc1/tim_oc1n outputs are disabled (the timer releases the output control which is taken over by the GPIO, which forces a Hi-Z state)

1: When inactive, tim_oc1/tim_oc1n outputs are enabled with their inactive level as soon as CC1E = 1 or CC1NE = 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 on channels configured as outputs.

See tim_oc1/tim_oc1n enable description for more details (Section 35.9.8: TIM capture/compare enable register (TIM_CCER) on page 1461).

0: When inactive, tim_oc1/tim_oc1n outputs are disabled (tim_oc1/tim_oc1n enable output signal = 0)

1: When inactive, tim_oc1/tim_oc1n outputs are forced first with their idle level as soon as CC1E = 1 or CC1NE = 1. tim_oc1/tim_oc1n enable output signal = 1)

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/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).

35.9.15 TIM timer deadtime register 2 (TIM_DTR2)

Address offset: 0x054

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DTPEDTAE
rwrw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.DTGF[7:0]
rwrwrwrwrwrwrwrw

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).

35.9.16 TIM input selection register (TIM_TISEL)

Address offset: 0x5C

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.TI1SEL[3:0]
rwrwrwrw

Bits 31:4 Reserved, must be kept at reset value.

Bits 3:0 TI1SEL[3:0]: selects tim_ti1_in[15:0] input

0000: TIMx_CH1 input (tim_ti1_in0)

0001: tim_ti1_in1

...

1111: tim_ti1_in15

Refer to Section 35.5.2: TIM15/TIM16/TIM17 pins and internalsignals for interconnects list.

35.9.17 TIM alternate function register 1 (TIM_AF1)

Address offset: 0x060

Reset value: 0x0000 0001

31302928272625242322212019181716
BKCM P20EBKCM P19EBKCM P18EBKCM P17EBKCM P16EBKCM P15EBKCM P14EBKCM P13EBKCM P12EBKCM P11EBKCM P10EBKCM P9ERes.Res.Res.Res.
rwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
Res.Res.BKCM P4PBKCM P3PBKCM P2PBKCM P1PBKINPBKCM P8EBKCM P7EBKCM P6EBKCM P5EBKCM P4EBKCM P3EBKCM P2EBKCM P1EBKINE
rwrwrwrwrwrwrwrwrwrwrwrwrwrw

Refer to Section 35.5.2: TIM15/TIM16/TIM17 pins and internalsignals for product specific implementation.

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 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: TIMx_BKIN input enable

This bit enables the TIMx_BKIN alternate function input for the timer's tim_brk input. TIMx_BKIN input is 'ORed' with the other tim_brk sources.

0: TIMx_BKIN input disabled

1: TIMx_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).

35.9.18 TIM alternate function register 2 (TIM_AF2)

Address offset: 0x064

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OCRSEL[3:0]
rwrwrwrw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.

Bits 31:20 Reserved, must be kept at reset value.

Bits 19:16 OCRSEL[3:0]: tim_ocref_clr source selection
These bits select the tim_ocref_clr input source.
0000: tim_ocref_clr0
0001: tim_ocref_clr1
...
1111: tim_ocref_clr15
Refer to Section 35.5.2: TIM15/TIM16/TIM17 pins and internalsignals 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).

Bits 15:0 Reserved, must be kept at reset value.

35.9.19 TIM multilevel protection register 1 (TIM_MPR1)

Address offset: 0x090
Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.BK1NM[1:0]BK1M[1:0]
rwrwrwrw

Bits 31:4 Reserved, must be kept at reset value.

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).

ST logo
ST logo

35.9.20 TIM multilevel protection register 2 (TIM_MPR2)

Address offset: 0x094

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.DBK2[7:0]
rwrwrwrwrwrwrwrw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.DBK1[7:0]
rwrwrwrwrwrwrwrw

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 preloaded and can be updated during timer operation (new value taken into account after an update event).

DBK2[7:5]=0xx => Delay2=DBK2[7:0]xtDTG with tDTG=tDTS.

DBK2[7:5]=10x => Delay2=(64+DBK2[5:0])xtDTG with tDTG=2xtDTS.

DBK2[7:5]=110 => Delay2=(32+DBK2[4:0])xtDTG with tDTG=8xtDTS.

DBK2[7:5]=111 => Delay2=(32+DBK2[4:0])xtDTG with tDTG=16xtDTS.

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 preloaded and can be updated during timer operation (new value taken into account after an update event).

DBK2[7:5]=0xx => Delay1=DBK2[7:0]xtDTG with tDTG=tDTS.

DBK2[7:5]=10x => Delay1=(64+DBK2[5:0])xtDTG with tDTG=2xtDTS.

DBK2[7:5]=110 => Delay1=(32+DBK2[4:0])xtDTG with tDTG=8xtDTS.

DBK2[7:5]=111 => Delay1=(32+DBK2[4:0])xtDTG with tDTG=16xtDTS.

Note: This bit can not be modified as long as LOCK level 2 or 3 has been programmed (LOCK bits in TIM_BDTR register).

35.9.21 TIM output override register (TIM_OOR)

Address offset: 0x0A0

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.OOCRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.OOS1NOOS1
rwrwrw

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:2 Reserved, must be kept at reset value.

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).

35.9.22 TIM DMA control register (TIM_DCR)

Address offset: 0x3DC

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DBSS[3:0]
rwrwrwrw
1514131211109876543210
Res.Res.Res.DBL[4:0]Res.Res.Res.DBA[4:0]
rwrwrwrwrwrwrwrwrwrw

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: Reserved

0001: Update

0010: CC1

Other: reserved

Bits 15:13 Reserved, must be kept at reset value.

Bits 12:8 DBL[4:0]: DMA burst length

This 5-bitfield 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. Transfers can be in half-words or in bytes (see example below).

00000: 1 transfer,

00001: 2 transfers,

00010: 3 transfers,

...

10001: 18 transfers.

Bits 7:5 Reserved, must be kept at reset value.

Bits 4:0 DBA[4:0]: DMA base address

This 5-bitfield 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,

...

Example: Let us consider the following transfer: DBL = 7 transfers and DBA = TIM_CR1. In this case the transfer is done to/from 7 registers starting from the TIM_CR1 address.

35.9.23 TIM DMA address for full transfer (TIM_DMAR)

Address offset: 0x3E0

Reset value: 0x0000 0000

31302928272625242322212019181716
DMAB[31:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
DMAB[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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
\((\text{TIM\_CR1 address}) + (\text{DBA} + \text{DMA index}) \times 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).

35.9.24 TIM16/TIM17 register map

TIM16/TIM17 registers are mapped as 16-bit addressable registers as described in the table below:

Table 365. TIM16/TIM17 register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x00TIM_CR1Res.Res.Res.Res.CKD2[3:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.UIFREMARes.CKD [1:0]ARPECMS [1:0]DIROPMURSUDISCEN
Reset value000000000000000
0x04TIM_CR2Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OIS1NOIS1Res.Res.Res.Res.CCDSCCUSRes.CCPC
Reset value00000
0x08ReservedRes.
0x0CTIM_DIERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.DIRIERes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CC1DEUDEBIERes.COMIERes.Res.Res.CC1IEUIE
Reset value0000000
0x10TIM_SRRes.Res.Res.TI1FSRes.Res.Res.UIOVRFRes.Res.Res.Res.Res.Res.Res.Res.Res.BGFSBIFRes.Res.Res.CC1OFRes.BIFRes.COMIFRes.Res.Res.CC1IFUIF
Reset value000000000
0x14TIM_EGRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.BGRes.COMGRes.Res.Res.CC1GUG
Reset value0000
0x18TIM_CCMR1
Input Capture mode
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.IC1F[3:0]IC1 PSC [1:0]CC1 S [1:0]
Reset value00000000
TIM_CCMR1
Output Compare mode
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OC1M[4:3]Res.Res.Res.Res.Res.Res.Res.Res.OC1CEOC1M [2:0]OC1PEOC1FECC1 S [1:0]
Reset value0000000000
0x1CReservedRes.
0x20TIM_CCERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CC1NPCC1NECC1PCC1E
Reset value0000
0x24TIM_CNTUIFCPY or Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CNT[15:0]
Reset value00000000000000000
0x28TIM_PSCRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.PSC[15:0]
Reset value0000000000000000

Table 365. TIM16/TIM17 register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x2CTIM_ARRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ARR[19:0]
Reset value00001111111111111111
0x30TIM_RCRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.REP[7:0]
Reset value00000000
0x34TIM_CCR1Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CCR1[19:0]
Reset value00000000000000000000
0x38 - 0x40ReservedRes.
0x44TIM_BDTRRes.Res.Res.BKBIDRes.BKDSRMRes.Res.Res.Res.Res.Res.BKF[3:0]MOEAOEBKPBKEOSSROSSILOCK [1:0]DT[7:0]
Reset value0000000000000000000000
0x48 - 0x50ReservedRes.
0x54TIM_DTR2Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DTPEDTAERes.Res.Res.Res.Res.Res.Res.Res.DTGF[7:0]
Reset value0000000000
0x58ReservedRes.
0x5CTIM_TISELRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.TI1SEL[3:0]
Reset value0000
0x60TIM_AF1BKCMP20EBKCMP19EBKCMP18EBKCMP17EBKCMP16EBKCMP15EBKCMP14EBKCMP13EBKCMP12EBKCMP11EBKCMP10EBKCMP9ERes.Res.Res.Res.Res.BKCMP4PBKCMP3PBKCMP2PBKCMP1PRes.BKINPBKCMP8EBKCMP7EBKCMP6EBKCMP5EBKCMP4EBKCMP3EBKCMP2EBKCMP1EBKINE
Reset value00000000000000000000000001
0x64TIM_AF2Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OCR SEL[3:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value0000
0x6C - 0x08CReservedRes.
0x090TIM_MPR1Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.BK1NM[1:0]BK1M[1:0]
Reset value0000
0x094TIM1x_MPR2Res.Res.Res.Res.Res.Res.Res.DBK2[7:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.DBK1[7:0]
Reset value0000000000000000
0x98 - 0x09CReservedRes.

Table 365. TIM16/TIM17 register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x0A0TIM_OORRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OOCRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.OOS1NOOS1
Reset value000
0xA4 - 0x3D8ReservedRes.
0x3DCTIM_DCRRes.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 value00000000000000
0x3E0TIM_DMARDMAB[31:0]
Reset value00000000000000000000000000000000

Refer to Section 2.2 for the register boundary addresses.

ST logo
ST logo