29. Advanced-control timers (TIM1)

In this section, “TIMx” should be understood as “TIM1” since there is only one instance of this type of timer for the products to which this reference manual applies.

29.1 TIM1 introduction

The advanced-control timer (TIM1) consists of a 16-bit autoreload counter driven by a programmable prescaler.

It may be used for a variety of purposes, including measuring the pulse lengths of input signals (input capture) or generating output waveforms (output compare, PWM, complementary PWM with dead-time insertion).

Pulse lengths and waveform periods can be modulated from a few microseconds to several milliseconds using the timer prescaler and the RCC clock controller prescalers.

The advanced-control (TIM1) and general-purpose (TIMy) timers are completely independent, and do not share any resources. They can be synchronized together as described in Section 29.3.30: Timer synchronization .

29.2 TIM1 main features

TIM1 timer features include:

29.3 TIM1 functional description

29.3.1 Block diagram

Figure 155. Advanced-control timer block diagram

Figure 155: Advanced-control timer block diagram. A complex schematic showing the internal architecture of the TIM1 timer. Key components include: Trigger controller, Slave controller mode, Encoder interface, IRQ interface, DMA interface, Clock prescaler (tim_psc_ck to tim_cnt_ck), Auto-reload register, Repetition counter, and six Capture/Compare channels. Channels 1-4 include input filters, edge detectors, prescalers, and output control (DTG) for complementary outputs (e.g., tim_oc1, tim_oc1n). Channels 5 and 6 are output-only. A Break and Break2 circuitry block handles safety inputs. The diagram shows signal routing from the 32-bit APB bus and external pins (TIM_CHx, TIM_ETR, TIM_BKIN) to internal registers and back to output pins. Notes define symbols for preload registers, events, and interrupt/DMA outputs.
Figure 155: Advanced-control timer block diagram. A complex schematic showing the internal architecture of the TIM1 timer. Key components include: Trigger controller, Slave controller mode, Encoder interface, IRQ interface, DMA interface, Clock prescaler (tim_psc_ck to tim_cnt_ck), Auto-reload register, Repetition counter, and six Capture/Compare channels. Channels 1-4 include input filters, edge detectors, prescalers, and output control (DTG) for complementary outputs (e.g., tim_oc1, tim_oc1n). Channels 5 and 6 are output-only. A Break and Break2 circuitry block handles safety inputs. The diagram shows signal routing from the 32-bit APB bus and external pins (TIM_CHx, TIM_ETR, TIM_BKIN) to internal registers and back to output pins. Notes define symbols for preload registers, events, and interrupt/DMA outputs.
  1. 1. This feature is not available on all timers, refer to Section 29.3.2: TIM1 pins and internal signals .
  2. 2. See Figure 202: Break and Break2 circuitry overview for details.

29.3.2 TIM1 pins and internal signals

The tables in this section summarize the TIM inputs and outputs

Table 253. TIM input/output pins

Pin nameSignal typeDescription
TIM_CH1
TIM_CH2
TIM_CH3
TIM_CH4
Input/outputTimer multi-purpose channels. Each channel can be used for capture, compare or PWM. TIM_CH1 and TIM_CH2 can also be used as external clock (below 1/4 of the tim_ker_ck clock), external trigger and quadrature encoder inputs. TIM_CH1, TIM_CH2 and TIM_CH3 can be used to interface with digital hall effect sensors.
TIM_CH1N
TIM_CH2N
TIM_CH3N
TIM_CH4N
OutputTimer complementary outputs, derived from TIM_CHx outputs with the possibility to have deadtime insertion.
TIM_ETRInputExternal trigger input. This input can be used as external trigger or as external clock source. This input can receive a clock with a frequency higher than the tim_ker_ck if the tim_etr_in prescaler is used.
TIM_BKIN
TIM_BKIN2
Input/outputBreak and Break2 inputs. These inputs can also be configured in bidirectional mode.

Table 254. TIM internal input/output signals

Internal signal nameSignal typeDescription
tim_ti1_in[15:0]
tim_ti2_in[15:0]
tim_ti3_in[15:0]
tim_ti4_in[15:0]
InputInternal timer inputs bus. The tim_ti1_in[15:0] and tim_ti2_in[15:0] inputs can be used for capture or as external clock (below 1/4 of the tim_ker_ck clock) and for quadrature encoder signals.
tim_etr[15:0]InputExternal trigger internal input bus. These inputs can be used as trigger, external clock or for hardware cycle-by-cycle pulsewidth control. These inputs can receive clock with a frequency higher than the tim_ker_ck if the tim_etr_in prescaler is used.
tim_itr[15: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_trgo/tim_trgo2OutputInternal trigger outputs. These triggers are used by other timers and /or other peripherals.

Table 254. TIM internal input/output signals (continued)

Internal signal nameSignal typeDescription
tim_ocref_clr[7:0]InputTimer tim_ocref_clr input bus. These inputs can be used to clear the tim_ocref signals, typically for hardware cycle-by-cycle pulsewidth control.
tim_brk_cmp[8:1]InputBreak input for internal signals
tim_brk2_cmp[8:1]InputBreak2 input for internal signals
tim_sys_brk[n:0]InputSystem break input. This input gathers the MCU's system level errors.
tim_pclkInputTimer APB clock
tim_ker_ckInputTimer kernel clock
tim_cc_itOutputTimer capture/compare interrupt
tim_upd_itOutputTimer update event interrupt
tim_brk_terrierr_itOutputTimer break, break2, transition error and index error interrupt
tim_trgi_com_dir_idx_itOutputTimer trigger, commutation, direction and index interrupt
tim_cc1_dma
tim_cc2_dma
tim_cc3_dma
tim_cc4_dma
OutputTimer capture / compare 1..4 dma requests
tim_upd_dmaOutputTimer update dma request
tim_trgi_dmaOutputTimer trigger dma request
tim_com_dmaOutputTimer commutation dma request

Table 255 , Table 256 , Table 257 and Table 258 list the sources connected to the tim_tif[4:1] input multiplexers.

Table 255. Interconnect to the tim_ti1 input multiplexer

tim_ti1 inputsSources
TIM1
tim_ti1_in0TIM1_CH1
tim_ti1_in1COMP1_OUT (1)
tim_ti1_in2COMP2_OUT (1)
tim_ti1_in[15:3]Reserved

1. Only available on STM32WBA54xx and STM32WBA55xx devices.

Table 256. Interconnect to the tim_ti2 input multiplexer

tim_ti2 inputsSources
TIM1
tim_ti2_in0TIM1_CH2
tim_ti2_in[15:1]Reserved

Table 257. Interconnect to the tim_ti3 input multiplexer

tim_ti3 inputsSources
TIM1
tim_ti3_in0TIM1_CH3
tim_ti3_in[15:1]Reserved

Table 258. Interconnect to the tim_ti4 input multiplexer

tim_ti4 inputsSources
TIM1
tim_ti4_in0TIM1_CH4
tim_ti4_in[15:1]Reserved

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

Table 259. Internal trigger connection

Timer internal trigger input signalTIM1
tim_itr0Reserved
tim_itr1tim2_trgo
tim_itr2tim3_trgo
Table 259. Internal trigger connection (continued)
Timer internal trigger input signalTIM1
tim_itr[6:3]Reserved
tim_itr7tim16_oc1
tim_itr8tim17_oc1
tim_itr[15:9]Reserved

Table 260 lists the internal sources connected to the tim_etr input multiplexer.

Table 260. Interconnect to the tim_etr input multiplexer
Timer external trigger input signalTimer external trigger signals assignment
TIM1
tim_etr0TIM1_ETR
tim_etr1COMP1_OUT (1)
tim_etr2COMP2_OUT (1)
tim_etr3Reserved
tim_etr4HSI16
tim_etr[10:5]Reserved
tim_etr11adc4_awd1
tim_etr12adc4_awd2
tim_etr13adc4_awd3
tim_etr[15:14]Reserved

1. Only available on STM32WBA54xx and STM32WBA55xx devices.

Table 261 , Table 262 and Table 263 list the sources connected to the tim_brk and tim_brk2inputs.

Table 261. Timer break interconnect
tim_brk inputsTIM1
TIM_BKINTIM1_BKIN pin
tim_brk_cmp1COMP1_OUT (1)
tim_brk_cmp2COMP2_OUT (1)
tim_brk_cmp[8:3]Reserved

1. Only available on STM32WBA54xx and STM32WBA55xx devices.

Table 262. Timer break2 interconnect

tim_brk2 inputsTIM1
TIM_BKIN2TIM1_BKIN2 pin
tim_brk2_cmp1COMP1_OUT (1)
tim_brk2_cmp2COMP2_OUT (1)
tim_brk2_cmp[8:3]Reserved

1. Only available on STM32WBA54xx and STM32WBA55xx devices.

Table 263. System break interconnect

tim_sys_brk inputsTIM1
tim_sys_brk0Cortex-M33 LOCKUP
tim_sys_brk1Programmable Voltage Detector (PVD)
tim_sys_brk2SRAM parity error
tim_sys_brk3Flash memory ECC error
tim_sys_brk4HSE32 lock Security System (HSECSS)

Table 264 lists the internal sources connected to the tim_ocref_clr input multiplexer.

Table 264. Interconnect to the ocref_clr input multiplexer

Timer OCREF clear signalTimer OCREF clear signals assignment
TIM1
tim_ocref_clr0COMP1_OUT (1)
tim_ocref_clr1COMP2_OUT (1)
tim_ocref_clr[7:2]Reserved

1. Only available on STM32WBA54xx and STM32WBA55xx devices.

29.3.3 Time-base unit

The main block of the programmable advanced-control timer is a 16-bit counter with its related autoreload register. The counter can count up, down or both up and down. The counter clock can be divided by a prescaler.

The counter, the autoreload register and the prescaler register can be written or read by software, even when the counter is running.

The time-base unit includes:

The autoreload register is preloaded. Writing to or reading from the autoreload register accesses the preload register. The content of the preload register are transferred into the

shadow register permanently or at each update event (UEV), depending on the autoreload preload enable bit (ARPE) in TIMx_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 TIMx_CR1 register. It can also be generated by software. The generation of the update event is described in detailed for each configuration.

The counter is clocked by the prescaler output tim_cnt_ck, which is enabled only when the counter enable bit (CEN) in TIMx_CR1 register is set (refer also to the slave mode controller description to get more details on counter enabling).

Note: The counter starts counting 1 clock cycle after setting the CEN bit in the TIMx_CR1 register.

Prescaler description

The prescaler divides the counter clock frequency by any factor from 1 to 65536. It is based on a 16-bit counter controlled through a 16-bit register (in the TIMx_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 156 and Figure 157 give some examples of the counter behavior when the prescaler ratio is changed on the fly.

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

Timing diagram showing the effect of changing the prescaler division from 1 to 2 on the counter behavior.

The timing diagram illustrates the relationship between several signals over time:

MSV50998V1

Timing diagram showing the effect of changing the prescaler division from 1 to 2 on the counter behavior.

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

Timing diagram showing the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Update event (UEV), Prescaler control register, Prescaler buffer, and Prescaler counter. It illustrates a change in prescaler division from 1 to 4.

The timing diagram shows the following signals and registers over time:

The diagram illustrates that when the prescaler control register is updated, the new value is latched into the prescaler buffer, which then changes the frequency of the tim_cnt_ck signal. The counter register continues to count, but the rate of counting changes due to the new prescaler division.

Timing diagram showing the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Update event (UEV), Prescaler control register, Prescaler buffer, and Prescaler counter. It illustrates a change in prescaler division from 1 to 4.

29.3.4 Counter modes

Upcounting mode

In upcounting mode, the counter counts from 0 to the autoreload value (content of the TIMx_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 (TIMx_RCR) + 1. Else the update event is generated at each counter overflow.

Setting the UG bit in the TIMx_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 TIMx_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 TIMx_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 TIMx_SR register) is set (depending on the URS bit):

The following figures show some examples of the counter behavior for different clock frequencies when TIMx_ARR = 0x36.

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

Timing diagram for a counter showing the relationship between prescaler clock, counter clock, counter register values, overflow, update event, and update interrupt flag.

The timing diagram illustrates the operation of a counter. The top signal, tim_psc_ck , is a periodic square wave representing the prescaler clock. Below it, CEN (Counter Enable) is shown as a signal that goes high to enable the counter. The tim_cnt_ck signal is the counter clock, which is a square wave with a frequency twice that of the prescaler clock. The Counter register shows a sequence of values: 31, 32, 33, 34, 35, 36, 00, 01, 02, 03, 04, 05, 06, 07. The Counter overflow signal is a pulse that goes high when the counter reaches the value 36. The Update event (UEV) signal is a pulse that goes high when the counter reaches the value 36. The Update interrupt flag (UIF) signal is a pulse that goes high when the counter reaches the value 36. Vertical dashed lines indicate the timing relationships between the signals.

MSv50997V1

Timing diagram for a counter showing the relationship between prescaler clock, counter clock, counter register values, overflow, update event, and update interrupt flag.

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

Timing diagram for internal clock divided by 2. It shows the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register values (0034, 0035, 0036, 0000, 0001, 0002, 0003), Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

This timing diagram illustrates the operation of a counter with an internal clock divided by 2. The top signal, tim_psc_ck , is a high-frequency square wave. The CEN (Counter Enable) signal is shown as a horizontal line that goes high at the second rising edge of tim_psc_ck . The tim_cnt_ck signal is a square wave with a frequency half that of tim_psc_ck , with its rising edges aligned with every second rising edge of tim_psc_ck after CEN goes high. The Counter register displays a sequence of values: 0034, 0035, 0036, 0000, 0001, 0002, 0003. Each value changes on a rising edge of tim_cnt_ck . When the counter reaches 0036, the next rising edge of tim_cnt_ck causes the register to reset to 0000. At this exact moment, the Counter overflow , Update event (UEV) , and Update interrupt flag (UIF) signals all transition from low to high. Vertical dashed lines indicate the timing relationships between the signals.

Timing diagram for internal clock divided by 2. It shows the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register values (0034, 0035, 0036, 0000, 0001, 0002, 0003), Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

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

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

This timing diagram illustrates the operation of a counter with an internal clock divided by 4. The tim_psc_ck signal is a high-frequency square wave. The CEN signal goes high at the second rising edge of tim_psc_ck . The tim_cnt_ck signal is a square wave with a frequency one-quarter that of tim_psc_ck , with its rising edges aligned with every fourth rising edge of tim_psc_ck after CEN goes high. The Counter register displays values 0035, 0036, 0000, and 0001. The counter increments from 0035 to 0036 on the first rising edge of tim_cnt_ck after CEN goes high. On the next rising edge of tim_cnt_ck , the register resets to 0000, which simultaneously triggers the Counter overflow , Update event (UEV) , and Update interrupt flag (UIF) signals to go high. Vertical dashed lines indicate the timing relationships between the signals.

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

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

Timing diagram for Figure 161 showing counter behavior with internal clock divided by N.

This timing diagram illustrates the counter's operation when the internal clock is divided by N. The top signal, tim_psc_ck , is a periodic square wave. Below it, tim_cnt_ck is a lower-frequency square wave, representing the clock after division. The Counter register shows a sequence of values: starting at 1F , it increments to 20 , then overflows to 00 . The Counter overflow signal is a pulse that goes high when the counter reaches 20 and returns low when it reaches 00 . The Update event (UEV) and Update interrupt flag (UIF) are also pulses that go high at the overflow point (from 20 to 00) and return low at the zero point (from 00 to 01). The diagram is labeled MSv62302V1.

Timing diagram for Figure 161 showing counter behavior with internal clock divided by N.

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

Timing diagram for Figure 162 showing counter behavior with ARPE = 0 and TIMx_ARR not preloaded.

This timing diagram shows the counter's operation with ARPE = 0 and TIMx_ARR not preloaded. The tim_psc_ck signal is a periodic square wave. The CEN (Counter Enable) signal is shown as a high-level signal. The tim_cnt_ck signal is a periodic square wave. The Counter register shows a sequence of values: starting at 31 , it increments through 32 , 33 , 34 , 35 , 36 , then overflows to 00 , 01 , 02 , 03 , 04 , 05 , 06 , 07 . The Counter overflow signal is a pulse that goes high when the counter reaches 36 and returns low when it reaches 00 . The Update event (UEV) and Update interrupt flag (UIF) are also pulses that go high at the overflow point (from 36 to 00) and return low at the zero point (from 00 to 01). The Auto-reload preload register shows a value of FF before a write event, and then changes to 36 after the event Write a new value in TIMx_ARR . The diagram is labeled MSv62303V1.

Timing diagram for Figure 162 showing counter behavior with ARPE = 0 and TIMx_ARR not preloaded.

Figure 163. Counter timing diagram, update event when ARPE = 1 (TIMx_ARR preloaded)

Timing diagram showing 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 shadow register. It illustrates the update event generation when ARPE = 1 and TIMx_ARR is preloaded.

The timing diagram shows the following signals and registers over time:

MSV62304V1

Timing diagram showing 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 shadow register. It illustrates the update event generation when ARPE = 1 and TIMx_ARR is preloaded.

Downcounting mode

In downcounting mode, the counter counts from the autoreload value (content of the TIMx_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 (TIMx_RCR) + 1. Else the update event is generated at each counter underflow.

Setting the UG bit in the TIMx_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 TIMx_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 TIMx_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 TIMx_SR register) is set (depending on the URS bit):

The following figures show some examples of the counter behavior for different clock frequencies when TIMx_ARR = 0x36.

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

Timing diagram for Figure 164 showing counter behavior with internal clock divided by 1.

The timing diagram illustrates the relationship between several signals over time. The top signal, tim_psc_ck , is a periodic square wave representing the prescaler clock. Below it, the CEN (Counter Enable) signal is shown as a horizontal line that transitions from low to high at a specific point. Following this transition, the tim_cnt_ck signal begins its periodic square wave activity. The Counter register is depicted as a sequence of values: 05, 04, 03, 02, 01, 00, 36, 35, 34, 33, 32, 31, 30, 2F. The counter decrements from 05 down to 00, and upon reaching 00, it underflows to 36. This underflow event triggers a pulse on the Counter underflow (cnt_udf) signal. Simultaneously, an Update event (UEV) is generated, shown as a short pulse. Finally, the Update interrupt flag (UIF) is set, indicated by a signal transition to high at the moment of the underflow.

Timing diagram for Figure 164 showing counter behavior with internal clock divided by 1.

MSV62305V1

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

Timing diagram for Figure 165 showing tim_psc_ck, CEN, tim_cnt_ck, Counter register values (0002, 0001, 0000, 0036, 0035, 0034, 0033), Counter underflow, Update event (UEV), and Update interrupt flag (UIF).

This timing diagram illustrates the operation of a counter with the internal clock divided by 2. The top signal, tim_psc_ck , is a high-frequency square wave. Below it, CEN (Counter Enable) is shown as a high-level signal. The tim_cnt_ck signal is a square wave with a frequency half that of tim_psc_ck . The Counter register displays a sequence of values: 0002, 0001, 0000, 0036, 0035, 0034, and 0033. Vertical dashed lines indicate the rising edges of tim_cnt_ck that correspond to the counter's decrementing steps. When the counter reaches 0000, the Counter underflow signal pulses high. Simultaneously, the Update event (UEV) and the Update interrupt flag (UIF) also pulse high. The diagram is labeled MSV62306V1 in the bottom right corner.

Timing diagram for Figure 165 showing tim_psc_ck, CEN, tim_cnt_ck, Counter register values (0002, 0001, 0000, 0036, 0035, 0034, 0033), Counter underflow, Update event (UEV), and Update interrupt flag (UIF).

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

Timing diagram for Figure 166 showing tim_psc_ck, CEN, tim_cnt_ck, Counter register values (0001, 0000, 0000, 0001), Counter underflow, Update event (UEV), and Update interrupt flag (UIF).

This timing diagram illustrates the operation of a counter with the internal clock divided by 4. The tim_psc_ck signal is a high-frequency square wave, and CEN is a high-level signal. The tim_cnt_ck signal is a square wave with a frequency one-quarter that of tim_psc_ck . The Counter register shows values 0001, 0000, 0000, and 0001. Vertical dashed lines mark the rising edges of tim_cnt_ck . The counter decrements from 0001 to 0000, triggering the Counter underflow , Update event (UEV) , and Update interrupt flag (UIF) signals. After another tim_cnt_ck rising edge, the counter value remains at 0000, and the signals remain high. On the next rising edge, the counter increments to 0001, and the signals return to their initial states. The diagram is labeled MSV62307V1 in the bottom right corner.

Timing diagram for Figure 166 showing tim_psc_ck, CEN, tim_cnt_ck, Counter register values (0001, 0000, 0000, 0001), Counter underflow, Update event (UEV), and Update interrupt flag (UIF).

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

Timing diagram for Figure 167 showing signals: 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 timer when the internal clock is divided by N. The top signal, tim_psc_ck , is a periodic square wave. Below it, tim_cnt_ck is a signal that toggles its state on the rising edges of tim_psc_ck . The Counter register shows a sequence of values: 20, 1F, 00, and 36. The counter counts down from 20 to 1F, then wraps around to 00. Upon reaching 00, a Counter underflow pulse is generated, followed by an Update event (UEV) and a pulse on the Update interrupt flag (UIF) . After the update event, the counter resumes counting from 36. The diagram is labeled MSv62308V1.

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

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

Timing diagram for Figure 168 showing signals: tim_psc_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 timer's behavior when the repetition counter is not used. The tim_psc_ck signal is a square wave. The CEN (Counter Enable) signal is shown as a high level. The tim_cnt_ck signal is a square wave derived from tim_psc_ck . The Counter register displays a sequence of values: 05, 04, 03, 02, 01, 00, 36, 35, 34, 33, 32, 31, 30, and 2F. The counter counts down from 05 to 00. At 00, a Counter underflow pulse occurs, followed by an Update event (UEV) and a pulse on the Update interrupt flag (UIF) . The counter then reloads with the value 36 and continues counting down. The Auto-reload preload register is shown with values FF and 36. An annotation 'Write a new value in TIMx_ARR' points to the transition between FF and 36. The diagram is labeled MSv62309V1.

Timing diagram for Figure 168 showing signals: tim_psc_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 TIMx_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 TIMx_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 TIMx_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 TIMx_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 TIMx_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 TIMx_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 TIMx_SR register) is set (depending on the URS bit):

The following figures show some examples of the counter behavior for different clock frequencies.

Figure 169. Counter timing diagram, internal clock divided by 1, TIMx_ARR = 0x6

Timing diagram for Figure 169 showing signals: tim_psc_ck, CEN, tim_cnt_ck, Counter register (values: 04, 03, 02, 01, 00, 01, 02, 03, 04, 05, 06, 05, 04, 03), Counter underflow, Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

This timing diagram illustrates the operation of a timer in center-aligned mode 1 with an internal clock divided by 1 and an auto-reload register (TIMx_ARR) set to 0x6. The diagram shows the following signals over time:

Vertical dashed lines indicate the clock edges of tim_cnt_ck that correspond to the counter value changes. The diagram is labeled MSV62310V1.

Timing diagram for Figure 169 showing signals: tim_psc_ck, CEN, tim_cnt_ck, Counter register (values: 04, 03, 02, 01, 00, 01, 02, 03, 04, 05, 06, 05, 04, 03), Counter underflow, Counter overflow, Update event (UEV), and Update interrupt flag (UIF).
  1. 1. Here, center-aligned mode 1 is used (for more details refer to Section 29.6: TIM1 registers ).

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

Timing diagram for Figure 170 showing signals: tim_psc_ck, CEN, tim_cnt_ck, Counter register (values: 0003, 0002, 0001, 0000, 0001, 0002, 0003), Counter underflow, Update event (UEV), and Update interrupt flag (UIF).

This timing diagram illustrates the operation of a timer with an internal clock divided by 2. The diagram shows the following signals over time:

Vertical dashed lines indicate the clock edges of tim_cnt_ck that correspond to the counter value changes. The diagram is labeled MSV62311V1.

Timing diagram for Figure 170 showing signals: tim_psc_ck, CEN, tim_cnt_ck, Counter register (values: 0003, 0002, 0001, 0000, 0001, 0002, 0003), Counter underflow, Update event (UEV), and Update interrupt flag (UIF).

Figure 171. Counter timing diagram, internal clock divided by 4, TIMx_ARR = 0x36

Timing diagram for Figure 171 showing signals: tim_psc_ck, CEN, tim_cnt_ck, Counter register (values 0034, 0035, 0036, 0035), Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

This timing diagram illustrates the operation of a counter with an internal clock divided by 4 and an auto-reload register (TIMx_ARR) set to 0x36. The signals shown are:

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

MSV62312V1

Timing diagram for Figure 171 showing signals: tim_psc_ck, CEN, tim_cnt_ck, Counter register (values 0034, 0035, 0036, 0035), Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

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

Timing diagram for Figure 172 showing signals: tim_psc_ck, tim_cnt_ck, Counter register (values 20, 1F, 01, 00), Counter underflow, Update event (UEV), and Update interrupt flag (UIF).

This timing diagram illustrates the operation of a counter with an internal clock divided by N. The signals shown are:

MSV62313V1

Timing diagram for Figure 172 showing signals: tim_psc_ck, tim_cnt_ck, Counter register (values 20, 1F, 01, 00), Counter underflow, Update event (UEV), and Update interrupt flag (UIF).

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

Figure 173: Counter timing diagram, update event with ARPE = 1 (counter underflow). The diagram shows the relationship between various timer signals during a down-counting sequence that reaches zero and wraps around. Key signals include tim_psc_ck (prescaler clock), CEN (counter enable), tim_cnt_ck (counter clock), Counter register (values 06, 05, 04, 03, 02, 01, 00, 01, 02, 03, 04, 05, 06, 07), Counter underflow pulse, Update event (UEV) pulse, Update interrupt flag (UIF), Auto-reload preload register, and Auto-reload active register. A write to TIMx_ARR changes the preload register from FD to 36, which is then transferred to the active register at the update event.
tim_psc_ck
CEN
tim_cnt_ck
Counter register
Counter underflow
Update event (UEV)
Update interrupt flag (UIF)
Auto-reload preload register
Write a new value in TIMx_ARR
Auto-reload active register
MSV62314V1
Figure 173: Counter timing diagram, update event with ARPE = 1 (counter underflow). The diagram shows the relationship between various timer signals during a down-counting sequence that reaches zero and wraps around. Key signals include tim_psc_ck (prescaler clock), CEN (counter enable), tim_cnt_ck (counter clock), Counter register (values 06, 05, 04, 03, 02, 01, 00, 01, 02, 03, 04, 05, 06, 07), Counter underflow pulse, Update event (UEV) pulse, Update interrupt flag (UIF), Auto-reload preload register, and Auto-reload active register. A write to TIMx_ARR changes the preload register from FD to 36, which is then transferred to the active register at the update event.

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

Figure 174. Counter timing diagram, Update event with ARPE = 1 (counter overflow). The diagram shows the relationship between the prescaler clock (tim_psc_ck), counter enable (CEN), counter clock (tim_cnt_ck), counter register values, counter overflow, update event (UEV), update interrupt flag (UIF), auto-reload preload register, and auto-reload active register. The counter register values are shown in hexadecimal: F7, F8, F9, FA, FB, FC, 36, 35, 34, 33, 32, 31, 30, 2F. The auto-reload preload register is shown with the value FD, and the auto-reload active register is shown with the value 36. A note indicates 'Write a new value in TIMx_ARR'.

The timing diagram illustrates the operation of an advanced-control timer (TIM1) in counter mode with ARPE = 1. The signals shown are:

MSv62315V1

Figure 174. Counter timing diagram, Update event with ARPE = 1 (counter overflow). The diagram shows the relationship between the prescaler clock (tim_psc_ck), counter enable (CEN), counter clock (tim_cnt_ck), counter register values, counter overflow, update event (UEV), update interrupt flag (UIF), auto-reload preload register, and auto-reload active register. The counter register values are shown in hexadecimal: F7, F8, F9, FA, FB, FC, 36, 35, 34, 33, 32, 31, 30, 2F. The auto-reload preload register is shown with the value FD, and the auto-reload active register is shown with the value 36. A note indicates 'Write a new value in TIMx_ARR'.

29.3.5 Repetition counter

Section 29.3.3: Time-base unit describes how the update event (UEV) is generated with respect to the counter overflows/underflows. It is actually generated only when the repetition counter has reached zero. This can be useful when generating PWM signals.

This means that data are transferred from the preload registers to the shadow registers (TIMx_ARR autoreload register, TIMx_PSC prescaler register, but also TIMx_CCRx capture/compare registers in compare mode) every N+1 counter overflows or underflows, where N is the value in the TIMx_RCR repetition counter register.

The repetition counter is decremented:

    • • At each counter overflow in upcounting mode,
    • • At each counter underflow in downcounting mode,
    • • At each counter overflow and at each counter underflow in center-aligned mode.
  1. Although this limits the maximum number of repetition to 32768 PWM cycles, it makes it possible to update the duty cycle twice per PWM period. When refreshing compare registers only once per PWM period in center-aligned mode, maximum resolution is \( 2 \times T_{ck} \) , due to the symmetry of the pattern.

The repetition counter is an autoreload type; the repetition rate is maintained as defined by the TIMx_RCR register value (refer to Figure 175 ). When the update event is generated by software (by setting the UG bit in TIMx_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 TIMx_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 175. Update rate examples depending on mode and TIMx_RCR register settings

Figure 175: Update rate examples depending on mode and TIMx_RCR register settings. The figure shows a grid of waveforms for Counter-aligned and Edge-aligned (Upcounting/Downcounting) modes across various TIMx_RCR values (0, 1, 2, 3, and 3 with re-synchronization).

The figure illustrates the update event (UEV) frequency for different timer modes and RCR settings. The grid is organized as follows:

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

MSv31195V1

Figure 175: Update rate examples depending on mode and TIMx_RCR register settings. The figure shows a grid of waveforms for Counter-aligned and Edge-aligned (Upcounting/Downcounting) modes across various TIMx_RCR values (0, 1, 2, 3, and 3 with re-synchronization).

29.3.6 External trigger input

The timer features an external trigger input tim_etr_in . It can be used as:

Figure 176 below describes the tim_etr_in input conditioning. The input polarity is defined with the ETP bit in TIMxSMCR register. The trigger can be prescaled with the divider programmed by the ETPS[1:0] bitfield and digitally filtered with the ETF[3:0] bitfield. The resulting signal ( tim_etr ) is available for three purposes: as an external clock, to condition

the output (typically to reset a PWM output for a current limitation), and as a trigger for the Slave mode controller.

Figure 176. External trigger input block

Figure 176. External trigger input block diagram. The diagram shows the signal flow from the TIM_ETR pin (tim_etr0) and internal sources (tim_etr[15:1]) through a multiplexer (tim_etr_in) to a divider (/1, /2, /4, /8) and then to a filter downcounter. The divider output (tim_etrp) is connected to the filter downcounter. The filter downcounter output (tim_etr) is connected to the Output mode controller, the CK_PSC circuitry, and the Slave mode controller. Control signals are provided by TIMx_AF1[17:14] for the multiplexer, TIMx_SMCR for the ETP, ETPS[1:0] for the divider, and ETF[3:0] for the filter downcounter.
Figure 176. External trigger input block diagram. The diagram shows the signal flow from the TIM_ETR pin (tim_etr0) and internal sources (tim_etr[15:1]) through a multiplexer (tim_etr_in) to a divider (/1, /2, /4, /8) and then to a filter downcounter. The divider output (tim_etrp) is connected to the filter downcounter. The filter downcounter output (tim_etr) is connected to the Output mode controller, the CK_PSC circuitry, and the Slave mode controller. Control signals are provided by TIMx_AF1[17:14] for the multiplexer, TIMx_SMCR for the ETP, ETPS[1:0] for the divider, and ETF[3:0] for the filter downcounter.

The tim_etr_in input comes from multiple sources: input pins (default configuration), or internal sources. The selection is done with the ETRSEL[3:0] bitfield in the TIMx_AF1 register.

Refer to Section 29.3.2: TIM1 pins and internal signals for the list of sources connected to the etr_in input in the product.

29.3.7 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 = 000 ), then the CEN , DIR (in the TIMx_CR1 register) and UG bits (in the TIMx_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 177 shows the behavior of the control circuit and the upcounter in normal mode, without prescaler.

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

Timing diagram for Figure 177 showing control signals and counter register values over time. The signals shown are tim_ker_ck (kernel clock), CEN (counter enable), UG (update generation), counter initialization (internal), tim_cnt_ck and tim_psc_ck (counter and prescaler clocks), and the Counter register values. The counter register values shown are 31, 32, 33, 34, 35, 36, 00, 01, 02, 03, 04, 05, 06, 07. The diagram shows that the counter increments on the rising edges of tim_cnt_ck when CEN is high and UG is low. The counter is initialized to 00 when UG is high and counter initialization is active.
Timing diagram for Figure 177 showing control signals and counter register values over time. The signals shown are tim_ker_ck (kernel clock), CEN (counter enable), UG (update generation), counter initialization (internal), tim_cnt_ck and tim_psc_ck (counter and prescaler clocks), and the Counter register values. The counter register values shown are 31, 32, 33, 34, 35, 36, 00, 01, 02, 03, 04, 05, 06, 07. The diagram shows that the counter increments on the rising edges of tim_cnt_ck when CEN is high and UG is low. The counter is initialized to 00 when UG is high and counter initialization is active.

External clock source mode 1

This mode is selected when SMS = 111 in the TIMx_SMCR register. The counter can count at each rising or falling edge on a selected input.

Figure 178. tim_ti2 external clock connection example

Block diagram for Figure 178 showing the connection of tim_ti2 as an external clock source. The diagram shows the TIM_CH2 input (tim_ti2_in0 and tim_ti2_in[15:1]) connected to a Filter block (controlled by ICF[3:0] from TIMx_CCMR1). The Filter output is connected to an Edge detector block (controlled by CC2P from TIMx_CCER). The Edge detector output is connected to a multiplexer (controlled by TS[4:0] from TIMx_SMCR). The multiplexer selects between various clock sources: tim_itrx, tim_ti1f_ed, tim_ti1fp2, etrf, or internal clock (tim_ker_ck). The selected clock source is connected to the Encoder mode, External clock mode 1, External clock mode 2, or Internal clock mode blocks. These blocks are controlled by ECE and SMS[2:0] from TIMx_SMCR. The output of these blocks is tim_psc_ck.
Block diagram for Figure 178 showing the connection of tim_ti2 as an external clock source. The diagram shows the TIM_CH2 input (tim_ti2_in0 and tim_ti2_in[15:1]) connected to a Filter block (controlled by ICF[3:0] from TIMx_CCMR1). The Filter output is connected to an Edge detector block (controlled by CC2P from TIMx_CCER). The Edge detector output is connected to a multiplexer (controlled by TS[4:0] from TIMx_SMCR). The multiplexer selects between various clock sources: tim_itrx, tim_ti1f_ed, tim_ti1fp2, etrf, or internal clock (tim_ker_ck). The selected clock source is connected to the Encoder mode, External clock mode 1, External clock mode 2, or Internal clock mode blocks. These blocks are controlled by ECE and SMS[2:0] from TIMx_SMCR. The output of these blocks is tim_psc_ck.

1. Codes ranging from 01000 to 11111 are reserved.

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

  1. 1. Configure channel 2 to detect rising edges on the tim_ti2 input by writing CC2S = 01 in the TIMx_CCMR1 register.
  2. 2. Configure the input filter duration by writing the IC2F[3:0] bits in the TIMx_CCMR1 register (if no filter is needed, keep IC2F = 0000).
  3. 3. Select rising edge polarity by writing CC2P = 0 and CC2NP = 0 in the TIMx_CCER register.
  4. 4. Configure the timer in external clock mode 1 by writing SMS = 111 in the TIMx_SMCR register.
  5. 5. Select tim_ti2 as the trigger input source by writing TS = 00110 in the TIMx_SMCR register.
  6. 6. Enable the counter by writing CEN = 1 in the TIMx_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 179. Control circuit in external clock mode 1

Timing diagram for Figure 179 showing the relationship between tim_ti2, CEN, tim_cnt_ck, Counter register, and TIF signals. The diagram shows that the counter register increments from 34 to 35 and then to 36 in response to rising edges on tim_ti2. The TIF flag is set when the counter increments and is cleared by writing TIF=0.

The timing diagram illustrates the control circuit in external clock mode 1. It shows five signal traces over time:

Timing diagram for Figure 179 showing the relationship between tim_ti2, CEN, tim_cnt_ck, Counter register, and TIF signals. The diagram shows that the counter register increments from 34 to 35 and then to 36 in response to rising edges on tim_ti2. The TIF flag is set when the counter increments and is cleared by writing TIF=0.

External clock source mode 2

This mode is selected by writing ECE = 1 in the TIMx_SMCR register.

The counter counts at each rising or falling edge on the external trigger input tim_etr_in.

The Figure 180 gives an overview of the external trigger input block.

Figure 180. External trigger input block

Figure 180. External trigger input block diagram showing the signal flow from TIM_ETR and tim_etr[15:1] through a multiplexer, filter, and downcounter to the encoder mode selection logic.

The diagram illustrates the external trigger input block for TIM1. On the left, the TIM_ETR pin (tim_etr0) and the tim_etr[15:1] signal are inputs to a multiplexer. The multiplexer output is tim_etr_in. This signal is also connected to an inverter. The tim_etr_in signal is then processed by a filter and a downcounter. The filter is controlled by the ETF[3:0] register in the TIMx_SMCR. The downcounter is controlled by the ETPS[1:0] register in the TIMx_SMCR. The output of the downcounter is tim_etrp. This signal is then processed by a second multiplexer. The second multiplexer has four inputs: tim_tif1 or tim_tif2, tim_trgi, tim_etrp, and tim_ker_ck (internal clock). The output of this multiplexer is tim_psc_ck. The second multiplexer is controlled by the ECE and SMS[2:0] registers in the TIMx_SMCR. The diagram also shows the TIMx_AF1[17:14] register and the MSV62320V2 identifier.

Figure 180. External trigger input block diagram showing the signal flow from TIM_ETR and tim_etr[15:1] through a multiplexer, filter, and downcounter to the encoder mode selection logic.
  1. 1. Refer to Section 29.3.2: TIM1 pins and internal signals .

For example, to configure the upcounter to count each 2 rising edges on tim_etr_in, use the following procedure:

  1. 1. As no filter is needed in this example, write ETF[3:0] = 0000 in the TIMx_SMCR register.
  2. 2. Set the prescaler by writing ETPS[1:0] = 01 in the TIMx_SMCR register
  3. 3. Select rising edge detection on the tim_etr_in input by writing ETP = 0 in the TIMx_SMCR register
  4. 4. Enable external clock mode 2 by writing ECE = 1 in the TIMx_SMCR register.
  5. 5. Enable the counter by writing CEN = 1 in the TIMx_CR1 register.

The counter counts once each 2 tim_etr_in rising edges.

The delay between the rising edge on tim_etr_in and the actual clock of the counter is due to the resynchronization circuit on the tim_etrp signal. As a consequence, the maximum frequency which can be correctly captured by the counter is at most \( \frac{1}{4} \) of tim_ker_ck frequency. When the ETRP signal is faster, the user must apply a division of the external signal by a proper ETPS prescaler setting.

Figure 181. Control circuit in external clock mode 2

Timing diagram for Figure 181 showing signals tim_ker_ck, CEN, tim_etr_in, tim_etrp, tim_etrF, tim_cnt_ck, tim_psc_ck, and Counter register values 34, 35, 36 over time.

The diagram shows the relationship between several signals over time. tim_ker_ck is a periodic square wave. CEN is a signal that goes high and stays high. tim_etr_in and tim_etrp are square waves with varying frequencies and phases. tim_etrF is a signal that goes high when tim_etr_in is high and tim_etrp is low. tim_cnt_ck and tim_psc_ck are signals that are high only when tim_etrF is high. The Counter register shows values 34, 35, and 36, with increments occurring on the falling edges of tim_cnt_ck . The diagram is labeled MSv62321V1.

Timing diagram for Figure 181 showing signals tim_ker_ck, CEN, tim_etr_in, tim_etrp, tim_etrF, tim_cnt_ck, tim_psc_ck, and Counter register values 34, 35, 36 over time.

29.3.8 Capture/compare channels

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

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

Block diagram of the capture/compare channel input stage for channel 1.

The diagram illustrates the input stage of a capture/compare channel. It starts with TIM_CH1 and tim_ti1_in[15:1] inputs. A multiplexer selects between these based on TIMx_TISEL (specifically TI1SEL[3:0] ). The selected signal passes through a Filter downcounter (controlled by ICF[3:0] and TIMx_CCMR1 ) to produce tim_ti1f . This signal then goes through an Edge detector (controlled by CC1P/CC1NP and TIMx_CCER ) to generate tim_ti1f_rising and tim_ti1f_falling signals. These are combined into tim_ti1f_ed , which is sent to the slave mode controller. Another multiplexer selects between tim_ti1f_rising , tim_ti1f_falling , tim_ti2f_rising (from channel 2), tim_ti2f_falling (from channel 2), tim_trc (from slave mode controller), and tim_etr based on CC1S[1:0] and ICPS[1:0] (controlled by TIMx_CCMR1 ). The selected signal is then divided by a Divider (options: /1, /2, /4, /8) controlled by CC1E (controlled by TIMx_CCER ) to produce the final output tim_ic1f . The diagram is labeled MSv62322V2.

Block diagram of the capture/compare channel input stage for channel 1.

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

Block diagram of Capture/compare channel 1 main circuit showing input and output modes, registers, and logic gates.

The diagram illustrates the internal architecture of Capture/compare channel 1. At the top, the APB Bus connects to an MCU-peripheral interface, which in turn connects to a 16/32-bit Capture/compare preload register. This register is linked to a compare shadow register, which is further connected to a Counter. The Counter's output is fed into a Comparator, which produces two signals: CNT>CCR1 and CNT=CCR1. The Comparator also receives input from the compare shadow register. The Counter's output is also used for capture operations. In input mode, the Counter's output is captured into the compare shadow register via a 'Capture' block. This is controlled by logic gates that take inputs from CC1S[1], CC1S[0], IC1PS, CC1E, CC1G, and TIMx_EGR. In output mode, the compare shadow register's value is transferred to the Counter via a 'Compare transfer' block. This is controlled by logic gates that take inputs from CC1S[1], CC1S[0], OC1PE, and UEV (from time base unit). The OC1PE signal is derived from TIMx_CCMR1. The Counter's output is also used to generate the OC1PE signal. The diagram is labeled MSv63030V1 in the bottom right corner.

Block diagram of Capture/compare channel 1 main circuit showing input and output modes, registers, and logic gates.

Figure 184. Output stage of capture/compare channel (channel 1, idem ch. 2, 3 and 4)

Schematic diagram of the output stage of capture/compare channel 1. It shows the signal flow from the Output mode controller through an Output selector and Dead-time generator to the Output enable circuit, resulting in the tim_oc1 output. Various control registers like TIMx_SMCR, TIMx_CCMR1, TIMx_BDTR, and TIMx_CR2 are shown with their respective bits and signals.

The diagram illustrates the internal logic of the output stage for channel 1. At the top, the TIMx_SMCR register's OCCS bit is connected to a multiplexer. The inputs to this MUX are tim_ocref_clr (0) and tim_etr (1). The output of the MUX is ocref_clr_int, which is also connected to the Output mode controller. The Output mode controller receives inputs from CNT>CCR1, CNT=CCR1, tim_ocxref (1) (tim_oc5ref), and tim_oc1ref. It has control bits OC1CE and OC1M[3:0] from the TIMx_CCMR1 register. The controller's output goes to an Output selector. The Output selector also receives inputs from the Dead-time generator and has control bits from the TIMx_BDTR register (DTG[7:0]). The Dead-time generator produces tim_oc1refc and tim_oc1n_dt signals. The tim_oc1refc signal is sent to the master mode controller. The tim_oc1n_dt signal is processed by a multiplexer (inputs '0' and 11) and then an inverter. The output of the inverter is connected to the CC1P register (part of TIMx_CCER). The CC1P register's output is connected to the Output enable circuit. The Output enable circuit also receives inputs from the CC1NE and CC1E registers (part of TIMx_CCER) and control bits from the TIMx_BDTR register (MOE, OSSI, OSSR) and TIMx_CR2 (OIS1, OIS1N). The final output is tim_oc1.

Schematic diagram of the output stage of capture/compare channel 1. It shows the signal flow from the Output mode controller through an Output selector and Dead-time generator to the Output enable circuit, resulting in the tim_oc1 output. Various control registers like TIMx_SMCR, TIMx_CCMR1, TIMx_BDTR, and TIMx_CR2 are shown with their respective bits and signals.

1. tim_ocxref, where x is the rank of the complementary channel

Figure 185. Output stage of capture/compare channel (channel 5, idem ch. 6)

Schematic diagram of the output stage of capture/compare channel 5. It shows the signal flow from the Output mode controller through a multiplexer and an inverter to the Output enable circuit, resulting in the tim_oc5 output. Control registers like TIMx_SMCR, TIMx_CCMR3, TIMx_BDTR, and TIMx_CR2 are shown with their respective bits and signals.

The diagram illustrates the internal logic of the output stage for channel 5. At the top, the TIMx_SMCR register's OCCS bit is connected to a multiplexer. The inputs to this MUX are tim_ocref_clr (0) and tim_etr (1). The output of the MUX is ocref_clr_int, which is also connected to the Output mode controller. The Output mode controller receives inputs from CNT>CCR5, CNT=CCR5, and tim_oc5ref. It has control bits OC5CE and OC5M[3:0] from the TIMx_CCMR3 register. The controller's output goes to a multiplexer (inputs '0' and 1). The output of this MUX is processed by an inverter. The output of the inverter is connected to the CC5P register (part of TIMx_CCER). The CC5P register's output is connected to the Output enable circuit. The Output enable circuit also receives inputs from the CC5E register (part of TIMx_CCER) and control bits from the TIMx_BDTR register (MOE, OSSI) and TIMx_CR2 (OIS5). The final output is tim_oc5 (1) .

Schematic diagram of the output stage of capture/compare channel 5. It shows the signal flow from the Output mode controller through a multiplexer and an inverter to the Output enable circuit, resulting in the tim_oc5 output. Control registers like TIMx_SMCR, TIMx_CCMR3, TIMx_BDTR, and TIMx_CR2 are shown with their respective bits and signals.

1. Not available externally.

The capture/compare block is made of one preload register and one shadow register. Write and read always access the preload register.

In capture mode, captures are actually done in the shadow register, which is copied into the preload register.

In compare mode, the content of the preload register is copied into the shadow register which is compared to the counter.

29.3.9 Input capture mode

In Input capture mode, the capture/compare registers (TIMx_CCRx) are used to latch the value of the counter after a transition detected by the corresponding ICx signal. When a capture occurs, the corresponding CCxIF flag (TIMx_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 (TIMx_SR register) is set. CCxIF can be cleared by software by writing it to 0 or by reading the captured data stored in the TIMx_CCRx register. CCxOF is cleared when it is written with 0.

The following example shows how to capture the counter value in TIMx_CCR1 when tim_ti1 input rises. To do this, use the following procedure:

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

29.3.10 PWM input mode

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

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

The period and the pulsewidth of a PWM signal applied on tim_ti1 can be measured using the following procedure:

Figure 186. PWM input mode timing

Timing diagram for PWM input mode showing tim_ti1, TIMx_CNT, TIMx_CCR1, and TIMx_CCR2 signals over time. The diagram illustrates three capture events: IC1 capture (IC2 capture, reset counter) at the first falling edge, IC2 capture (pulse width measurement) at the first rising edge, and IC1 capture (pulse width measurement) at the second falling edge. The counter values are shown in the TIMx_CNT register: 0004, 0000, 0001, 0002, 0003, 0004, 0000. The capture registers TIMx_CCR1 and TIMx_CCR2 show values 0004 and 0002 respectively.

The timing diagram shows the relationship between the input signal tim_ti1 , the counter TIMx_CNT , and the capture/compare registers TIMx_CCR1 and TIMx_CCR2 in PWM input mode. The tim_ti1 signal is a PWM signal. The counter TIMx_CNT is shown with values 0004, 0000, 0001, 0002, 0003, 0004, 0000. The capture registers TIMx_CCR1 and TIMx_CCR2 show values 0004 and 0002 respectively. The diagram illustrates three capture events: IC1 capture (IC2 capture, reset counter) at the first falling edge, IC2 capture (pulse width measurement) at the first rising edge, and IC1 capture (pulse width measurement) at the second falling edge. The text MSv62325V1 is present in the bottom right corner of the diagram.

Timing diagram for PWM input mode showing tim_ti1, TIMx_CNT, TIMx_CCR1, and TIMx_CCR2 signals over time. The diagram illustrates three capture events: IC1 capture (IC2 capture, reset counter) at the first falling edge, IC2 capture (pulse width measurement) at the first rising edge, and IC1 capture (pulse width measurement) at the second falling edge. The counter values are shown in the TIMx_CNT register: 0004, 0000, 0001, 0002, 0003, 0004, 0000. The capture registers TIMx_CCR1 and TIMx_CCR2 show values 0004 and 0002 respectively.

29.3.11 Forced output mode

In output mode ( CCxS bits = 00 in the TIMx_CCMRx register), each output compare signal ( tim_ocxref and then tim_ocx/tim_ocxn ) can be forced to active or inactive level directly by software, independently of any comparison between the output compare register and the counter.

To force an output compare signal ( tim_ocxref/tim_ocx ) to its active level, user just needs to write 0101 in the OCxM bits in the corresponding TIMx_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 0100 in the TIMx_CCMRx register.

Anyway, the comparison between the TIMx_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.

29.3.12 Output compare mode

This function is used to control an output waveform or indicate when a period of time has elapsed. Channels 1 to 4 can be output, while channel 5 and 6 are only available inside the microcontroller (for instance, for compound waveform generation or for ADC triggering).

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

set active (OCxM = 0001), be set inactive (OCxM = 0010) or can toggle (OCxM = 0011) on match.

The TIMx_CCRx registers can be programmed with or without preload registers using the OCxPE bit in the TIMx_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 TIMx_ARR and TIMx_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 = 0011 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 TIMx_CR1 register.

The TIMx_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 TIMx_CCRx shadow register is updated only at the next update event UEV). An example is given in Figure 187 .

Figure 187. Output compare mode, toggle on tim_oc1

Timing diagram for Output compare mode, toggle on tim_oc1. The diagram shows three horizontal timelines: CNT (Counter), CCR1 (Capture/Compare Register 1), and tim_oc1ref = tim_oc1 (Output compare reference). CNT starts at 0039, increments through 003A, 003B, and eventually reaches B200 and B201. CCR1 is initially set to 003A and is updated to B201. An arrow points from the text 'Write B201h in the CC1R register' to the CCR1 value B201. The tim_oc1ref output is shown as a square wave that toggles state when the CNT value matches the CCR1 value. Two arrows point from the rising and falling edges of the square wave to the text 'Match detected on CCR1 Interrupt generated if enabled'. The diagram is labeled MSV62326V1 in the bottom right corner.
Timing diagram for Output compare mode, toggle on tim_oc1. The diagram shows three horizontal timelines: CNT (Counter), CCR1 (Capture/Compare Register 1), and tim_oc1ref = tim_oc1 (Output compare reference). CNT starts at 0039, increments through 003A, 003B, and eventually reaches B200 and B201. CCR1 is initially set to 003A and is updated to B201. An arrow points from the text 'Write B201h in the CC1R register' to the CCR1 value B201. The tim_oc1ref output is shown as a square wave that toggles state when the CNT value matches the CCR1 value. Two arrows point from the rising and falling edges of the square wave to the text 'Match detected on CCR1 Interrupt generated if enabled'. The diagram is labeled MSV62326V1 in the bottom right corner.

29.3.13 PWM mode

Pulse width modulation mode is used to generate a signal with a frequency determined by the value of the TIMx_ARR register and a duty cycle determined by the value of the TIMx_CCRx register.

The PWM mode can be selected independently on each channel (one PWM per tim_ocx output) by writing 0110 (PWM mode 1) or 0111 (PWM mode 2) in the OCxM bits in the TIMx_CCMRx register. The corresponding preload register must be enabled by setting the OCxPE bit in the TIMx_CCMRx register, and eventually the autoreload preload register (in upcounting or center-aligned modes) by setting the ARPE bit in the TIMx_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 TIMx_EGR register.

tim_ocx polarity is software programmable using the CCxP bit in the TIMx_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 (TIMx_CCER and TIMx_BDTR registers). Refer to the TIMx_CCER register description for more details.

In PWM mode (1 or 2), TIMx_CNT and TIMx_CCRx are always compared to determine whether \( TIMx\_CCRx \leq TIMx\_CNT \) or \( TIMx\_CNT \leq TIMx\_CCRx \) (depending on the direction of the counter).

The timer is able to generate PWM in edge-aligned mode or center-aligned mode depending on the CMS bits in the TIMx_CR1 register.

PWM edge-aligned mode

Upcounting is active when the DIR bit in the TIMx_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 TIMx_CNT < TIMx_CCRx else it becomes low. If the compare value in TIMx_CCRx is greater than the autoreload value (in TIMx_ARR) then tim_ocxref is held at 1. If the compare value is zero then tim_ocxref is held at 0.

Figure 188 shows some edge-aligned PWM waveforms in an example where TIMx_ARR = 8.

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

Timing diagram showing Counter register values (0-8, 0, 1) and corresponding PWM waveforms for CCRx=4, CCRx=8, CCRx>8, and CCRx=0. The diagram shows the relationship between the counter value and the output signal tim_ocxref and interrupt flag CCxIF.

The figure is a timing diagram illustrating edge-aligned PWM waveforms for different compare register (CCR) values. The top row shows the Counter register (TIMx_CNT) values: 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1. Vertical dashed lines mark the transitions between these values. Below the counter, four sets of waveforms are shown for different CCRx values:

MSV62327V1

Timing diagram showing Counter register values (0-8, 0, 1) and corresponding PWM waveforms for CCRx=4, CCRx=8, CCRx>8, and CCRx=0. The diagram shows the relationship between the counter value and the output signal tim_ocxref and interrupt flag CCxIF.

Downcounting is active when DIR bit in TIMx_CR1 register is high. Refer to the Downcounting mode

In PWM mode 1, the reference signal tim_ocxref is low as long as TIMx_CNT > TIMx_CCRx else it becomes high. If the compare value in TIMx_CCRx is greater than the autoreload value in TIMx_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 TIMx_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 TIMx_CR1 register is updated by hardware and must not be changed by software. Refer to Center-aligned mode (up/down counting) .

Figure 189 shows some center-aligned PWM waveforms in an example where:

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

Timing diagram showing center-aligned PWM waveforms for different CCRx values (4, 7, 8, >8, 0) with ARR=8. The diagram includes counter register values, tim_ocxref waveforms, and CCxIF flag status for CMS=01, 10, and 11.

The figure illustrates the relationship between the counter register values and the resulting PWM waveforms for various Capture/Compare Register (CCR) values. The counter register values are shown at the top, cycling from 0 to 8 and back down to 0. Vertical dashed lines indicate the timing points for each CCR value.

MSV62328V2

Timing diagram showing center-aligned PWM waveforms for different CCRx values (4, 7, 8, >8, 0) with ARR=8. The diagram includes counter register values, tim_ocxref waveforms, and CCxIF flag status for CMS=01, 10, and 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 TIMx_CR1 register. This applies to both the CCR (for duty cycle resolution increase) and ARR (for PWM frequency resolution increase).

The operating principle is to have the actual CCR (or ARR) value slightly changed (adding or not one timer clock period) over 16 consecutive PWM periods, with predefined patterns. This allows a 16-fold resolution increase, considering the average duty cycle or PWM period. Figure 190 presents the dithering principle applied to four consecutive PWM cycles.

Figure 190. Dithering principle

Figure 190. Dithering principle. A diagram showing five rows of PWM waveforms over four consecutive cycles. The top row shows a standard PWM with a high pulse of 7 clock cycles and a low pulse of 5 clock cycles, labeled 'Average duty cycle' and 'DC = 7/5'. The subsequent rows show the effect of dithering: 'DC = (7+1/4)/5' adds a 1/4 clock cycle high pulse; 'DC = (7+1/2)/5' adds a 1/2 clock cycle high pulse; 'DC = (7+3/4)/5' adds a 3/4 clock cycle high pulse; and the bottom row shows 'DC = 8/5' where the high pulse is 8 clock cycles. Shaded vertical bars indicate the additional time added to the high pulse in each dithering step. A double-headed arrow at the bottom indicates '1 clock cycle'.
Figure 190. Dithering principle. A diagram showing five rows of PWM waveforms over four consecutive cycles. The top row shows a standard PWM with a high pulse of 7 clock cycles and a low pulse of 5 clock cycles, labeled 'Average duty cycle' and 'DC = 7/5'. The subsequent rows show the effect of dithering: 'DC = (7+1/4)/5' adds a 1/4 clock cycle high pulse; 'DC = (7+1/2)/5' adds a 1/2 clock cycle high pulse; 'DC = (7+3/4)/5' adds a 3/4 clock cycle high pulse; and the bottom row shows 'DC = 8/5' where the high pulse is 8 clock cycles. Shaded vertical bars indicate the additional time added to the high pulse in each dithering step. A double-headed arrow at the bottom indicates '1 clock cycle'.

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

  1. Note: The following sequence must be followed when resetting the DITHEN bit:
    1. 1. CEN and ARPE bits must be reset.
    2. 2. The DITHEN bit must be reset.
    3. 3. The CCIF flags must be cleared.
    4. 4. The CEN bit can be set (eventually with ARPE = 1).

Figure 191. Data format and register coding in dithering mode

Figure 191: Data format and register coding in dithering mode. The diagram shows two examples of a 20-bit register format. The first example shows the 'Register format in dithering mode' with bits b19 to b0. The MSB (bits b19 to b4) is a 16-bit integer part, and the LSB (bits b3 to b0) is a 4-bit fractional part. The second example shows a specific register value of 326. This value is split into an integer part of 20 and a fractional part of 6. Arrows point from these parts to a description: 'Base compare value is 20 during 16 periods' and 'Additional 6 cycles are spread over the 16 periods'. The code MSv45753V2 is shown in the bottom right corner.
Figure 191: Data format and register coding in dithering mode. The diagram shows two examples of a 20-bit register format. The first example shows the 'Register format in dithering mode' with bits b19 to b0. The MSB (bits b19 to b4) is a 16-bit integer part, and the LSB (bits b3 to b0) is a 4-bit fractional part. The second example shows a specific register value of 326. This value is split into an integer part of 20 and a fractional part of 6. Arrows point from these parts to a description: 'Base compare value is 20 during 16 periods' and 'Additional 6 cycles are spread over the 16 periods'. The code MSv45753V2 is shown in the bottom right corner.

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}} \]

  1. Note: The maximum TIMx_ARR and TIMxCCRy values are limited to 0xFFFEF in dithering mode (corresponds to 65534 for the integer part and 15 for the dithered part).

As shown on Figure 192, the dithering mode is used to increase the PWM resolution whatever the PWM frequency.

Figure 192. PWM resolution vs frequency

Figure 192. PWM resolution vs frequency. A graph showing PWM resolution (Y-axis) versus PWM frequency (X-axis). The Y-axis has markers for 20-bit and 16-bit. The X-axis has a marker for F_PWM min. Two curves are shown: 'Dithering' and 'No Dithering'. Both curves start at the minimum frequency and decrease as frequency increases. The 'Dithering' curve starts at 20-bit resolution, while the 'No Dithering' curve starts at 16-bit resolution. A vertical dashed line at F_PWM min indicates the starting point for both curves.

The graph illustrates the relationship between PWM resolution and PWM frequency. The Y-axis represents PWM resolution, with markers at 20-bit and 16-bit. The X-axis represents PWM frequency, with a marker at \( F_{PWM\ min} \) . Two curves are plotted: 'Dithering' and 'No Dithering'. Both curves start at the minimum frequency and decrease as frequency increases. The 'Dithering' curve starts at 20-bit resolution, while the 'No Dithering' curve starts at 16-bit resolution. A vertical dashed line at \( F_{PWM\ min} \) indicates the starting point for both curves. The 'Dithering' curve is consistently above the 'No Dithering' curve, indicating a higher resolution across the frequency range.

MSV47464V2

Figure 192. PWM resolution vs frequency. A graph showing PWM resolution (Y-axis) versus PWM frequency (X-axis). The Y-axis has markers for 20-bit and 16-bit. The X-axis has a marker for F_PWM min. Two curves are shown: 'Dithering' and 'No Dithering'. Both curves start at the minimum frequency and decrease as frequency increases. The 'Dithering' curve starts at 20-bit resolution, while the 'No Dithering' curve starts at 16-bit resolution. A vertical dashed line at F_PWM min indicates the starting point for both curves.

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

Figure 193. PWM dithering pattern

Timing diagram showing PWM dithering pattern over 16 counter periods. It includes rows for Counter period (1-16), CCR1 value (322), Compare1 value (alternating 21 and 20), CCR2 value (326), Compare2 value (alternating 21 and 20), CCR3 value (334), Compare3 value (mostly 21, some 20), CCR4 value (336), Compare4 value (mostly 21, some 20), ARR value (643), and Auto-Reload value (alternating 41 and 40).

The figure illustrates the PWM dithering pattern over 16 counter periods. The 'Counter period' row shows a sawtooth wave from 1 to 16. The 'CCR1 value' is constant at 322. The 'Compare1 value' alternates between 21 and 20. The 'CCR2 value' is constant at 326. The 'Compare2 value' alternates between 21 and 20. The 'CCR3 value' is constant at 334. The 'Compare3 value' is mostly 21, with some 20s. The 'CCR4 value' is constant at 336. The 'Compare4 value' is mostly 21, with some 20s. The 'ARR value' is constant at 643. The 'Auto-Reload value' alternates between 41 and 40.

Timing diagram showing PWM dithering pattern over 16 counter periods. It includes rows for Counter period (1-16), CCR1 value (322), Compare1 value (alternating 21 and 20), CCR2 value (326), Compare2 value (alternating 21 and 20), CCR3 value (334), Compare3 value (mostly 21, some 20), CCR4 value (336), Compare4 value (mostly 21, some 20), ARR value (643), and Auto-Reload value (alternating 41 and 40).

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

Table 265. CCR and ARR register change dithering pattern

LSB valuePWM period
12345678910111213141516
0000----------------
0001+1---------------
0010+1-------+1-------
0011+1---+1---+1-------
0100+1---+1---+1---+1---
0101+1-+1-+1---+1---+1---
0110+1-+1-+1---+1-+1-+1---

Table 265. CCR and ARR register change dithering pattern (continued)

LSB valuePWM period
12345678910111213141516
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 TIMx_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 194.

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

Three diagrams illustrating PWM duty cycle dithering. The first diagram shows a standard PWM signal with a constant duty cycle, labeled 'No dithering'. The second diagram shows the signal with the duty cycle increasing over time, labeled 'Dithering up'. The third diagram shows the signal with the duty cycle decreasing over time, labeled 'Dithering down'. Each diagram includes a dashed horizontal line representing the target duty cycle level.
Three diagrams illustrating PWM duty cycle dithering. The first diagram shows a standard PWM signal with a constant duty cycle, labeled 'No dithering'. The second diagram shows the signal with the duty cycle increasing over time, labeled 'Dithering up'. The third diagram shows the signal with the duty cycle decreasing over time, labeled 'Dithering down'. Each diagram includes a dashed horizontal line representing the target duty cycle level.

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

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

Table 266. CCR register change dithering pattern in center-aligned PWM mode (continued)

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

29.3.14 Asymmetric PWM mode

Asymmetric mode allows two center-aligned PWM signals to be generated with a programmable phase shift. While the frequency is determined by the value of the TIMx_ARR register, the duty cycle and the phase-shift are determined by a pair of TIMx_CCRx register. One register controls the PWM during up-counting, the second during down counting, so that PWM is adjusted every half PWM cycle:

Asymmetric PWM mode can be selected independently on two channel (one tim_ocx output per pair of CCR registers) by writing 1110 (Asymmetric PWM mode 1) or 1111 (Asymmetric PWM mode 2) in the OCxM bits in the TIMx_CCMRx register.

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

When a given channel is used as asymmetric PWM channel, its complementary channel can also be used. For instance, if an tim_oc1refc signal is generated on channel 1 (Asymmetric PWM mode 1), it is possible to output either the tim_oc2ref signal on channel 2, or an tim_oc2refc signal resulting from asymmetric PWM mode 1.

Figure 195 represents an example of signals that can be generated using asymmetric PWM mode (channels 1 to 4 are configured in asymmetric PWM mode 2). Together with the deadtime generator, this allows a full-bridge phase-shifted DC to DC converter to be controlled.

Figure 195. Generation of 2 phase-shifted PWM signals with 50% duty cycle

Timing diagram showing the generation of two phase-shifted PWM signals with 50% duty cycle. The top row shows the Counter register values from 0 to 8, then 7 down to 0, then 1. Below are two PWM signals: tim_oc1refc and tim_oc3refc. tim_oc1refc is high from counter value 0 to 8 and low from 8 to 0. tim_oc3refc is high from counter value 3 to 5 and low otherwise. CCR1=0, CCR2=8, CCR3=3, CCR4=5. MSV62329V1 is noted in the bottom right.

Counter register: 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 1

tim_oc1refc
CCR1=0
CCR2=8

tim_oc3refc
CCR3=3
CCR4=5

MSV62329V1

Timing diagram showing the generation of two phase-shifted PWM signals with 50% duty cycle. The top row shows the Counter register values from 0 to 8, then 7 down to 0, then 1. Below are two PWM signals: tim_oc1refc and tim_oc3refc. tim_oc1refc is high from counter value 0 to 8 and low from 8 to 0. tim_oc3refc is high from counter value 3 to 5 and low otherwise. CCR1=0, CCR2=8, CCR3=3, CCR4=5. MSV62329V1 is noted in the bottom right.

29.3.15 Combined PWM mode

Combined PWM mode allows two edge or center-aligned PWM signals to be generated with programmable delay and phase shift between respective pulses. While the frequency is determined by the value of the TIMx_ARR register, the duty cycle and delay are determined by the two TIMx_CCRx registers. The resulting signals, tim_ocxrefc, are made of an OR or AND logical combination of two reference PWMs:

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

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

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

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

Figure 196. Combined PWM mode on channel 1 and 3

Timing diagrams for combined PWM mode on channel 1 and 3. The top diagram shows the AND combination of tim_oc1ref and tim_oc2ref to produce tim_oc1refc. The bottom diagram shows the OR combination of tim1_oc1ref and tim1_oc2ref to produce tim1_oc1refc. Both diagrams include waveforms for CCR2, CCR1, and the respective reference signals.

Timing diagram illustrating Combined PWM mode on channel 1 and 3. The top section shows the AND combination of \( tim\_oc1ref \) and \( tim\_oc2ref \) to produce \( tim\_oc1refc \) . The bottom section shows the OR combination of \( tim1\_oc1ref \) and \( tim1\_oc2ref \) to produce \( tim1\_oc1refc \) . Both diagrams include waveforms for \( CCR2 \) , \( CCR1 \) , and the resulting combined signal.

Top section: \( tim\_oc1refc = tim\_oc1ref \text{ AND } tim\_oc2ref \)

Bottom section: \( tim1\_oc1refc = tim1\_oc1ref \text{ OR } tim1\_oc2ref \)

MSv62330V1

Timing diagrams for combined PWM mode on channel 1 and 3. The top diagram shows the AND combination of tim_oc1ref and tim_oc2ref to produce tim_oc1refc. The bottom diagram shows the OR combination of tim1_oc1ref and tim1_oc2ref to produce tim1_oc1refc. Both diagrams include waveforms for CCR2, CCR1, and the respective reference signals.

29.3.16 Combined 3-phase PWM mode

Combined 3-phase PWM mode allows one to three center-aligned PWM signals to be generated with a single programmable signal ANDed in the middle of the pulses. The \( tim\_oc5ref \) signal is used to define the resulting combined signal. The 3-bits \( GC5C[3:1] \) in the \( TIMx\_CCR5 \) allow selection on which reference signal the \( tim\_oc5ref \) is combined. The resulting signals, \( tim\_ocxrefc \) , are made of an AND logical combination of two reference PWMs:

Combined 3-phase PWM mode can be selected independently on channels 1 to 3 by setting at least one of the 3-bits \( GC5C[3:1] \) .

Figure 197. 3-phase combined PWM signals with multiple trigger pulses per period

Timing diagram showing 3-phase combined PWM signals with multiple trigger pulses per period. The diagram displays various control signals and output waveforms over time. At the top, ARR, CCR5, CCR6, CCR1, CCR4, CCR2, and CCR3 are shown as horizontal lines. Below them, the Counter is shown as a sawtooth waveform. Further down, tim_oc5ref, tim_oc1refc, tim_oc2refc, and tim_oc3refc are shown as step-like waveforms. The Preload register is shown with values 100, xxx, and 100. The Active register is shown with values 001 and 100. At the bottom, tim_oc4ref, tim_oc6ref, and tim_trgo2 are shown as step-like waveforms. The diagram is labeled MSv62331V1 in the bottom right corner.
Timing diagram showing 3-phase combined PWM signals with multiple trigger pulses per period. The diagram displays various control signals and output waveforms over time. At the top, ARR, CCR5, CCR6, CCR1, CCR4, CCR2, and CCR3 are shown as horizontal lines. Below them, the Counter is shown as a sawtooth waveform. Further down, tim_oc5ref, tim_oc1refc, tim_oc2refc, and tim_oc3refc are shown as step-like waveforms. The Preload register is shown with values 100, xxx, and 100. The Active register is shown with values 001 and 100. At the bottom, tim_oc4ref, tim_oc6ref, and tim_trgo2 are shown as step-like waveforms. The diagram is labeled MSv62331V1 in the bottom right corner.

The tim_trgo2 waveform shows how the ADC can be synchronized on given 3-phase PWM signals. Refer to Section 29.3.31: ADC triggers for more details.

29.3.17 Complementary outputs and dead-time insertion

The advanced-control timers (TIM1) can output two complementary signals and manage the switching-off and the switching-on instants of the outputs.

This time is generally known as dead-time and it has to be adjusted depending on the devices that are connected to the outputs and their characteristics (such as intrinsic delays of level-shifters, or delays due to power switches).

The polarity of the outputs (main output tim_ocx or complementary tim_ocxn) can be selected independently for each output. This is done by writing to the CCxP and CCxNP bits in the TIMx_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 TIMx_CCER register and the MOE, OISx, OISxN, OSSI, and OSSR bits in the TIMx_BDTR and TIMx_CR2 registers. Refer to Table 274: Output control bits for complementary tim_ocx and tim_ocxn channels with break feature for more details. In particular, the dead-time is activated when switching to the idle state (MOE falling down to 0).

Dead-time insertion is enabled by setting both CCxE and CCxNE bits, and the MOE bit if the break circuit is present. There is one 10-bit dead-time generator for each channel. From a

reference waveform tim_ocxref , it generates two outputs tim_ocx and tim_ocxn . If tim_ocx and tim_ocxn are active high:

If the delay is greater than the width of the active output ( tim_ocx or tim_ocxn ) then the corresponding pulse is not generated.

The following figures show the relationships between the output signals of the dead-time generator and the reference signal tim_ocxref considering CCxP = 0 , CCxNP = 0 , MOE = 1 , CCxE = 1 and CCxNE = 1 in these examples.

Figure 198. Complementary output with symmetrical dead-time insertion

Timing diagram showing three waveforms: tim_ocxref, tim_ocx, and tim_ocxn. tim_ocxref is a periodic square wave. tim_ocx is a delayed version of tim_ocxref, with its rising edge delayed by 'delay' from the reference rising edge. tim_ocxn is the complement of tim_ocx, with its falling edge delayed by 'delay' from the reference falling edge. The diagram illustrates symmetrical dead-time insertion. A small text 'MSv62332V1' is visible in the bottom right corner of the diagram area.
Timing diagram showing three waveforms: tim_ocxref, tim_ocx, and tim_ocxn. tim_ocxref is a periodic square wave. tim_ocx is a delayed version of tim_ocxref, with its rising edge delayed by 'delay' from the reference rising edge. tim_ocxn is the complement of tim_ocx, with its falling edge delayed by 'delay' from the reference falling edge. The diagram illustrates symmetrical dead-time insertion. A small text 'MSv62332V1' is visible in the bottom right corner of the diagram area.

The DTAE bit in the TIMx_DTR2 is used to differentiate the deadtime values for rising and falling edges of the reference signal, as shown on Figure 199 .

In asymmetrical mode ( DTAE = 1 ), the rising edge-referred deadtime is defined by the DTG[7:0] bitfield in the TIMx_BDTR register, while the falling edge-referred is defined by the DTGF[7:0] bitfield in the TIMx_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 TIMx_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 199. Asymmetrical deadtime

Timing diagram showing symmetrical and asymmetrical deadtime between tim_ocref, tim_ocx, and tim_ocxn signals. The symmetrical section (DTAE = 0) shows equal deadtime intervals labeled DTG[7:0]. The asymmetrical section (DTAE = 1) shows different deadtime intervals labeled DTGF[7:0] and DTG[7:0].

The figure displays two sets of timing diagrams for three signals: tim_ocref , tim_ocx , and tim_ocxn .
The top set, labeled Symmetrical deadtime (DTAE = 0) , shows that when tim_ocref transitions, tim_ocx and tim_ocxn transition simultaneously after a deadtime interval DTG[7:0] .
The bottom set, labeled Asymmetrical deadtime (DTAE = 1) , shows that the deadtime is different for each channel: tim_ocx has a deadtime interval DTGF[7:0] and tim_ocxn has a deadtime interval DTG[7:0] .
The diagram is identified by the code MSv62333V1 .

Timing diagram showing symmetrical and asymmetrical deadtime between tim_ocref, tim_ocx, and tim_ocxn signals. The symmetrical section (DTAE = 0) shows equal deadtime intervals labeled DTG[7:0]. The asymmetrical section (DTAE = 1) shows different deadtime intervals labeled DTGF[7:0] and DTG[7:0].

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

Timing diagram showing dead-time waveforms where the delay is greater than the negative pulse width for tim_ocref, tim_ocx, and tim_ocxn signals.

This timing diagram shows the signals tim_ocref , tim_ocx , and tim_ocxn . It illustrates a scenario where the deadtime delay is greater than the width of the negative pulse of tim_ocref . The delay is explicitly labeled between the falling edge of tim_ocref and the falling edge of tim_ocx . The diagram is identified by the code MSv62334V1 .

Timing diagram showing dead-time waveforms where the delay is greater than the negative pulse width for tim_ocref, tim_ocx, and tim_ocxn signals.

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

Timing diagram showing dead-time waveforms where the delay is greater than the positive pulse width for tim_ocref, tim_ocx, and tim_ocxn signals.

This timing diagram shows the signals tim_ocref , tim_ocx , and tim_ocxn . It illustrates a scenario where the deadtime delay is greater than the width of the positive pulse of tim_ocref . The delay is explicitly labeled between the rising edge of tim_ocref and the rising edge of tim_ocx . The diagram is identified by the code MSv62335V1 .

Timing diagram showing dead-time waveforms where the delay is greater than the positive pulse width for tim_ocref, tim_ocx, and tim_ocxn signals.

The dead-time delay is the same for each of the channels and is programmable with the DTG bits in the TIMx_BDTR register. Refer to Section 29.6.20: TIM1 break and dead-time register (TIM1_BDTR) for delay calculation.

Redirecting tim_ocxref to tim_ocx or tim_ocxn

In output mode (forced, output compare or PWM), tim_ocxref can be redirected to the tim_ocx output or to tim_ocxn output by configuring the CCxE and CCxNE bits in the TIMx_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.

29.3.18 Using the break function

The purpose of the break function is to protect power switches driven by PWM signals generated with the timers. The two break inputs are usually connected to fault outputs of power stages and 3-phase inverters. When activated, the break circuitry shuts down the PWM outputs and forces them to a predefined safe state. A number of internal MCU events can also be selected to trigger an output shut-down.

The break features two channels. A break channel which gathers both system-level fault (clock failure, ECC/parity errors,...) and application fault (from input pins and built-in comparator), and can force the outputs to a predefined level (either active or inactive) after a deadtime duration. A break2 channel which only includes application faults and is able to force the outputs to an inactive state.

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

When exiting from reset, the break circuit is disabled and the MOE bit is low. The break functions can be enabled by setting the BKE and BK2E bits in the TIMx_BDTR register. The break input polarities can be selected by configuring the BKP and BK2P bits in the same register. BKEx and BKPx can be modified at the same time. When the BKEx and BKPx bits are written, a delay of one APB clock cycle is applied before the writing is effective. Consequently, it is necessary to wait one APB clock period to correctly read back the bit after the write operation.

Because MOE falling edge can be asynchronous, a resynchronization circuit has been inserted between the actual signal (acting on the outputs) and the synchronous control bit (accessed in the TIMx_BDTR register). It results in some delays between the asynchronous

and the synchronous signals. In particular, if MOE is set to 1 whereas it was low, a delay must be inserted (dummy instruction) before reading it correctly. This is because the write acts on the asynchronous signal whereas the read reflects the synchronous signal.

The sources for break (tim_brk) channel are:

The sources for break2 (tim_brk2) are:

Break events can also be generated by software using BG and B2G bits in the TIMx_EGR register.

All sources are ORed before entering the timer tim_brk or tim_brk2 inputs, as per Figure 202 below.

Figure 202. Break and Break2 circuitry overview

Figure 202. Break and Break2 circuitry overview. This block diagram illustrates the internal logic for generating break signals in a timer. The top section shows the 'tim_sys_brk' signal generation, which is an OR of five AND gates. Each AND gate takes an 'Enable' input (tim_sys_brk0 through tim_sys_brkx) and a 'CSS' input. The output of this OR gate is connected to the 'SBIF' flag. The middle section shows the 'tim_brk' signal generation. It starts with 'BKINP' and 'TIMx_BKIN from AF controller' inputs. 'BKINP' is inverted and then ANDed with 'BKINE'. 'TIMx_BKIN from AF controller' is also inverted and ANDed with 'BKINE'. These two results are ORed together. The output is then ANDed with 'BKCF[3:0]' (Application break requests) and 'BKP'. This signal is then ANDed with 'BKE' (Software break requests: BG) to produce the 'tim_brk' signal and the 'BIF' flag. The bottom section shows the 'tim_brk2' signal generation, which is a duplicate of the 'tim_brk' section but uses 'BK2INP', 'BK2INE', 'BK2CF[3:0]', 'BK2P', 'BK2E' (Software break requests: B2G), and produces the 'B2IF' flag. The diagram is labeled 'MSv62336V2' in the bottom right corner.
Figure 202. Break and Break2 circuitry overview. This block diagram illustrates the internal logic for generating break signals in a timer. The top section shows the 'tim_sys_brk' signal generation, which is an OR of five AND gates. Each AND gate takes an 'Enable' input (tim_sys_brk0 through tim_sys_brkx) and a 'CSS' input. The output of this OR gate is connected to the 'SBIF' flag. The middle section shows the 'tim_brk' signal generation. It starts with 'BKINP' and 'TIMx_BKIN from AF controller' inputs. 'BKINP' is inverted and then ANDed with 'BKINE'. 'TIMx_BKIN from AF controller' is also inverted and ANDed with 'BKINE'. These two results are ORed together. The output is then ANDed with 'BKCF[3:0]' (Application break requests) and 'BKP'. This signal is then ANDed with 'BKE' (Software break requests: BG) to produce the 'tim_brk' signal and the 'BIF' flag. The bottom section shows the 'tim_brk2' signal generation, which is a duplicate of the 'tim_brk' section but uses 'BK2INP', 'BK2INE', 'BK2CF[3:0]', 'BK2P', 'BK2E' (Software break requests: B2G), and produces the 'B2IF' flag. The diagram is labeled 'MSv62336V2' in the bottom right corner.

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

When one of the breaks occurs (selected level on one of the break inputs):

their active level together. Note that because of the resynchronization on MOE, the dead-time duration is slightly longer than usual (around 2 tim_ker_ck clock cycles).

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

The break inputs are active on level. Thus, the MOE cannot be set while the break input is active (neither automatically nor by software). In the meantime, the status flag BIF and B2IF cannot be cleared.

In addition to the break input and the output management, a write protection has been implemented inside the break circuit to safeguard the application. It is used to freeze the configuration of several parameters (dead-time duration, tim_ocx/tim_ocxn polarities and state when disabled, OCxM configurations, break enable, and polarity). The application can choose from three levels of protection selected by the LOCK bits in the TIMx_BDTR register. Refer to Section 29.6.20 . The LOCK bits can be written only once after an MCU reset.

Figure 203 shows an example of behavior of the outputs in response to a break.

Figure 203. Various output behavior in response to a break event on tim_brk (OSSI = 1)

Timing diagram showing various output behaviors in response to a break event on tim_brk (OSSI = 1).

The diagram illustrates the response of various timer outputs to a break event (MOE \( \downarrow \) ). The break event is indicated by a vertical dashed line. The outputs shown are:

MSv62337V1

Timing diagram showing various output behaviors in response to a break event on tim_brk (OSSI = 1).

The two break inputs have different behaviors on timer outputs:

The tim_brk has a higher priority than tim_brk2 input, as described in Table 267 .

Note: tim_brk2 must only be used with OSSR = OSSI = 1.

Table 267. Behavior of timer outputs versus tim_brk/tim_brk2 inputs

tim_brktim_brk2Timer outputs stateTypical use case
tim_ocxn output (low side switches)tim_ocx output (high side switches)
ActiveX
  • – Inactive then forced output state (after a deadtime)
  • – Outputs disabled if OSSI = 0 (control taken over by GPIO logic)
ON after deadtime insertionOFF
InactiveActiveInactiveOFFOFF

Figure 204 gives an example of tim_ocx and tim_ocxn output behavior in case of active signals on tim_brk and tim_brk2 inputs. In this case, both outputs have active high polarities (CCxP = CCxNP = 0 in TIMx_CCER register).

Figure 204. PWM output state following tim_brk and tim_brk2 assertion (OSSI = 1)

Timing diagram showing the PWM output state following tim_brk and tim_brk2 assertion. The diagram shows four waveforms: tim_brk2, tim_brk, tim_ocx, and tim_ocxn. The I/O state is divided into Active, Inactive, and Idle periods. Deadtime is indicated between the Active and Inactive periods for the output signals.

The timing diagram illustrates the behavior of timer outputs (tim_ocx and tim_ocxn) following the assertion of break inputs (tim_brk and tim_brk2). The diagram is divided into three main I/O states: Active, Inactive, and Idle.
1. Active State: Both tim_brk and tim_brk2 are inactive. The outputs tim_ocx and tim_ocxn are active.
2. Assertion: tim_brk2 goes active first, followed by tim_brk.
3. Inactive State: Both tim_brk and tim_brk2 are active. The outputs tim_ocx and tim_ocxn transition to an inactive state. A 'Deadtime' interval is shown between the active and inactive states for the outputs.
4. Idle State: Both tim_brk and tim_brk2 return to inactive. The outputs remain inactive. Another 'Deadtime' interval is shown before the outputs return to the active state when the break inputs are inactive again.
The diagram also includes a reference to 'MSV62338V1' in the bottom right corner.

Timing diagram showing the PWM output state following tim_brk and tim_brk2 assertion. The diagram shows four waveforms: tim_brk2, tim_brk, tim_ocx, and tim_ocxn. The I/O state is divided into Active, Inactive, and Idle periods. Deadtime is indicated between the Active and Inactive periods for the output signals.
Figure 205. PWM output state following tim_brk assertion (OSSI = 0) Timing diagram showing the PWM output state following a break assertion. The diagram illustrates the relationship between the break input (tim_brk), the active output (tim_ocx), and the inactive output (tim_ocxn) across three phases: Active, Inactive, and Disabled. During the Active phase, tim_ocx is high and tim_ocxn is low. When tim_brk goes low, a deadtime interval occurs where both outputs are high-impedance (HI-Z). After the break assertion, in the Disabled phase, both outputs remain in the HI-Z state as defined by the GPIO controller.

The diagram shows three horizontal signal lines: tim_brk , tim_ocx , and tim_ocxn . The tim_brk line is shown going from a high state to a low state. The tim_ocx and tim_ocxn lines show their states over time, divided into three regions: 'Active', 'Inactive', and 'Disabled'. In the 'Active' region, tim_ocx is high and tim_ocxn is low. When tim_brk asserts (goes low), a 'Deadtime' interval is indicated by a double-headed arrow. During this deadtime, both tim_ocx and tim_ocxn are in a high-impedance (HI-Z) state. In the 'Disabled' region, after the break assertion, both outputs remain in the HI-Z state, labeled as 'I/O state defined by the GPIO controller (HI-Z)'. The diagram is labeled with 'MSv62339V1' in the bottom right corner.

Timing diagram showing the PWM output state following a break assertion. The diagram illustrates the relationship between the break input (tim_brk), the active output (tim_ocx), and the inactive output (tim_ocxn) across three phases: Active, Inactive, and Disabled. During the Active phase, tim_ocx is high and tim_ocxn is low. When tim_brk goes low, a deadtime interval occurs where both outputs are high-impedance (HI-Z). After the break assertion, in the Disabled phase, both outputs remain in the HI-Z state as defined by the GPIO controller.

29.3.19 Bidirectional break inputs

The TIM1 features bidirectional break I/Os, as represented on Figure 206 .

This provides support for:

The tim_brk and tim_brk2 inputs are configured in bidirectional mode using the BKBID and BK2BID bits in the TIMxBDTR register. The BKBID programming bits can be locked in read-only mode using the LOCK bits in the TIMxBDTR register (in LOCK level 1 or above).

The bidirectional mode is available for both the tim_brk and tim_brk2 inputs, and require the I/O to be configured in open-drain mode with active low polarity (using BKINP , BKP , BK2INP and BK2P bits). Any break request coming either from system (for example CSS ), from on-chip peripherals, or from break inputs forces a low level on the break input to signal the fault event. The bidirectional mode is inhibited if the polarity bits are not correctly set (active high polarity), for safety purposes.

The break software events ( BG and B2G ) also cause the break I/O to be forced to 0 to indicate to the external components that the timer is entered in break state. However, this is valid only if the break is enabled ( BKE or B2KE = 1). When a software break event is generated with BKE or B2KE = 0, the outputs are put in safe state and the break flag is set, but there is no effect on the TIMx_BKIN and TIMx_BKIN2 I/Os.

A safe disarming mechanism prevents the system to be definitively locked-up (a low level on the break input triggers a break which enforces a low level on the same input).

When the BKDSRM ( BK2DSRM ) bit is set to 1, this releases the break output to clear a fault signal and to give the possibility to re-arm the system.

At no point the break protection circuitry can be disabled:

Table 268. Break protection disarming conditions

MOEBKBID
(BK2BID)
BKDSRM
(BK2DSRM)
Break 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 (break2) 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 206. Output redirection (tim_brk2 request not represented)

Figure 206. Output redirection (tim_brk2 request not represented). This block diagram illustrates the internal logic for break protection. On the left, 'Other break inputs' and a 'Bidirectional Break I/O TIM_BKIN' are shown. The TIM_BKIN has an 'AF input (active low)' and an 'AF output (open drain)' connected to Vss. These inputs feed into an 'AF controller'. The AF controller outputs 'tim_brk_cmp[8:1]' and 'BKIN inputs from AF controller'. The 'tim_brk_cmp[8:1]' signal passes through an OR gate, then a 'Filter' block, then a 'BKP' block, and finally an AND gate. The 'BKIN inputs from AF controller' also pass through this AND gate. The output of the AND gate is labeled 'Application break requests' and connects to a 'tim_sys_brk' line which leads to an 'SBIF flag'. Below the AND gate, there is a 'Bidirectional mode control logic' block. This block receives 'System break request' and 'tim_brk request' signals and has control inputs 'MOE', 'BKBID', and 'BKDSRM'. The output of this logic block connects to a 'BKE' input of the AND gate. Additionally, 'Software break requests: BG' and a 'BIF flag' are shown as inputs to an OR gate that generates the 'BRK request' signal, which is also labeled 'tim_brk'.
Figure 206. Output redirection (tim_brk2 request not represented). This block diagram illustrates the internal logic for break protection. On the left, 'Other break inputs' and a 'Bidirectional Break I/O TIM_BKIN' are shown. The TIM_BKIN has an 'AF input (active low)' and an 'AF output (open drain)' connected to Vss. These inputs feed into an 'AF controller'. The AF controller outputs 'tim_brk_cmp[8:1]' and 'BKIN inputs from AF controller'. The 'tim_brk_cmp[8:1]' signal passes through an OR gate, then a 'Filter' block, then a 'BKP' block, and finally an AND gate. The 'BKIN inputs from AF controller' also pass through this AND gate. The output of the AND gate is labeled 'Application break requests' and connects to a 'tim_sys_brk' line which leads to an 'SBIF flag'. Below the AND gate, there is a 'Bidirectional mode control logic' block. This block receives 'System break request' and 'tim_brk request' signals and has control inputs 'MOE', 'BKBID', and 'BKDSRM'. The output of this logic block connects to a 'BKE' input of the AND gate. Additionally, 'Software break requests: BG' and a 'BIF flag' are shown as inputs to an OR gate that generates the 'BRK request' signal, which is also labeled 'tim_brk'.

29.3.20 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 TIMx_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 does not work in Forced mode. tim_ocref_clr_int input can be selected between the tim_ocref_clr input and tim_etrf ( tim_etr_in after the filter) by configuring the OCCS bit in the TIMx_SMCR register.

The tim_ocref_clr input can be selected among several inputs, using the OCRSEL[2:0] bitfield in the TIMx_AF2 register, as shown on the Figure 207 below. Refer to Section 29.3.2: TIM1 pins and internal signals for a list of sources available in the product.

Figure 207. tim_ocref_clr input selection multiplexer

Figure 207: tim_ocref_clr input selection multiplexer diagram. The diagram shows two multiplexers. The first multiplexer has eight inputs labeled tim_ocref_clr0 through tim_ocref_clr7. Its output is labeled tim_ocref_clr. This output is connected to the second multiplexer. The second multiplexer also has an input labeled tim_etrf. Its output is labeled tim_ocref_clr_int. The first multiplexer is controlled by the OCRSEL[2:0] bitfield in the TIMx_AF2 register. The second multiplexer is controlled by the OCCS bit in the TIMx_SMCR register. A small text 'MSV62341V2' is in the bottom right corner of the diagram box.

MSV62341V2

Figure 207: tim_ocref_clr input selection multiplexer diagram. The diagram shows two multiplexers. The first multiplexer has eight inputs labeled tim_ocref_clr0 through tim_ocref_clr7. Its output is labeled tim_ocref_clr. This output is connected to the second multiplexer. The second multiplexer also has an input labeled tim_etrf. Its output is labeled tim_ocref_clr_int. The first multiplexer is controlled by the OCRSEL[2:0] bitfield in the TIMx_AF2 register. The second multiplexer is controlled by the OCCS bit in the TIMx_SMCR register. A small text 'MSV62341V2' is in the bottom right corner of the diagram box.

When tim_etrf is chosen, tim_etr_in must be configured as follows:

  1. 1. The external trigger prescaler must be kept off: bits ETPS[1:0] of the TIMx_SMCR register set to 00.
  2. 2. The external clock mode 2 must be disabled: bit ECE of the TIMx_SMCR register set to 0.
  3. 3. The external trigger polarity ( ETP ) and the external trigger filter ( ETF ) can be configured according to application needs (as per polarity of the source connected to the trigger and eventual need to remove noise using the filter).

Figure 208 shows the behavior of the tim_ocxref signal when the tim_etrf input becomes high, for both values of the enable bit OCxCE . In this example, the timer TIMx is programmed in PWM mode.

Figure 208. Clearing TIMx tim_ocxref

Timing diagram showing Counter (CNT) with CCRx threshold, tim_etrf signal, and tim_ocxref output for OCxCE = '0' and OCxCE = '1'. Annotations show tim_ocref_clr_int becoming high and staying high.

The diagram illustrates the relationship between the Counter (CNT), the external trigger (tim_etrf), and the output compare reference (tim_ocxref). The counter (CNT) is shown as a sawtooth wave with a compare register (CCRx) threshold. The tim_etrf signal is a periodic pulse. The tim_ocxref signal is shown for two cases: OCxCE = '0' and OCxCE = '1'. In the OCxCE = '0' case, the tim_ocxref signal is high when the counter is below the CCRx threshold and low when it is above. In the OCxCE = '1' case, the tim_ocxref signal is low when the counter is below the CCRx threshold and high when it is above. Two arrows point to the tim_ocxref signal in the OCxCE = '1' case, indicating that the tim_ocref_clr_int interrupt becomes high at the first counter overflow and remains high at the second counter overflow.

Timing diagram showing Counter (CNT) with CCRx threshold, tim_etrf signal, and tim_ocxref output for OCxCE = '0' and OCxCE = '1'. Annotations show tim_ocref_clr_int becoming high and staying high.

Note: In case of a PWM with a 100% duty cycle (if CCRx>ARR), then tim_ocxref is enabled again at the next counter overflow.

29.3.21 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 TIMx_EGR register or by hardware (on tim_trgi rising edge).

A flag is set when the COM event occurs (COMIF bit in the TIMx_SR register), which can generate an interrupt (if the COMIE bit is set in the TIMx_DIER register) or a DMA request (if the COMDE bit is set in the TIMx_DIER register).

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

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

Timing diagram for 6-step generation, COM example (OSSR = 1). The diagram shows the relationship between the Counter (CNT), tim_ocxref, COM event, and three examples of output waveforms (tim_ocx, tim_ocxn) over time. The counter (CNT) is shown as a sawtooth wave. The tim_ocxref signal is a periodic square wave. The COM event is a narrow pulse. Example 1 shows tim_ocx and tim_ocxn signals with initial settings CCxE = 1, CCxNE = 0, OCxM = 0010 (forced inactive). After writing OCxM to 0100, tim_ocx becomes a square wave and tim_ocxn becomes a constant high. Example 2 shows tim_ocx and tim_ocxn signals with initial settings CCxE = 1, CCxNE = 0, OCxM = 0100 (forced inactive). After writing CCxNE to 1 and OCxM to 0101, tim_ocx becomes a constant high and tim_ocxn becomes a square wave. Example 3 shows tim_ocx and tim_ocxn signals with initial settings CCxE = 1, CCxNE = 0, OCxM = 0010 (forced inactive). After writing CCxNE to 0 and OCxM to 0100, tim_ocx becomes a square wave and tim_ocxn becomes a constant high. The diagram also includes configuration settings for each example and a note 'Write COM to 1'.

Counter (CNT) (CCRx)

tim_ocxref

COM event

Example 1

tim_ocx

tim_ocxn

CCxE = 1
CCxNE = 0
OCxM = 0010 (forced inactive)

Write OCxM to 0100

CCxE = 1
CCxNE = 0
OCxM = 0100

Example 2

tim_ocx

tim_ocxn

CCxE = 1
CCxNE = 0
OCxM = 0100 (forced inactive)

Write CCxNE to 1 and OCxM to 0101

CCxE = 0
CCxNE = 1
OCxM = 0101

Example 3

tim_ocx

tim_ocxn

CCxE = 1
CCxNE = 0
OCxM = 0010 (forced inactive)

Write CCxNE to 0 and OCxM to 0100

CCxE = 1
CCxNE = 1
OCxM = 0100

Write COM to 1

MSv62343V1

Timing diagram for 6-step generation, COM example (OSSR = 1). The diagram shows the relationship between the Counter (CNT), tim_ocxref, COM event, and three examples of output waveforms (tim_ocx, tim_ocxn) over time. The counter (CNT) is shown as a sawtooth wave. The tim_ocxref signal is a periodic square wave. The COM event is a narrow pulse. Example 1 shows tim_ocx and tim_ocxn signals with initial settings CCxE = 1, CCxNE = 0, OCxM = 0010 (forced inactive). After writing OCxM to 0100, tim_ocx becomes a square wave and tim_ocxn becomes a constant high. Example 2 shows tim_ocx and tim_ocxn signals with initial settings CCxE = 1, CCxNE = 0, OCxM = 0100 (forced inactive). After writing CCxNE to 1 and OCxM to 0101, tim_ocx becomes a constant high and tim_ocxn becomes a square wave. Example 3 shows tim_ocx and tim_ocxn signals with initial settings CCxE = 1, CCxNE = 0, OCxM = 0010 (forced inactive). After writing CCxNE to 0 and OCxM to 0100, tim_ocx becomes a square wave and tim_ocxn becomes a constant high. The diagram also includes configuration settings for each example and a note 'Write COM to 1'.

29.3.22 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 TIMx_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 210. Example of one pulse mode.

Timing diagram for one pulse mode. The diagram shows four waveforms over time (t). 1. tim_ti2: A single positive pulse. 2. tim_oc1ref: A periodic square wave. 3. tim_oc1: A single positive pulse that starts after a delay (t_DELAY) from the rising edge of tim_ti2 and ends when the counter reaches the auto-reload value (TIMx_ARR). 4. Counter: A sawtooth-like waveform that starts at 0 and increases in steps until it reaches the auto-reload value (TIMx_ARR). The time from the start of the counter to the start of the tim_oc1 pulse is labeled t_DELAY. The duration of the tim_oc1 pulse is labeled t_PULSE. The diagram is labeled MSV62344V1.
Timing diagram for one pulse mode. The diagram shows four waveforms over time (t). 1. tim_ti2: A single positive pulse. 2. tim_oc1ref: A periodic square wave. 3. tim_oc1: A single positive pulse that starts after a delay (t_DELAY) from the rising edge of tim_ti2 and ends when the counter reaches the auto-reload value (TIMx_ARR). 4. Counter: A sawtooth-like waveform that starts at 0 and increases in steps until it reaches the auto-reload value (TIMx_ARR). The time from the start of the counter to the start of the tim_oc1 pulse is labeled t_DELAY. The duration of the tim_oc1 pulse is labeled t_PULSE. The diagram is labeled MSV62344V1.

In the following example, the user wants to generate a positive pulse on tim_oc1 with a length of \( t_{PULSE} \) and after a delay of \( t_{DELAY} \) as soon as a positive edge is detected on the tim_ti2 input pin.

Use tim_ti2fp2 as trigger 1:

The OPM waveform is defined by writing the compare registers (taking into account the clock frequency and the counter prescaler).

In this example, the DIR and CMS bits in the TIMx_CR1 register must be low.

Since only one pulse (Single mode) is needed, a 1 must be written in the OPM bit in the TIMx_CR1 register to stop the counter at the next update event (when the counter rolls over

from the autoreload value back to 0). When OPM bit in the TIMx_CR1 register is set to 0, so the Repetitive mode is selected.

Particular case: tim_ocx fast enable:

In One-pulse mode, the edge detection on tim_tix input set the CEN bit which enables the counter. Then the comparison between the counter and the compare value makes the output toggle. But several clock cycles are needed for these operations and it limits the minimum delay \( t_{\text{DELAY min}} \) that can be achieved.

To output a waveform with the minimum delay, the OCxFE bit can be set in the TIMx_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.

29.3.23 Retriggerable One-pulse mode

This mode allows the counter to be started in response to a stimulus and to generate a pulse with a programmable length, but with the following differences with nonretriggerable one-pulse mode described in Section 29.3.22 :

The timer must be in Slave mode, with the bits SMS[3:0] = 1000 (Combined Reset + trigger mode) in the TIMx_SMCR register, and the OCxM[3:0] bits set to 1000 or 1001 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[3:0] and SMS[3:0] bitfields are split into two parts for compatibility reasons, the most significant bit are not contiguous with the three least significant ones.

This mode must not be used with center-aligned PWM modes. It is mandatory to have CMS[1:0] = 00 in TIMx_CR1.

Figure 211. Retriggerable one-pulse mode

Timing diagram for Retriggerable One-pulse mode. The diagram shows three waveforms over time: tim_trgi (trigger), Counter, and tim_ocx (output). The tim_trgi signal has three positive pulses. The Counter signal is a sawtooth wave that starts at 0 on the first trigger and increases linearly until it reaches a horizontal dashed line representing the autoreload value (ARR). If a second trigger occurs before the counter reaches ARR, the counter is reset to 0 and starts increasing again. The third trigger occurs while the counter is still increasing from the second trigger. The tim_ocx signal is a rectangular pulse that goes high when the counter starts and goes low when the counter reaches the ARR value. Due to the retriggering, the second pulse is extended because of the subsequent triggers before it reaches the ARR value.
Timing diagram for Retriggerable One-pulse mode. The diagram shows three waveforms over time: tim_trgi (trigger), Counter, and tim_ocx (output). The tim_trgi signal has three positive pulses. The Counter signal is a sawtooth wave that starts at 0 on the first trigger and increases linearly until it reaches a horizontal dashed line representing the autoreload value (ARR). If a second trigger occurs before the counter reaches ARR, the counter is reset to 0 and starts increasing again. The third trigger occurs while the counter is still increasing from the second trigger. The tim_ocx signal is a rectangular pulse that goes high when the counter starts and goes low when the counter reaches the ARR value. Due to the retriggering, the second pulse is extended because of the subsequent triggers before it reaches the ARR value.

MSv62345V2

29.3.24 Pulse on compare mode

A pulse can be generated upon compare match event. A signal with a programmable pulsewidth generated when the counter value equals a given compare value, for debugging or synchronization purposes.

This mode is available for any slave mode selection, including encoder modes, in edge and center aligned counting modes. It is solely available for channel 3 and channel 4. The pulse generator is unique and is shared by the two channels, as shown on Figure 212 .

Figure 212. Pulse generator circuitry

Figure 212. Pulse generator circuitry diagram

The diagram illustrates the pulse generator circuitry for TIM1 channels 3 and 4. On the left, two 'CCR match' inputs (CCR3 match and CCR4 match) are connected to 'Enable' blocks. These blocks are controlled by configuration registers OC3M and OC4M, both set to 1010. The outputs of these 'Enable' blocks are connected to an OR gate. The output of the OR gate is connected to a 'Pulse generator' block. This block also receives inputs from a 'PWPRSC [2:0]' register and a 'PW[7:0]' register. The output of the 'Pulse generator' is connected to a 'tim_oc3' output through an AND gate and to a 'tim_oc4' output through another AND gate. Each AND gate also receives inputs from an 'R/S' (Reset/Set) flip-flop. The 'R/S' flip-flops are controlled by 'Set' and 'Reset' signals. The 'Reset' signal for the top flip-flop is derived from the 'tim_oc3' output through an inverter. The 'Set' and 'Reset' signals for the bottom flip-flop are derived from the 'tim_oc4' output through an inverter. The diagram is labeled 'MSV62346V1' in the bottom right corner.

Figure 212. Pulse generator circuitry diagram

Figure 213 shows how the pulse is generated for edge-aligned and encoder operating modes.

Figure 213. Pulse generation on compare event, for edge-aligned and encoder modes

Figure 213: Pulse generation on compare event, for edge-aligned and encoder modes. The figure contains two timing diagrams. The top diagram shows the Counter, CMP3, Triggers, and tim_ocx signals. The Counter is a sawtooth wave. CMP3 is a dashed line. Triggers are vertical arrows. tim_ocx is a pulse train. An arrow points to a pulse labeled 'Extended pulsewidth due to re-trigger'. The bottom diagram shows the Counter, CMP3, Triggers, and tim_ocx signals. The Counter is a sawtooth wave. CMP3 is a dashed line. Triggers are vertical arrows. tim_ocx is a pulse train. The signal MSv62347V1 is shown in the bottom right corner.
Figure 213: Pulse generation on compare event, for edge-aligned and encoder modes. The figure contains two timing diagrams. The top diagram shows the Counter, CMP3, Triggers, and tim_ocx signals. The Counter is a sawtooth wave. CMP3 is a dashed line. Triggers are vertical arrows. tim_ocx is a pulse train. An arrow points to a pulse labeled 'Extended pulsewidth due to re-trigger'. The bottom diagram shows the Counter, CMP3, Triggers, and tim_ocx signals. The Counter is a sawtooth wave. CMP3 is a dashed line. Triggers are vertical arrows. tim_ocx is a pulse train. The signal MSv62347V1 is shown in the bottom right corner.

This output compare mode is selected using the OC3M[3:0] and OC4M[3:0] bitfields in TIMx_CCMR2 register.

The pulsewidth is programmed using the PW[7:0] bitfield in the register, using a specific clock prescaled according to PWPRSC[2:0] bits, as follows:

\[ t_{PW} = PW[7:0] \times t_{PWG} \]

\[ \text{where } t_{PWG} = (2^{(PWPRSC[2:0])}) \times t_{tim\_ker\_ck} \]

gives the resolution and maximum values depending on the prescaler value.

The pulse is retriggerable: a new trigger while the pulse is ongoing, causes the pulse to be extended.

Note: If the two channels are enabled simultaneously, the pulses are issued independently as long as the trigger on one channel is not overlapping the pulse generated on the concurrent output. On the opposite, if the two triggers are overlapping, the pulse width related to the first arriving trigger is extended (because of the retrigger), while the pulse width of the last arriving trigger is correct (as shown on Figure 214).

Figure 214. Extended pulsewidth in case of concurrent triggers

Timing diagram showing the effect of concurrent triggers on timer output pulsewidth. The diagram displays four waveforms: Trigger CMP3, Trigger CMP4, tim_oc3, and tim_oc4. Trigger CMP3 and CMP4 are shown as vertical dashed lines representing falling edges. tim_oc3 and tim_oc4 are square waves. The diagram illustrates that when both triggers are active, the pulsewidth of tim_oc3 is extended due to overlapping CMP4 triggers. The text 'Extended pulsewidth due to overlapping CMP4 trigger' is present. The diagram is labeled MSV62348V1.
Timing diagram showing the effect of concurrent triggers on timer output pulsewidth. The diagram displays four waveforms: Trigger CMP3, Trigger CMP4, tim_oc3, and tim_oc4. Trigger CMP3 and CMP4 are shown as vertical dashed lines representing falling edges. tim_oc3 and tim_oc4 are square waves. The diagram illustrates that when both triggers are active, the pulsewidth of tim_oc3 is extended due to overlapping CMP4 triggers. The text 'Extended pulsewidth due to overlapping CMP4 trigger' is present. The diagram is labeled MSV62348V1.

29.3.25 Encoder interface mode

Quadrature encoder

To select Encoder Interface mode write SMS = 0001 in the TIMx_SMCR register if the counter is counting on tim_ti1 edges only, SMS = 0010 if it is counting on tim_ti2 edges only and SMS = 0011 if it is counting on both tim_ti1 and tim_ti2 edges.

Select the tim_ti1 and tim_ti2 polarity by programming the CC1P and CC2P bits in the TIMx_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 an quadrature encoder. Refer to Table 269 . 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 TIMx_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 TIMx_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 TIMx_ARR register (0 to ARR or ARR down to 0 depending on the direction). So the TIMx_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 269. Counting direction versus encoder signals (CC1P = CC2P = 0)

Active edgeSMS[3: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
1110HighDownUpNo countNo count
LowNo countNo countNo countNo count
Counting on tim_ti2 only
x1 mode
1111HighNo countNo countUpDown
LowNo countNo countNo countNo count
Counting on tim_ti1 only
x2 mode
0001HighDownUpNo countNo count
LowUpDownNo countNo count
Counting on tim_ti2 only
x2 mode
0010HighNo countNo countUpDown
LowNo countNo countDownUp
Counting on tim_ti1 and
tim_ti2
x4 mode
0011HighDownUpUpDown
LowUpDownDownUp

A quadrature encoder can be connected directly to the MCU without external interface logic. However, comparators are normally 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 215 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 215. Example of counter operation in encoder interface mode.

Timing diagram for Figure 215 showing forward, jitter, backward, jitter, and forward phases for tim_ti1, tim_ti2, and Counter signals.

This timing diagram illustrates the operation of a timer counter in encoder interface mode. It features three horizontal signal lines: tim_ti1 , tim_ti2 , and Counter . The diagram is divided into five temporal segments: forward , jitter , backward , jitter , and forward . In the first forward segment, tim_ti1 and tim_ti2 are square waves in phase, and the Counter value increases in a staircase pattern, labeled up . In the jitter segment, the signals change irregularly, and the counter value remains constant. In the backward segment, tim_ti1 and tim_ti2 are square waves 180 degrees out of phase, and the Counter value decreases in a staircase pattern, labeled down . The second jitter segment shows another period of signal instability with a constant counter value. The final forward segment shows the signals returning to phase, and the Counter value increases again, labeled up . The diagram is identified by the code MSv62349V1 in the bottom right corner.

Timing diagram for Figure 215 showing forward, jitter, backward, jitter, and forward phases for tim_ti1, tim_ti2, and Counter signals.

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

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

Timing diagram for Figure 216 showing forward, jitter, backward, jitter, and forward phases for tim_ti1, tim_ti2, and Counter signals with inverted polarity for tim_ti1.

This timing diagram shows the counter behavior with the tim_ti1fp1 polarity inverted. It follows the same five segments as Figure 215: forward , jitter , backward , jitter , and forward . In the first forward segment, tim_ti1 is inverted compared to Figure 215, and the Counter value decreases, labeled down . In the jitter segment, the counter value is constant. In the backward segment, the counter value increases, labeled up . The second jitter segment shows constant counter value. The final forward segment shows the counter value decreasing again, labeled down . The diagram is identified by the code MSv62350V1 in the bottom right corner.

Timing diagram for Figure 216 showing forward, jitter, backward, jitter, and forward phases for tim_ti1, tim_ti2, and Counter signals with inverted polarity for tim_ti1.

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

Figure 217. Quadrature encoder counting modes

Timing diagram showing quadrature encoder counting modes. It displays three signal traces: tim_ti1 (square wave), tim_ti2 (square wave phase-shifted from tim_ti1), and DIR bit (direction indicator). Below these are three counter value sequences: Counter x4, Counter x2, and Counter x1. Counter x4 shows a sequence of 16 values: 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2. Counter x2 shows a sequence of 12 values: 8, 9, 0, 1, 2, 1, 0, 9, 8, 7, 6. Counter x1 shows a sequence of 6 values: 9, 0, 1, 0, 9, 8. Vertical dashed lines indicate the relationship between encoder events and counter updates. The diagram is labeled MSV62351V1 in the bottom right corner.
Timing diagram showing quadrature encoder counting modes. It displays three signal traces: tim_ti1 (square wave), tim_ti2 (square wave phase-shifted from tim_ti1), and DIR bit (direction indicator). Below these are three counter value sequences: Counter x4, Counter x2, and Counter x1. Counter x4 shows a sequence of 16 values: 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2. Counter x2 shows a sequence of 12 values: 8, 9, 0, 1, 2, 1, 0, 9, 8, 7, 6. Counter x1 shows a sequence of 6 values: 9, 0, 1, 0, 9, 8. Vertical dashed lines indicate the relationship between encoder events and counter updates. The diagram is labeled MSV62351V1 in the bottom right corner.

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 TIMx_CR1 register forces a continuous copy of the update interrupt flag (UIF) into the timer counter register's bit 31 (TIMxCNT[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 218, 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[3:0] bitfield in the TIMx_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 218. Direction plus clock encoder mode

Timing diagram for Figure 218: Direction plus clock encoder mode. The diagram shows four waveforms over time. The top waveform is tim_ti1, which is high during the first half and low during the second half. The second waveform is tim_ti2, a periodic square wave. The third waveform, labeled 'Counter x2 mode', shows the counter value increasing from 6 to 11 and then decreasing back to 6, with updates occurring on both rising and falling edges of tim_ti2. The bottom waveform, labeled 'Counter x1 mode', shows the counter value increasing from 6 to 9 and then decreasing back to 6, with updates occurring only on falling edges of tim_ti2. A label 'MSv62352V1' is in the bottom right corner.
Timing diagram for Figure 218: Direction plus clock encoder mode. The diagram shows four waveforms over time. The top waveform is tim_ti1, which is high during the first half and low during the second half. The second waveform is tim_ti2, a periodic square wave. The third waveform, labeled 'Counter x2 mode', shows the counter value increasing from 6 to 11 and then decreasing back to 6, with updates occurring on both rising and falling edges of tim_ti2. The bottom waveform, labeled 'Counter x1 mode', shows the counter value increasing from 6 to 9 and then decreasing back to 6, with updates occurring only on falling edges of tim_ti2. A label 'MSv62352V1' is in the bottom right corner.

Directional clock encoder mode

In the directional clock mode on Figure 219 , 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[3:0] bitfield in the TIMx_SMCR register, as following:

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

Timing diagram for Figure 219: Directional clock encoder mode (CC1P = CC2P = 0). The diagram shows five waveforms over time. The top waveform is tim_ti1, which is high during the first half and low during the second half. The second waveform is tim_ti2, a periodic square wave. The third waveform is the DIR bit, which is high during the first half and low during the second half. The fourth waveform, labeled 'Counter x2 mode', shows the counter value increasing from 6 to 11 and then decreasing back to 5, with updates occurring on both rising and falling edges of tim_ti2. The bottom waveform, labeled 'Counter x1 mode', shows the counter value increasing from 6 to 8 and then decreasing back to 5, with updates occurring only on falling edges of tim_ti2. A label 'MSv62353V1' is in the bottom right corner.
Timing diagram for Figure 219: Directional clock encoder mode (CC1P = CC2P = 0). The diagram shows five waveforms over time. The top waveform is tim_ti1, which is high during the first half and low during the second half. The second waveform is tim_ti2, a periodic square wave. The third waveform is the DIR bit, which is high during the first half and low during the second half. The fourth waveform, labeled 'Counter x2 mode', shows the counter value increasing from 6 to 11 and then decreasing back to 5, with updates occurring on both rising and falling edges of tim_ti2. The bottom waveform, labeled 'Counter x1 mode', shows the counter value increasing from 6 to 8 and then decreasing back to 5, with updates occurring only on falling edges of tim_ti2. A label 'MSv62353V1' is in the bottom right corner.

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

Timing diagram for Figure 220 showing tim_ti1, tim_ti2, DIR bit, Counter x2 mode, and Counter x1 mode signals over time. The diagram shows two square waves, tim_ti1 and tim_ti2, and a DIR bit. Below them, two counter modes are shown: Counter x2 mode and Counter x1 mode. Counter x2 mode counts from 6 to 11, then back down to 5. Counter x1 mode counts from 7 to 9, then back down to 6. Vertical dashed lines indicate the relationship between the input signals and the counter values.
Timing diagram for Figure 220 showing tim_ti1, tim_ti2, DIR bit, Counter x2 mode, and Counter x1 mode signals over time. The diagram shows two square waves, tim_ti1 and tim_ti2, and a DIR bit. Below them, two counter modes are shown: Counter x2 mode and Counter x1 mode. Counter x2 mode counts from 6 to 11, then back down to 5. Counter x1 mode counts from 7 to 9, then back down to 6. Vertical dashed lines indicate the relationship between the input signals and the counter values.

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

Table 270. Counting direction versus encoder signals and polarity settings

Directional clock modeSMS[3: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
1100HighDownDownUpUp
LowNo countNo countNo countNo count
x2 mode
CCxP = 1
1100HighNo countNo countNo countNo count
LowDownDownUpUp
x1 mode
CCxP = 0
1101HighNo countDownNo countUp
LowNo countNo countNo countNo count
x1 mode
CCxP = 1
1101HighNo countNo countNo countNo count
LowDownNo countUpNo count

Index input

The counter can be reset by an index signal coming from the encoder, indicating an absolute reference position. The index signal must be connected to the tim_etr_in input. It can be filtered using the digital input filter.

The index functionality is enabled with the IE bit in the TIMX_ECR register. The IE bit must be set only in encoder mode, when the SMS[3:0] bitfield has the following values: 0001, 0010, 011, 1010, 1011, 1100, 1101, 1110, 1111.

Available encoders are proposed with several options for index pulse conditioning, as per Figure 221 :

Figure 221. Index gating options

Timing diagram showing five waveforms: Channel A, Channel B, Gated A & B, Gated A, and Ungated. Channel A and B are square waves. Gated A & B is high only when both A and B are high. Gated A is high when A is high and B is high. Ungated is high when A is high. Vertical dashed lines indicate alignment points. MSV45765V1 is noted in the bottom right.

Timing diagram illustrating the index gating options. The diagram shows five waveforms: Channel A, Channel B, Gated A & B, Gated A, and Ungated. Channel A and B are square waves. Gated A & B is high only when both A and B are high. Gated A is high when A is high and B is high. Ungated is high when A is high. Vertical dashed lines indicate alignment points. MSV45765V1 is noted in the bottom right.

Timing diagram showing five waveforms: Channel A, Channel B, Gated A & B, Gated A, and Ungated. Channel A and B are square waves. Gated A & B is high only when both A and B are high. Gated A is high when A is high and B is high. Ungated is high when A is high. Vertical dashed lines indicate alignment points. MSV45765V1 is noted in the bottom right.

The circuitry tolerates jitter on index signal, whatever the gating mode, as shown on Figure 222 .

In ungated mode, the signal must be strictly below two encoder periods. If the pulselength is greater or equal to two encoder periods, the counter is reset multiple times.

Figure 222. Jittered Index signals

Timing diagram showing five waveforms: Channel A, Channel B, Gated A & B, Gated A, and Ungated. Channel A and B are square waves. Gated A & B, Gated A, and Ungated show jittered signals. A double-headed arrow labeled 'Max pulselength ungated mode' spans two periods of Channel A. MSV45766V1 is noted in the bottom right.

Timing diagram illustrating jittered index signals. The diagram shows five waveforms: Channel A, Channel B, Gated A & B, Gated A, and Ungated. Channel A and B are square waves. Gated A & B, Gated A, and Ungated show jittered signals. A double-headed arrow labeled "Max pulselength ungated mode" spans two periods of Channel A. MSV45766V1 is noted in the bottom right.

Timing diagram showing five waveforms: Channel A, Channel B, Gated A & B, Gated A, and Ungated. Channel A and B are square waves. Gated A & B, Gated A, and Ungated show jittered signals. A double-headed arrow labeled 'Max pulselength ungated mode' spans two periods of Channel A. MSV45766V1 is noted in the bottom right.

The timer supports the three gating options identically, without any specific programming needed. It is only necessary to define on which encoder state (for example channel A and

channel B state combination) the index must be synchronized, using the IPOS[1:0] bitfield in the TIMx_ECR register.

The index detection event acts differently depending on counting direction to ensure symmetrical operation during speed reversal:

This allows the index to be generated on the very same mechanical angular position whatever the counting direction. Figure 223 shows at which position is the index generated, for a simplistic example (an encoder providing four edges par mechanical rotation).

Figure 223. Index generation for IPOS[1:0] = 11

Figure 223: Index generation for IPOS[1:0] = 11. A state transition diagram showing four states: State 1 (AB = 00) at 0°, State 2 (AB = 01) at 90°, State 3 (AB = 11) at 180°, and State 4 (AB = 10) at 270°. Arrows indicate up-counting (1→2→3→4→1) and down-counting (1→4→3→2→1). An arrow points to the transition from State 4 to State 1, labeled 'The index event is always generated here'.

MSv45767V1

Figure 223: Index generation for IPOS[1:0] = 11. A state transition diagram showing four states: State 1 (AB = 00) at 0°, State 2 (AB = 01) at 90°, State 3 (AB = 11) at 180°, and State 4 (AB = 10) at 270°. Arrows indicate up-counting (1→2→3→4→1) and down-counting (1→4→3→2→1). An arrow points to the transition from State 4 to State 1, labeled 'The index event is always generated here'.

Figure 224 presents waveforms and corresponding values for IPOS[1:0] = 11. It shows that the instant at which the counter value is forced is automatically adjusted depending on the counting direction:

An interrupt can be issued upon index detection event.

The arrows are indicating on which transition is the index event interrupt generated.

Figure 224. Counter reading with index gated on channel A (IPOS[1:0] = 11)

Figure 224: Counter reading with index gated on channel A (IPOS[1:0] = 11). A timing diagram showing Channel A, Channel B, Index, DIR bit, and Counter. The counter counts up from 5 to 7, then resets to 0 at the first rising edge of Channel A following an Index pulse. It then counts up to 6. When the DIR bit goes high, the counter counts down from 6 to 1. At the next rising edge of Channel A following an Index pulse, it resets to 0 and counts up again. Arrows indicate the counter reset points.

MSv45768V1

Figure 224: Counter reading with index gated on channel A (IPOS[1:0] = 11). A timing diagram showing Channel A, Channel B, Index, DIR bit, and Counter. The counter counts up from 5 to 7, then resets to 0 at the first rising edge of Channel A following an Index pulse. It then counts up to 6. When the DIR bit goes high, the counter counts down from 6 to 1. At the next rising edge of Channel A following an Index pulse, it resets to 0 and counts up again. Arrows indicate the counter reset points.

Figure 225. presents waveforms and corresponding values for the ungated mode. The arrows are indicating on which transition is the index event generated.

Timing diagram for ungated mode showing Channel A, Channel B, Index, DIR bit, and Counter waveforms. The counter sequence is 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 7. Arrows indicate index events at the falling edge of Channel B when DIR is high, and at the rising edge of Channel B when DIR is low.

Figure 225. Counter reading with index ungated (IPOS[1:0] = 00)

MSv45769V1

Timing diagram for ungated mode showing Channel A, Channel B, Index, DIR bit, and Counter waveforms. The counter sequence is 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 7. Arrows indicate index events at the falling edge of Channel B when DIR is high, and at the rising edge of Channel B when DIR is low.

Figure 226. shows how the 'gated on A & B' mode is handled, for various pulse alignment scenario. The arrows are indicating on which transition is the index event generated.

Timing diagram for gated mode showing Channel A, Channel B, Index, DIR bit, and Counter waveforms. The counter sequence is 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1. Arrows indicate index events at the falling edge of Channel B when DIR is high, and at the rising edge of Channel B when DIR is low, but only if Channel A is high at that time.

Figure 226. Counter reading with index gated on channel A and B

MSv45770V1

Timing diagram for gated mode showing Channel A, Channel B, Index, DIR bit, and Counter waveforms. The counter sequence is 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1. Arrows indicate index events at the falling edge of Channel B when DIR is high, and at the rising edge of Channel B when DIR is low, but only if Channel A is high at that time.

Figure 227 and Figure 228 detail the case where the subsequent index pulse may be narrower than one quarter of the encoder clock period.

Figure 227. Encoder mode behavior in case of narrow index pulse (IPOS[1:0] = 11)

Timing diagrams for encoder mode behavior with narrow index pulse. Top diagram: 'Index leading state transition' shows Channel A, Channel B, Index, DIR bit, and Counter. Bottom diagram: 'Index delayed versus state transition' shows the same signals with a delay in the Index pulse.

The figure consists of two timing diagrams illustrating the behavior of an encoder mode timer (TIM1) when a narrow index pulse is present (IPOS[1:0] = 11). Both diagrams show five signals over time: Channel A, Channel B, Index, DIR bit, and Counter.

Top Diagram: Index leading state transition

Bottom Diagram: Index delayed versus state transition

MSv45771V1

Timing diagrams for encoder mode behavior with narrow index pulse. Top diagram: 'Index leading state transition' shows Channel A, Channel B, Index, DIR bit, and Counter. Bottom diagram: 'Index delayed versus state transition' shows the same signals with a delay in the Index pulse.

Figure 228. Counter reset Narrow index pulse (closer view, ARR = 0x07)

Timing diagram showing two instances of counter reset by a narrow index pulse. The diagram includes signals for Channel A, Channel B, Index, DIR bit, and Counter. In the top instance, the counter counts 5, 6, 7, then resets to 0 upon an index pulse, continuing with 1, 2, 3. In the bottom instance, it counts 4, 5, 6, then resets to 0, continuing with 1, 2, 3. Arrows indicate the reset action from the Index pulse to the Counter value 0.

The figure displays two timing diagrams illustrating the counter reset behavior triggered by a narrow index pulse. Both diagrams show the following signals over time:

Arrows in both diagrams point from the rising edge of the Index pulse to the counter value 0, indicating the reset action. The text "MSV45772V1" is visible in the bottom right corner of the diagram area.

Timing diagram showing two instances of counter reset by a narrow index pulse. The diagram includes signals for Channel A, Channel B, Index, DIR bit, and Counter. In the top instance, the counter counts 5, 6, 7, then resets to 0 upon an index pulse, continuing with 1, 2, 3. In the bottom instance, it counts 4, 5, 6, then resets to 0, continuing with 1, 2, 3. Arrows indicate the reset action from the Index pulse to the Counter value 0.

Figure 229 shows how the index is managed in x1 and x2 modes.

Figure 229. Index behavior in x1 and x2 mode (IPOS[1:0] = 01)

Timing diagram showing Channel A, Channel B, Index, DIR bit, Counter x2, and Counter x1. Channel A and B are square waves. Index is high when both A and B are high. DIR bit is high for up-counting. Counter x2 counts 10, 11, 0, 1, 2, 1, 0, 11, 10, 9, 8. Counter x1 counts 5, 6, 7, 0, 1, 3. Arrows show index pulses resetting the counters.

AB = IPOS[1:0] = 01

Channel A

Channel B

Index

DIR bit

Counter x2: 10, 11, 0, 1, 2, 1, 0, 11, 10, 9, 8

Counter x1: 5, 6, 7, 0, 1, 3

MSv45773V1

Timing diagram showing Channel A, Channel B, Index, DIR bit, Counter x2, and Counter x1. Channel A and B are square waves. Index is high when both A and B are high. DIR bit is high for up-counting. Counter x2 counts 10, 11, 0, 1, 2, 1, 0, 11, 10, 9, 8. Counter x1 counts 5, 6, 7, 0, 1, 3. Arrows show index pulses resetting the counters.

Directional index sensitivity

The IDIR[1:0] bitfield in the TIMx_ECR register allows the index to be active only in a selected counting direction.

Figure 230 shows the relationship between index and counter reset events, depending on IDIR[1:0] value.

Figure 230. Directional index sensitivity

Timing diagram showing DIR bit (UP-counting and Down-counting), Counter (sawtooth waves), Index input, and Counter reset signals for IDIR[1:0] = 00, 01, and 10. Counter reset only occurs on index pulses when the direction matches the IDIR setting.

DIR bit: UP-counting, Down-counting

Counter

Index input

Counter reset

IDIR[1:0]=00

IDIR[1:0]=01

IDIR[1:0]=10

MSv45774V1

Timing diagram showing DIR bit (UP-counting and Down-counting), Counter (sawtooth waves), Index input, and Counter reset signals for IDIR[1:0] = 00, 01, and 10. Counter reset only occurs on index pulses when the direction matches the IDIR setting.

Special first index event management

The FIDX bit in the TIMx_ECR register allows the index to be taken only once, as shown on Figure 231 . Once the first index has arrived, any subsequent index is ignored. If needed, the circuitry can be rearmed by writing the FIDX bit to 0 and setting it again to 1.

Figure 231. Counter reset as function of FIDX bit setting

Timing diagram for Figure 231 showing counter reset behavior with FIDX bit settings.

This timing diagram illustrates the counter reset behavior based on the FIDX bit setting. It consists of four horizontal signal lines:

The diagram is labeled with 'MSv45775V1' in the bottom right corner.

Timing diagram for Figure 231 showing counter reset behavior with FIDX bit settings.

Index blanking

The index event can be blanked using the tim_ti3 or tim_ti4 inputs. During the blanking window, the index events are no longer resetting the counter, as shown on the Figure 232 below.

This mode is enabled using the IBLK[1:0] bitfield in the TIMx_ECR register, as following:

Figure 232. Index blanking

Timing diagram for Figure 232 showing index blanking behavior.

This timing diagram illustrates the index blanking behavior. It consists of five horizontal signal lines:

The diagram is labeled with 'MSv45776V1' in the bottom right corner.

Timing diagram for Figure 232 showing index blanking behavior.

Index management in nonquadrature mode

Figure 233 and Figure 234 detail how the index is managed in directional clock mode and clock plus direction mode, when the SMS[3:0] bitfield is equal to 1010, 1011, 1100, 1101.

For both of these modes, the index sensitivity is set with the IPOS[0] bit as following:

The IPOS[1] bit is not-significant.

Figure 233. Index behavior in clock + direction mode, IPOS[0] = 1

Timing diagram for Figure 233 showing index behavior in clock + direction mode with IPOS[0] = 1. The diagram includes waveforms for tim_ti1, tim_ti2, Index, Counter x2 mode, and Counter x1 mode. Counter x2 mode counts 7, 0, 1, 2, 3, 4, 3, 2, 7, 6, 5. Counter x1 mode counts 7, 0, 1, 2, 1, 7. The Index pulse is shown rising on the falling edge of tim_ti2 when tim_ti1 is high.

The diagram illustrates the relationship between timer inputs and counter values. tim_ti1 is a signal that is high during the first half of the sequence and low during the second half. tim_ti2 is a square wave. The Index signal is a pulse that goes high when tim_ti2 has a falling edge and tim_ti1 is high. The Counter x2 mode shows a sequence of values: 7, 0, 1, 2, 3, 4, 3, 2, 7, 6, 5. The Counter x1 mode shows a sequence of values: 7, 0, 1, 2, 1, 7. Arrows indicate the correspondence between counter values and input transitions.

Timing diagram for Figure 233 showing index behavior in clock + direction mode with IPOS[0] = 1. The diagram includes waveforms for tim_ti1, tim_ti2, Index, Counter x2 mode, and Counter x1 mode. Counter x2 mode counts 7, 0, 1, 2, 3, 4, 3, 2, 7, 6, 5. Counter x1 mode counts 7, 0, 1, 2, 1, 7. The Index pulse is shown rising on the falling edge of tim_ti2 when tim_ti1 is high.

Figure 234. Index behavior in directional clock mode, IPOS[0] = 1

Timing diagram for Figure 234 showing index behavior in directional clock mode with IPOS[0] = 1. The diagram includes waveforms for tim_ti1, tim_ti2, DIR bit, Counter x2 mode, and Counter x1 mode. Counter x2 mode counts 9, 0, 1, 2, 3, 4, 3, 2, 1, 0, 9, 8. Counter x1 mode counts 9, 0, 1, 2, 1, 0, 9. The DIR bit is high when tim_ti1 is high. The Index pulse is shown rising on the falling edge of tim_ti2 when tim_ti1 is high.

This diagram shows the index behavior in directional clock mode. It includes a DIR bit signal that is high when tim_ti1 is high. The Index pulse goes high on the falling edge of tim_ti2 when tim_ti1 is high. The Counter x2 mode sequence is 9, 0, 1, 2, 3, 4, 3, 2, 1, 0, 9, 8. The Counter x1 mode sequence is 9, 0, 1, 2, 1, 0, 9.

Timing diagram for Figure 234 showing index behavior in directional clock mode with IPOS[0] = 1. The diagram includes waveforms for tim_ti1, tim_ti2, DIR bit, Counter x2 mode, and Counter x1 mode. Counter x2 mode counts 9, 0, 1, 2, 3, 4, 3, 2, 1, 0, 9, 8. Counter x1 mode counts 9, 0, 1, 2, 1, 0, 9. The DIR bit is high when tim_ti1 is high. The Index pulse is shown rising on the falling edge of tim_ti2 when tim_ti1 is high.

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 235. A single bit is expected to change at once. An erroneous transition sets the TERRF interrupt flag in the TIMx_SR

status register. A transition error interrupt is generated if the TERRIE bit is set in the TIMx_DIER register.

Figure 235. State diagram for quadrature encoded signals

State diagram for quadrature encoded signals showing four states (00, 01, 10, 11) and their transitions.

The diagram illustrates the state transitions for quadrature encoded signals. It features four circular nodes arranged in a square, labeled 00 (top-left), 01 (top-right), 10 (bottom-left), and 11 (bottom-right). Solid double-headed arrows represent correct transitions between adjacent states: 00 to 01, 01 to 11, 11 to 10, and 10 to 00. Dashed double-headed arrows represent erroneous transitions between diagonal states: 00 to 11 and 10 to 01. A legend at the bottom left shows a solid arrow for 'Correct transitions' and a dashed arrow for 'Erroneous transitions'. The code MSv45779V1 is in the bottom right corner.

State diagram for quadrature encoded signals showing four states (00, 01, 10, 11) and their transitions.

For encoder having an index signal, it is possible to detect abnormal operation resulting in an excess of pulses per revolution. An encoder with N pulses per revolution provides \( 4 \times N \) counts per revolution. The index signal resets the counter every \( 4 \times N \) clock periods.

If the counter value is incremented from TIMx_ARR to 0 or decremented from 0 to TIMx_ARR value without any index event, this is reported as an index position error.

The overflow threshold is programmed using the TIMx_ARR register. A 1000 lines encoder results in a counter value being between 0 and 3999 (in 4x reading mode). The overflow detection threshold must be programmed by setting \( \text{TIMx\_ARR} = 3999 + 1 = 4000 \) .

The error assertion is delayed to the transition 0 to 1 when in up-counting. This is cope with narrow index pulses in gated A and B mode, as shown on Figure 236 .

Figure 236. Up-counting encoder error detection

Timing diagram showing up-counting encoder error detection in two scenarios. Both scenarios show signals tim_ti1, tim_ti2, Index, IERRF, and a Counter sequence 5, 6, 7, 0, 1, 2, 3. In the top scenario, an index pulse occurs between counter values 7 and 0; 'Error detected' is marked at the 0 to 1 transition, and 'Abort (index detection)' is marked at the index pulse. In the bottom scenario, IERRF goes high at the 0 to 1 transition, where both 'Error detected' and 'Error asserted' are marked.

The figure illustrates the timing for up-counting encoder error detection. It is divided into two horizontal sections.

Top Section:

Bottom Section:

MSV62357V1

Timing diagram showing up-counting encoder error detection in two scenarios. Both scenarios show signals tim_ti1, tim_ti2, Index, IERRF, and a Counter sequence 5, 6, 7, 0, 1, 2, 3. In the top scenario, an index pulse occurs between counter values 7 and 0; 'Error detected' is marked at the 0 to 1 transition, and 'Abort (index detection)' is marked at the index pulse. In the bottom scenario, IERRF goes high at the 0 to 1 transition, where both 'Error detected' and 'Error asserted' are marked.

In down-counting mode, the detection is conditioned by a preliminary transition from 1 to 0. This is to cope with narrow index pulses in gated A and B mode, as shown on Figure 237 , to avoid any false error detection in case the encoder dithers between TIMx_ARR and 0 immediately after the index detection.

Figure 237. Down-counting encode error detection

Timing diagram for down-counting encode error detection. The diagram is split into two horizontal sections. The top section shows a 'No error' scenario where the counter transitions from 0 to 7 after an index pulse. The bottom section shows an 'Error detected' scenario where the counter transitions from 0 to 7 without a preceding 1-to-0 transition on tim_ti1. Signals shown are tim_ti1, tim_ti2, Index, IERRF, and Counter.

The figure illustrates two timing scenarios for down-counting encode error detection. Both sections show the following signals over time:

Top Section (No error): The counter counts down from 2 to 0. An index pulse occurs at 0. The counter then wraps to 7. A note indicates: "No error: transition from 0 to TIMx_ARR following an index".

Bottom Section (Error detected): The counter counts down from 2 to 0. No index pulse occurs. The counter wraps to 7. A note indicates: "Error detected". Later, the counter reaches 6, and a note indicates: "Error asserted". Another note for the 0 to 7 transition states: "No error: transition from 0 to TIMx_ARR without index, but not following a transition from 1 to 0".

MSV62358V1

Timing diagram for down-counting encode error detection. The diagram is split into two horizontal sections. The top section shows a 'No error' scenario where the counter transitions from 0 to 7 after an index pulse. The bottom section shows an 'Error detected' scenario where the counter transitions from 0 to 7 without a preceding 1-to-0 transition on tim_ti1. Signals shown are tim_ti1, tim_ti2, Index, IERRF, and Counter.

An index error sets the IERRF interrupt flag in the TIMx_SR status register. An index error interrupt is generated if the IERRIE bit is set in the TIMx_DIER register.

Functional encoder interrupts

The following interrupts are 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 mode, as shown on Figure 238.

For this purpose, the SMS[3:0] bit can be preloaded. This is enabled by setting the SMSPE enable bit in the TIMx_SMCR register. The trigger for the transfer from SMS[3:0] preload to active value can be selected with the SMSPS bit in the TIMx_SMCR register.

Figure 238. Encoder mode change with preload transferred on update (SMSPS = 0)

Timing diagram showing encoder mode change from x4 to x2 to x1 mode. The diagram illustrates the relationship between the encoder clock output, update events, preload values, and active values for the SMS[3:0] bits.

The figure is a timing diagram illustrating an encoder mode change. The top section shows the encoder clock output (a sawtooth-like waveform) transitioning from x4 mode to x2 mode and then to x1 mode. Below this, the 'Update event' line shows periodic pulses. The 'Preload value' row shows the SMS[3:0] bits being updated: SMS = 0011 in x4 mode, SMS = 0001 in x2 mode, and SMS = 1110 in x1 mode. The 'Active value' row shows the current active SMS[3:0] bits, which match the preload values. Vertical dashed lines indicate the transition points between modes, where the update event triggers the transfer of the preload value to the active value. The diagram is labeled MSv45781V1 in the bottom right corner.

Timing diagram showing encoder mode change from x4 to x2 to x1 mode. The diagram illustrates the relationship between the encoder clock output, update events, preload values, and active values for the SMS[3:0] bits.

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 TIMx_CR2 register. It is valid for the following SMS[3:0] values: 0001, 0010, 0011, 1010, 1011, 1100, 1101, 1110, 1111. Any other SMS[3:0] code is not allowed and may lead to unexpected behavior.

29.3.26 Direction bit output

It is possible to output a direction signal out of the timer, on the tim_oc3n and tim_oc4 output signals (copy of the DIR bit in the TIMx_CR1 register). This is achieved by setting the OC3M[3:0] or the OC4M[3:0] bitfield to 1011 in the TIMx_CCMR2 register.

This feature can be used for monitoring the counting direction (or rotation direction) in encoder mode, or to have a signal indicating the up/down phases in center-aligned PWM mode.

29.3.27 UIF bit remapping

The IUFREMAP bit in the TIMx_CR1 register forces a continuous copy of the update interrupt flag UIF into the timer counter register's bit 31 (TIMxCNT[31]). This allows both the counter value and a potential roll-over condition signaled by the UIFCPY flag to be read in an atomic way. In particular cases, it can ease the calculations by avoiding race conditions, caused for instance by a processing shared between a background task (counter reading) and an interrupt (update interrupt).

There is no latency between the UIF and UIFCPY flags assertion.

29.3.28 Timer input XOR function

The TI1S bit in the TIMx_CR2 register, allows the input filter of channel 1 to be connected to the output of an XOR gate, combining the three input pins tim_ti1, tim_ti2 and tim_ti3.

The XOR output can be used with all the timer input functions such as trigger or input capture. It is convenient to measure the interval between edges on two input signals, as per Figure 239.

Figure 239. Measuring time interval between edges on three signals

Timing diagram showing three input signals (tim_ti1, tim_ti2, tim_ti3) and their XOR output. The XOR output is connected to the TIMx Counter. The diagram illustrates the measurement of time intervals between edges on the XOR output signal. The signals are shown as digital waveforms over time. The XOR output is high when an odd number of inputs are high. The TIMx Counter is shown as a sawtooth waveform, indicating it is counting up and then rolling over. The counter is triggered by the XOR output signal. The diagram is labeled MSV75854V1.
Timing diagram showing three input signals (tim_ti1, tim_ti2, tim_ti3) and their XOR output. The XOR output is connected to the TIMx Counter. The diagram illustrates the measurement of time intervals between edges on the XOR output signal. The signals are shown as digital waveforms over time. The XOR output is high when an odd number of inputs are high. The TIMx Counter is shown as a sawtooth waveform, indicating it is counting up and then rolling over. The counter is triggered by the XOR output signal. The diagram is labeled MSV75854V1.

29.3.29 Interfacing with Hall sensors

This is done using the advanced-control timers to generate PWM signals to drive the motor and another timer TIMx referred to as “interfacing timer” in Figure 240. The “interfacing timer” captures the three timer input pins (tim_ti1, tim_ti2 and tim_ti3) connected through a XOR to the tim_ti1 input channel (selected by setting the TI1S bit in the TIMx_CR2 register).

The slave mode controller is configured in reset mode; the slave input is tim_ti1f_ed. Thus, each time one of the three inputs toggles, the counter restarts counting from 0. This creates a time base triggered by any change on the Hall inputs.

On the “interfacing timer”, capture/compare channel 1 is configured in capture mode, capture signal is tim_trc (See Figure 182). The captured value, which corresponds to the time elapsed between two changes on the inputs, gives information about motor speed.

The “interfacing timer” can be used in output mode to generate a pulse which changes the configuration of the channels of the advanced-control timer (by triggering a COM event). The advanced-control timer is used to generate PWM signals to drive the motor. To do this, the interfacing timer channel must be programmed so that a positive pulse is generated after a programmed delay (in output compare or PWM mode). This pulse is sent to the advanced-control timer through the tim_trgo output.

In this example the user wants to change the PWM configuration of the advanced-control timer after a programmed delay each time a change occurs on the Hall inputs connected to one of the TIMx timers.

In the advanced-control timer, the right tim_itrx input must be selected as trigger input, the timer is programmed to generate PWM signals, the capture/compare control signals are preloaded (CCPC = 1 in the TIMx_CR2 register) and the COM event is controlled by the trigger input (CCUS = 1 in the TIMx_CR2 register). The PWM control bits (CCxE, OCxM) are written after a COM event for the next step (this can be done in an interrupt subroutine generated by the rising edge of tim_oc2ref).

Figure 240 describes this example.

Figure 240. Example of Hall sensor interface

Timing diagram for Figure 240. Example of Hall sensor interface. The diagram shows the relationship between Hall sensor inputs (tim_ti1, tim_ti2, tim_ti3), the timer counter (CNT), capture/compare registers (CCR1, CCR2), trigger output (tim_trgo), and advanced-control timer outputs (tim_oc1, tim_oc1n, tim_oc2, tim_oc2n, tim_oc3, tim_oc3n).

The timing diagram illustrates the operation of a Hall sensor interface using advanced-control timers. The signals shown are:

Arrows at the bottom indicate the points where CCxE, CCxNE, and OCxM registers are updated for the next step. The diagram is labeled MSv62360V1.

Timing diagram for Figure 240. Example of Hall sensor interface. The diagram shows the relationship between Hall sensor inputs (tim_ti1, tim_ti2, tim_ti3), the timer counter (CNT), capture/compare registers (CCR1, CCR2), trigger output (tim_trgo), and advanced-control timer outputs (tim_oc1, tim_oc1n, tim_oc2, tim_oc2n, tim_oc3, tim_oc3n).

29.3.30 Timer synchronization

The TIMx timers are linked together internally for timer synchronization or chaining. Refer to Section 30.4.23: Timer synchronization for details. They can be synchronized in several modes: Reset mode, Gated mode, Trigger mode, Reset + trigger, and gated + reset modes.

Slave mode: Reset mode

The counter and its prescaler can be reinitialized in response to an event on a trigger input. Moreover, if the URS bit from the TIMx_CR1 register is low, an update event UEV is generated. Then all the preloaded registers (TIMx_ARR, TIMx_CCRx) are updated.

In the following example, the upcounter is cleared in response to a rising edge on tim_ti1 input:

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 TIMx_SR register) and an interrupt request, or a DMA request can be sent if enabled (depending on the TIE and TDE bits in TIMx_DIER register).

The following figure shows this behavior when the autoreload register TIMx_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 241. Control circuit in reset mode

Timing diagram for Figure 241. Control circuit in reset mode. The diagram shows five signals over time: tim_ti1 (input), UG (update generation), tim_cnt_ck, tim_psc_ck (clocks), Counter register (values 30-36, then 00-03), and TIF (trigger flag). A rising edge on tim_ti1 triggers a reset of the counter to 00 and sets the TIF flag. The UG signal is shown as a pulse following the reset. The counter continues to count from 00 to 03. The source is MSV62361V1.
Timing diagram for Figure 241. Control circuit in reset mode. The diagram shows five signals over time: tim_ti1 (input), UG (update generation), tim_cnt_ck, tim_psc_ck (clocks), Counter register (values 30-36, then 00-03), and TIF (trigger flag). A rising edge on tim_ti1 triggers a reset of the counter to 00 and sets the TIF flag. The UG signal is shown as a pulse following the reset. The counter continues to count from 00 to 03. The source is 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:

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 TIMx_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 242. Control circuit in Gated mode

Timing diagram for Figure 242. Control circuit in Gated mode. The diagram shows five signal traces over time. 1. tim_ti1: A signal that is initially low, then goes high, then low again, and finally stays high. 2. CEN: Counter Enable signal, which is high only when tim_ti1 is low. 3. tim_cnt_ck, tim_psc_ck: A periodic clock signal that is active only when CEN is high. 4. Counter register: Shows a sequence of values: 30, 31, 32, 33, 34, 35, 36, 37, 38. The counter increments while the clock is active. 5. TIF: A flag that is set (goes high) at the rising edge of tim_ti1 (when the counter stops) and at the falling edge of tim_ti1 (when the counter starts). Arrows from the text 'Write TIF = 0' point to the falling and rising edges of the TIF signal.
Timing diagram for Figure 242. Control circuit in Gated mode. The diagram shows five signal traces over time. 1. tim_ti1: A signal that is initially low, then goes high, then low again, and finally stays high. 2. CEN: Counter Enable signal, which is high only when tim_ti1 is low. 3. tim_cnt_ck, tim_psc_ck: A periodic clock signal that is active only when CEN is high. 4. Counter register: Shows a sequence of values: 30, 31, 32, 33, 34, 35, 36, 37, 38. The counter increments while the clock is active. 5. TIF: A flag that is set (goes high) at the rising edge of tim_ti1 (when the counter stops) and at the falling edge of tim_ti1 (when the counter starts). Arrows from the text 'Write TIF = 0' point to the falling and rising 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:

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 243. Control circuit in trigger mode

Timing diagram for Figure 243. Control circuit in trigger mode. The diagram shows five signals over time: tim_ti2, CEN, tim_cnt_ck, tim_psc_ck, Counter register, and TIF. A vertical dashed line marks the start of the counter. Before the dashed line, tim_ti2 is high, CEN is low, and the Counter register is at 34. At the dashed line, tim_ti2 falls, CEN rises, and the Counter register increments to 35. Following the dashed line, tim_cnt_ck and tim_psc_ck are high-frequency square waves, and the Counter register increments through 36, 37, and 38. TIF is shown as a low signal throughout.

Timing diagram showing the control circuit in trigger mode. The diagram illustrates the relationship between the trigger input (tim_ti2), the counter enable (CEN), the counter clock (tim_cnt_ck, tim_psc_ck), the counter register value, and the trigger interrupt flag (TIF). The counter register value is shown incrementing from 34 to 38 after the trigger input (tim_ti2) falls and the counter enable (CEN) rises. The counter clock (tim_cnt_ck, tim_psc_ck) is shown as a high-frequency square wave. The trigger interrupt flag (TIF) is shown as a low signal throughout the sequence. The diagram is labeled MSv62363V1.

Timing diagram for Figure 243. Control circuit in trigger mode. The diagram shows five signals over time: tim_ti2, CEN, tim_cnt_ck, tim_psc_ck, Counter register, and TIF. A vertical dashed line marks the start of the counter. Before the dashed line, tim_ti2 is high, CEN is low, and the Counter register is at 34. At the dashed line, tim_ti2 falls, CEN rises, and the Counter register increments to 35. Following the dashed line, tim_cnt_ck and tim_psc_ck are high-frequency square waves, and the Counter register increments through 36, 37, and 38. TIF is shown as a low signal throughout.

Slave mode: Combined reset + trigger mode

In this case, a rising edge of the selected trigger input (tim_trgi) reinitializes the counter, generates an update of the registers, and starts the counter.

This mode is used for One-pulse mode.

Slave mode: Combined gated + reset mode

The counter clock is enabled when the trigger input (tim_trgi) is high. The counter stops and is reset) as soon as the trigger becomes low. Both start and stop of the counter are controlled.

This mode is used to detect out-of-range PWM signal (duty cycle exceeding a maximum expected value).

Slave mode: external clock mode 2 + trigger mode

The external clock mode 2 can be used in addition to another slave mode (except external clock mode 1 and encoder mode). In this case, the tim_etr_in signal is used as external clock input, and another input can be selected as trigger input (in reset mode, gated mode or trigger mode). It is recommended not to select tim_etr_in as tim_trgi through the TS bits of TIMx_SMCR register.

In the following example, the upcounter is incremented at each rising edge of the tim_etr_in signal as soon as a rising edge of tim_ti1 occurs:

  1. 1. Configure the external trigger input circuit by programming the TIMx_SMCR register as follows:
    • – ETF = 0000: no filter
    • – ETPS = 00: prescaler disabled
    • – ETP = 0: detection of rising edges on tim_etr_in and ECE = 1 to enable the external clock mode 2.
  2. 2. Configure the channel 1 as follows, to detect rising edges on TI:
    • – IC1F = 0000: no filter.
    • – The capture prescaler is not used for triggering and does not need to be configured.
    • – CC1S = 01 in TIMx_CCMR1 register to select only the input capture source
    • – CC1P = 0 and CC1NP = 0 in TIMx_CCER register to validate the polarity (and detect rising edge only).
  3. 3. Configure the timer in trigger mode by writing SMS = 110 in TIMx_SMCR register. Select tim_ti1 as the input source by writing TS = 00101 in TIMx_SMCR register.

A rising edge on tim_ti1 enables the counter and sets the TIF flag. The counter then counts on tim_etr_in rising edges.

The delay between the rising edge of the tim_etr_in signal and the actual reset of the counter is due to the resynchronization circuit on tim_etrp input.

Figure 244. Control circuit in external clock mode 2 + trigger mode

Timing diagram for external clock mode 2 + trigger mode showing signals tim_ti1, CEN, ETR, tim_cnt_ck, Counter register, and TIF. A rising edge on tim_ti1 triggers CEN to go high and TIF to set. Subsequent rising edges on ETR cause pulses on tim_cnt_ck and increment the Counter register from 34 to 35 and then 36.

The timing diagram illustrates the operation of the timer in external clock mode 2 with trigger mode. The signals shown are: tim_ti1 (trigger input), CEN (counter enable), ETR (external trigger), tim_cnt_ck, tim_psc_ck (counter and prescaler clocks), Counter register (showing values 34, 35, 36), and TIF (trigger interrupt flag). The sequence starts with a rising edge on tim_ti1, which sets the TIF flag and enables the counter (CEN). Following this, rising edges on ETR increment the counter register. The counter clock (tim_cnt_ck) is shown as a series of pulses corresponding to the rising edges of ETR. The counter register values 34, 35, and 36 are shown at successive ETR rising edges. The diagram is labeled MSV62364V1 in the bottom right corner.

Timing diagram for external clock mode 2 + trigger mode showing signals tim_ti1, CEN, ETR, tim_cnt_ck, Counter register, and TIF. A rising edge on tim_ti1 triggers CEN to go high and TIF to set. Subsequent rising edges on ETR cause pulses on tim_cnt_ck and increment the Counter register from 34 to 35 and then 36.

Note: The clock of the slave peripherals (such as timer, ADC) receiving the tim_trgo or the tim_trgo2 signals must be enabled prior to receive events from the master timer, and the clock frequency (prescaler) must not be changed on-the-fly while triggers are received from the master timer.

29.3.31 ADC triggers

The timer can generate an ADC triggering event with various internal signals, such as reset, enable or compare events. It is also possible to generate a pulse issued by internal edge detectors, such as:

The triggers are issued on the tim_trgo2 internal line which is redirected to the ADC. There is a total of 16 possible events, which can be selected using the MMS2[3:0] bits in the TIMx_CR2 register.

An example of an application for 3-phase motor drives is given in Figure 197 .

Note: The clock of the slave peripherals (timer, ADC, ...) receiving the tim_trgo or the tim_trgo2 signals must be enabled prior to receive events from the master timer, and the clock frequency (prescaler) must not be changed on-the-fly while triggers are received from the master timer.

The clock of the ADC must be enabled prior to receive events from the master timer, and must not be changed on-the-fly while triggers are received from the timer.

29.3.32 DMA burst mode

The TIMx timers have the capability to generate multiple DMA requests upon a single event. The main purpose is to be able to reprogram part of the timer multiple times without software overhead, but it can also be used to read several registers in a row, at regular intervals.

The DMA controller destination is unique and must point to the virtual register TIMx_DMAR. On a given timer event, the timer launches a sequence of DMA requests (burst). Each write into the TIMx_DMAR register is actually redirected to one of the timer registers.

The DBL[4:0] bits in the TIMx_DCR register set the DMA burst length. The timer recognizes a burst transfer when a read or a write access is done to the TIMx_DMAR address), i.e. the number of transfers (either in half-words or in bytes).

The DBA[4:0] bits in the TIMx_DCR register define the DMA base address for DMA transfers (when read/write access are done through the TIMx_DMAR address). DBA is defined as an offset starting from the address of the TIMx_CR1 register:

Example:

00000: TIMx_CR1

00001: TIMx_CR2

00010: TIMx_SMCR

The DBSS[3:0] bits in the TIMx_DCR register defines the interrupt source that triggers the DMA burst transfers (see Section 29.6.29: TIM1 DMA control register (TIM1_DCR) for details).

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

This is done in the following steps:

  1. 1. Configure the corresponding DMA channel as follows:
    • – DMA channel peripheral address is the DMAR register address.
    • – DMA channel memory address is the address of the buffer in the RAM containing the data to be transferred by DMA into CCRx registers.
    • – Number of data to transfer = 3 (see note below).
    • – Circular mode disabled.
  2. 2. Configure the DCR register by configuring the DBA and DBL bitfields as follows: DBL = 3 transfers, DBA = 0xE and DBSS = 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 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.

29.3.33 TIM1 DMA requests

The TIM1 can generate a DMA request, as shown in the table below.

Table 271. DMA request

DMA request signalDMA requestEnable control bit
tim_upd_dmaUpdateUDE
tim_cc1_dmaCapture/compare 1CC1DE
tim_cc2_dmaCapture/compare 2CC2DE
tim_cc3_dmaCapture/compare 3CC3DE
tim_cc4_dmaCapture/compare 4CC4DE
tim_com_dmaCommutation (COM)COMDE
tim_trgi_dmaTriggerTDE

29.3.34 Debug mode

When the microcontroller enters debug mode (CPU1 Cortex ® -M33 core halted), the TIMx counter can either continue to work normally or stop, depending on DBG_TIMx_STOP configuration bit in DBG module.

The behavior in debug mode can be programmed with a dedicated configuration bit per timer in the Debug support (DBG) module.

For safety purposes, when the counter is stopped, the outputs are disabled (as if the MOE bit was reset). The outputs can either be forced to an inactive state (OSSI bit = 1), or have their control taken over by the GPIO controller (OSSI bit = 0), typically to force a Hi-Z.

For more details, refer to section Debug support (DBG).

29.4 TIM1 low-power modes

Table 272. Effect of low-power modes on TIM1

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.

29.5 TIM1 interrupts

The TIM1 can generate multiple interrupts, as shown in Table 273 .

Table 273. Interrupt requests

Interrupt acronymInterrupt eventEvent flagEnable control bitInterrupt clear methodExit from Sleep modeExit from Stop and Standby mode
TIM_UPDUpdateUIFUIEwrite 0 in UIFYesNo
TIM_CCCapture/compare 1CC1IFCC1IEwrite 0 in CC1IFYesNo
Capture/compare 2CC2IFCC2IEwrite 0 in CC2IFYesNo
Capture/compare 3CC3IFCC3IEwrite 0 in CC3IFYesNo
Capture/compare 4CC4IFCC4IEwrite 0 in CC4IFYesNo
TIM_TRGI_COM_
DIR_IDX
TIM_COMCommutation (COM)COMIFCOMIEwrite 0 in COMIFYesNo
TIM_TRGITriggerTIFTIEwrite 0 in TIFYesNo
TIM_IDXIndexIDXFIDXIEwrite 0 in IDXFYesNo
TIM_DIRDirectionDIRFDIRIEwrite 0 in DIRFYesNo
TIM_BRK_TERR_
IERR
TIM_BRKBreakBIFBIEwrite 0 in BIFYesNo
Break2B2IFwrite 0 in B2IFYesNo
System BreakSBIFwrite 0 in SBIFYesNo
TIM_IERRIndex ErrorIERRFIERRIEwrite 0 in IERRFYesNo
TIM_TERRTransition ErrorTERRFTERRIEwrite 0 in TERRFYesNo

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

29.6.1 TIM1 control register 1 (TIM1_CR1)

Address offset: 0x000

Reset value: 0x0000

1514131211109876543210
Res.Res.Res.DITH
EN
UIFRE
MAP
Res.CKD[1:0]ARPECMS[1:0]DIROPMURSUDISCEN
rwrwrwrwrwrwrwrwrwrwrwrw

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

Bit 12 DITHEN : Dithering enable

0: Dithering disabled
1: Dithering enabled

Note: The DITHEN 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 TIMx_CNT register bit 31.
1: Remapping enabled. UIF status bit is copied to TIMx_CNT register bit 31.

Bit 10 Reserved, must be kept at reset value.

Bits 9:8 CKD[1:0] : Clock division

This bitfield indicates the division ratio between the timer clock (tim_ker_ck) frequency and the dead-time and sampling clock ( \( t_{DTS} \) ) used by the dead-time generators and the digital filters (tim_etr_in, tim_tix),

00: \( t_{DTS} = t_{tim\_ker\_ck} \)
01: \( t_{DTS} = 2 * t_{tim\_ker\_ck} \)
10: \( t_{DTS} = 4 * t_{tim\_ker\_ck} \)
11: Reserved, do not program this value

Bit 7 ARPE : Autoreload preload enable

0: TIMx_ARR register is not buffered
1: TIMx_ARR register is buffered

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

00: Edge-aligned mode. The counter counts up or down depending on the direction bit (DIR).
01: Center-aligned mode 1. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS = 00 in TIMx_CCMRx register) are set only when the counter is counting down.
10: Center-aligned mode 2. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS = 00 in TIMx_CCMRx register) are set only when the counter is counting up.
11: Center-aligned mode 3. The counter counts up and down alternatively. Output compare interrupt flags of channels configured in output (CCxS = 00 in TIMx_CCMRx register) are set both when the counter is counting up or down.

Note: It is not allowed to switch from edge-aligned mode to center-aligned mode as long as the counter is enabled (CEN = 1)

Bit 4 DIR : Direction

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

Bit 3 OPM : One-pulse modeBit 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.

Buffered registers are then loaded with their preload values.

Bit 0 CEN : Counter enable

Note: External clock, gated mode and encoder mode can work only if the CEN bit has been previously set by software. However trigger mode can set the CEN bit automatically by hardware.

29.6.2 TIM1 control register 2 (TIM1_CR2)

Address offset: 0x004

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.MMS[3]Res.MMS2[3:0]Res.OIS6Res.OIS5
rwrwrwrwrwrwrw
1514131211109876543210
OIS4NOIS4OIS3NOIS3OIS2NOIS2OIS1NOIS1TI1SMMS[2:0]CCDSCCUSRes.CCPC
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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

Bit 24 Reserved, must be kept at reset value.

Bits 23:20 MMS2[3:0] : Master mode selection 2

These bits allow the information to be sent to ADC for synchronization (tim_trgo2) to be selected. The combination is as follows:

0000: Reset - the UG bit from the TIMx_EGR register is used as trigger output (tim_trgo2). If the reset is generated by the trigger input (slave mode controller configured in reset mode), the signal on tim_trgo2 is delayed compared to the actual reset.

0001: Enable - the Counter Enable signal CNT_EN is used as trigger output (tim_trgo2). It is useful to start several timers at the same time or to control a window in which a slave timer is enabled. The Counter Enable signal is generated by a logic AND between the CEN control bit and the trigger input when configured in Gated mode. When the Counter Enable signal is controlled by the trigger input, there is a delay on tim_trgo2, except if the Master/Slave mode is selected (see the MSM bit description in TIMx_SMCR register).

0010: Update - the update event is selected as trigger output (tim_trgo2). For instance, a master timer can then be used as a prescaler for a slave timer.

0011: Compare pulse - the trigger output sends a positive pulse when the CC1IF flag is to be set (even if it was already high), as soon as a capture or compare match occurs (tim_trgo2).

0100: Compare - tim_oc1refc signal is used as trigger output (tim_trgo2)

0101: Compare - tim_oc2refc signal is used as trigger output (tim_trgo2)

0110: Compare - tim_oc3refc signal is used as trigger output (tim_trgo2)

0111: Compare - tim_oc4refc signal is used as trigger output (tim_trgo2)

1000: Compare - tim_oc5refc signal is used as trigger output (tim_trgo2)

1001: Compare - tim_oc6refc signal is used as trigger output (tim_trgo2)

1010: Compare Pulse - tim_oc4refc rising or falling edges generate pulses on tim_trgo2

1011: Compare pulse - tim_oc6refc rising or falling edges generate pulses on tim_trgo2

1100: Compare pulse - tim_oc4refc or tim_oc6refc rising edges generate pulses on tim_trgo2

1101: Compare pulse - tim_oc4refc rising or tim_oc6refc falling edges generate pulses on tim_trgo2

1110: Compare pulse - tim_oc5refc or tim_oc6refc rising edges generate pulses on tim_trgo2

1111: Compare pulse - tim_oc5refc rising or tim_oc6refc falling edges generate pulses on tim_trgo2

Note: The clock of the slave timer or ADC must be enabled prior to receive events from the master timer, and must not be changed on-the-fly while triggers are received from the master timer.

Bit 19 Reserved, must be kept at reset value.

Bit 18 OIS6 : Output idle state 6 (tim_oc6 output)
Refer to OIS1 bit

Bit 17 Reserved, must be kept at reset value.

Bit 16 OIS5 : Output idle state 5 (tim_oc5 output)
Refer to OIS1 bit

Bit 15 OIS4N : Output idle state 4 (tim_oc4n output)
Refer to OIS1N bit

Bit 14 OIS4 : Output idle state 4 (tim_oc4 output)
Refer to OIS1 bit

Bit 13 OIS3N : Output idle state 3 (tim_oc3n output)

Refer to OIS1N bit

Bit 12 OIS3 : Output idle state 3 (tim_oc3n output)

Refer to OIS1 bit

Bit 11 OIS2N : Output idle state 2 (tim_oc2n output)

Refer to OIS1N bit

Bit 10 OIS2 : Output idle state 2 (tim_oc2 output)

Refer to OIS1 bit

Bit 9 OIS1N : Output idle state 1 (tim_oc1n output)

0: tim_oc1n = 0 after a dead-time when MOE = 0

1: tim_oc1n = 1 after a dead-time when MOE = 0

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

Bit 8 OIS1 : Output idle state 1 (tim_oc1 output)

0: tim_oc1 = 0 (after a dead-time) when MOE = 0

1: tim_oc1 = 1 (after a dead-time) when MOE = 0

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

Bit 7 TI1S : tim_ti1 selection

0: The tim_ti1_in[15:0] multiplexer output is connected to tim_ti1 input

1: tim_ti1_in[15:0], tim_ti2_in[15:0] and tim_ti3_in[15:0] multiplexers outputs are XORed and connected to the tim_ti1 input

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

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

0000: Reset - the UG bit from the TIMx_EGR register is used as trigger output (tim_trgo). If the reset is generated by the trigger input (slave mode controller configured in reset mode) then the signal on tim_trgo is delayed compared to the actual reset.

0001: Enable - the Counter Enable signal CNT_EN is used as trigger output (tim_trgo). It is useful to start several timers at the same time or to control a window in which a slave timer is enable. The Counter Enable signal is generated by a logic AND between CEN control bit and the trigger input when configured in gated mode. When the Counter Enable signal is controlled by the trigger input, there is a delay on tim_trgo, except if the master/slave mode is selected (see the MSM bit description in TIMx_SMCR register).

0010: Update - The update event is selected as trigger output (tim_trgo). For instance a master timer can then be used as a prescaler for a slave timer.

0011: Compare Pulse - The trigger output send a positive pulse when the CC1IF flag is to be set (even if it was already high), as soon as a capture or a compare match occurred. (tim_trgo).

0100: Compare - tim_oc1refc signal is used as trigger output (tim_trgo)

0101: Compare - tim_oc2refc signal is used as trigger output (tim_trgo)

0110: Compare - tim_oc3refc signal is used as trigger output (tim_trgo)

0111: Compare - tim_oc4refc signal is used as trigger output (tim_trgo)

1000: Encoder Clock output - The encoder clock signal is used as trigger output (tim_trgo). This code is valid for the following SMS[3:0] values: 0001, 0010, 0011, 1010, 1011, 1100, 1101, 1110, 1111. Any other SMS[3:0] code is not allowed and may lead to unexpected behavior.

Other codes reserved

Note: The clock of the slave timer or ADC must be enabled prior to receive events from the master timer, and must not be changed on-the-fly while triggers are received from the master timer.

Bit 3 CCDS : Capture/compare DMA selection

0: CCx DMA request sent when CCx event occurs

1: CCx DMA requests sent when update event occurs

Bit 2 CCUS : Capture/compare control update selection

0: When capture/compare control bits are preloaded (CCPC = 1), they are updated by setting the COMG bit only

1: When capture/compare control bits are preloaded (CCPC = 1), they are updated by setting the COMG bit or when an rising edge occurs on tim_trgi

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

Bit 1 Reserved, must be kept at reset value.

Bit 0 CCPC : Capture/compare preloaded control

0: CCxE, CCxNE and OCxM bits are not preloaded

1: CCxE, CCxNE and OCxM bits are preloaded, after having been written, they are updated only when a commutation event (COM) occurs (COMG bit set or rising edge detected on tim_trgi, depending on the CCUS bit).

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

29.6.3 TIM1 slave mode control register (TIM1_SMCR)

Address offset: 0x008

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.SMSPSSMSPERes.Res.TS[4:3]Res.Res.Res.Res.SMS[3]
rwrwrwrwrw
1514131211109876543210
ETPECEETPS[1:0]ETF[3:0]MSMTS[2:0]OCCSSMS[2:0]
rwrwrwrwrwrwrwrwrw

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

Bit 25 SMSPS : SMS preload source

This bit selects whether the events that triggers the SMS[3:0] bitfield transfer from preload to active

0: The transfer is triggered by the Timer's Update event

1: The transfer is triggered by the Index event

Bit 24 SMSPE : SMS preload enable

This bit selects whether the SMS[3:0] bitfield is preloaded

0: SMS[3:0] bitfield is not preloaded

1: SMS[3:0] preload is enabled

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

Bits 21:20 TS[4:3] : Trigger selection - bit 4:3

Refer to TS[2:0] description - bits 6:4

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

Bit 15 ETP : External trigger polarity

This bit selects whether tim_etr_in or tim_etr_in is used for trigger operations

0: tim_etr_in is non-inverted, active at high level or rising edge.

1: tim_etr_in is inverted, active at low level or falling edge.

Bit 14 ECE : External clock enable

This bit enables External clock mode 2.

0: External clock mode 2 disabled

1: External clock mode 2 enabled. The counter is clocked by any active edge on the tim_etrf signal.

Note: Setting the ECE bit has the same effect as selecting external clock mode 1 with tim_trgi connected to tim_etrf (SMS = 111 and TS = 00111).

It is possible to simultaneously use external clock mode 2 with the following slave modes: reset mode, gated mode and trigger mode. Nevertheless, tim_trgi must not be connected to tim_etrf in this case (TS bits must not be 00111).

If external clock mode 1 and external clock mode 2 are enabled at the same time, the external clock input is tim_etrf.

Bits 13:12 ETPS[1:0] : External trigger prescaler

External trigger signal tim_etrp frequency must be at most 1/4 of TIMxCLK frequency. A prescaler can be enabled to reduce tim_etrp frequency. It is useful when inputting fast external clocks on tim_etr_in.

00: Prescaler OFF

01: tim_etr_in frequency divided by 2

10: tim_etr_in frequency divided by 4

11: tim_etr_in frequency divided by 8

Bits 11:8 ETF[3:0] : External trigger filter

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

0000: No filter, sampling is done at \( 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

Bit 7 MSM : Master/slave mode

0: No action

1: The effect of an event on the trigger input (tim_trgi) is delayed to allow a perfect synchronization between the current timer and its slaves (through tim_trgo). It is useful if we want to synchronize several timers on a single external event.

Bits 6:4 TS[2:0] : Trigger selection

This bitfield is combined with TS[4:3] bits.

This bitfield selects the trigger input to be used to synchronize the counter.

00000: Internal Trigger 0 (tim_itr0)

00001: Internal Trigger 1 (tim_itr1)

00010: Internal Trigger 2 (tim_itr2)

00011: Internal Trigger 3 (tim_itr3)

00100: tim_ti1 Edge Detector (tim_ti1f_ed)

00101: Filtered Timer Input 1 (tim_ti1fp1)

00110: Filtered Timer Input 2 (tim_ti2fp2)

00111: External Trigger input (tim_etrf)

01000: Internal Trigger 4 (tim_itr4)

01001: Internal Trigger 5 (tim_itr5)

01010: Internal Trigger 6 (tim_itr6)

01011: Internal Trigger 7 (tim_itr7)

01100: Internal Trigger 8 (tim_itr8)

01101: Internal Trigger 9 (tim_itr9)

01110: Internal Trigger 10 (tim_itr10)

01111: Internal trigger 11 (tim_itr11)

10000: Internal trigger 12 (tim_itr12)

10001: Internal trigger 13 (tim_itr13)

10010: Internal trigger 14 (tim_itr14)

10011: Internal trigger 15 (tim_itr15)

Others: Reserved

See Table 259: Internal trigger connection for more details on tim_itr x meaning for each Timer.

Note: These bits must be changed only when they are not used (for example when SMS = 000) to avoid wrong edge detections at the transition.

Bit 3 OCCS : OREF clear selection

This bit is used to select the OREF clear source.

0: tim_ocref_clr_int is connected to the tim_ocref_clr input

1: tim_ocref_clr_int is connected to tim_etrf

Bits 16, 2:0 SMS[3: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 TIMx_SMCR for tim_etr_in and CCxP/CCxNP bits in TIMx_CCER register for tim_ti1fp1 and tim_ti2fp2).

0000: Slave mode disabled - if CEN = 1 then the prescaler is clocked directly by the internal clock.

0001: Quadrature encoder mode 1, x2 mode- Counter counts up/down on tim_ti1fp1 edge depending on tim_ti2fp2 level.

0010: Quadrature encoder mode 2, x2 mode - Counter counts up/down on tim_ti2fp2 edge depending on tim_ti1fp1 level.

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

0100: Reset mode - Rising edge of the selected trigger input (tim_trgi) reinitializes the counter and generates an update of the registers.

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

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

0111: External Clock mode 1 - Rising edges of the selected trigger (tim_trgi) clock the counter.

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

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

1010: Encoder mode: Clock plus direction, x2 mode.

1011: Encoder mode: Clock plus direction, x1 mode, tim_ti2fp2 edge sensitivity is set by CC2P

1100: Encoder mode: Directional Clock, x2 mode.

1101: Encoder mode: Directional Clock, x1 mode, tim_ti1fp1 and tim_ti2fp2 edge sensitivity is set by CC1P and CC2P.

1110: Quadrature encoder mode: x1 mode, counting on tim_ti1fp1 edges only, edge sensitivity is set by CC1P.

1111: Quadrature encoder mode: x1 mode, counting on tim_ti2fp2 edges only, edge sensitivity is set by CC2P.

Note: The gated mode must not be used if tim_ti1f_ed is selected as the trigger input (TS = 00100). Indeed, tim_ti1f_ed outputs 1 pulse for each transition on TI1F, whereas the gated mode checks the level of the trigger signal.

Note: The clock of the slave peripherals (timer, ADC, ...) receiving the tim_trgo or the tim_trgo2 signals must be enabled prior to receive events from the master timer, and the clock frequency (prescaler) must not be changed on-the-fly while triggers are received from the master timer.

29.6.4 TIM1 DMA/interrupt enable register (TIM1_DIER)

Address offset: 0x00C

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.TERRIEIERRIEDIRIEIDXIERes.Res.Res.Res.
rwrwrwrw
1514131211109876543210
Res.TDECOMDECC4DECC3DECC2DECC1DEUDEBIETIECOMIECC4IECC3IECC2IECC1IEUIE
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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

Bit 23 TERRIE : Transition error interrupt enable

0: Transition error interrupt disabled

1: Transition error interrupt enabled

Bit 22 IERRIE : Index error interrupt enable

0: Index error interrupt disabled

1: Index error interrupt enabled

Bit 21 DIRIE : Direction change interrupt enable

0: Direction Change interrupt disabled

1: Direction Change interrupt enabled

Bit 20 IDXIE : Index interrupt enable

0: Index interrupt disabled

1: Index Change interrupt enabled

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

Bit 14 TDE : Trigger DMA request enable

0: Trigger DMA request disabled

1: Trigger DMA request enabled

Bit 13 COMDE : COM DMA request enable

0: COM DMA request disabled

1: COM DMA request enabled

Bit 12 CC4DE : Capture/compare 4 DMA request enable

0: CC4 DMA request disabled

1: CC4 DMA request enabled

Bit 11 CC3DE : Capture/compare 3 DMA request enable

0: CC3 DMA request disabled

1: CC3 DMA request enabled

Bit 10 CC2DE : Capture/compare 2 DMA request enable

0: CC2 DMA request disabled

1: CC2 DMA request enabled

Bit 9 CC1DE : Capture/compare 1 DMA request enable

0: CC1 DMA request disabled

1: CC1 DMA request enabled

29.6.5 TIM1 status register (TIM1_SR)

Address offset: 0x010

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.TERRFIERRFDIRFIDXFRes.Res.CC6IFCC5IF
rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0
1514131211109876543210
Res.Res.SBIFCC4OFCC3OFCC2OFCC1OFB2IFBIFTIFCOMIFCC4IFCC3IFCC2IFCC1IFUIF
rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0rc_w0

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

Bit 23 TERRF : Transition error interrupt flag

This flag is set by hardware when a transition error is detected in encoder mode. It is cleared by software by writing it to 0.

0: No encoder transition error has been detected.

1: An encoder transition error has been detected

Bit 22 IERRF : Index error interrupt flag

This flag is set by hardware when an index error is detected. It is cleared by software by writing it to 0.

0: No index error has been detected.

1: An index error has been detected

Bit 21 DIRF : Direction change interrupt flag

This flag is set by hardware when the direction changes in encoder mode (DIR bit value in TIMx_CR is changing). It is cleared by software by writing it to 0.

0: No direction change

1: Direction change

Bit 20 IDXF : Index interrupt flag

This flag is set by hardware when an index event is detected. It is cleared by software by writing it to 0.

0: No index event occurred.

1: An index event has occurred

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

Bit 17 CC6IF : Compare 6 interrupt flag

Refer to CC1IF description

Note: Channel 6 can only be configured as output.

Bit 16 CC5IF : Compare 5 interrupt flag

Refer to CC1IF description

Note: Channel 5 can only be configured as output.

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

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

Bit 12 CC4OF : Capture/compare 4 overcapture flag

Refer to CC1OF description

Bit 11 CC3OF : Capture/compare 3 overcapture flag

Refer to CC1OF description

Bit 10 CC2OF : Capture/compare 2 overcapture flag

Refer to CC1OF description

Bit 9 CC1OF: Capture/compare 1 overcapture flag

This flag is set by hardware only when the corresponding channel is configured in input capture mode. It is cleared by software by writing it to 0.

0: No overcapture has been detected.

1: The counter value has been captured in TIMx_CCR1 register while CC1IF flag was already set

Bit 8 B2IF: Break 2 interrupt flag

This flag is set by hardware as soon as the break 2 input goes active. It can be cleared by software if the break 2 input is not active.

0: No break event occurred.

1: An active level has been detected on the break 2 input. An interrupt is generated if BIE = 1 in the TIMx_DIER register.

Bit 7 BIF: Break interrupt flag

This flag is set by hardware as soon as the break input goes active. It can be cleared by software if the break input is not active.

0: No break event occurred.

1: An active level has been detected on the break input. An interrupt is generated if BIE = 1 in the TIMx_DIER register.

Bit 6 TIF: Trigger interrupt flag

This flag is set by hardware on the TRG trigger event (active edge detected on tim_trgi input when the slave mode controller is enabled in all modes but gated mode. It is set when the counter starts or stops when gated mode is selected. It is cleared by software.

0: No trigger event occurred.

1: Trigger interrupt pending.

Bit 5 COMIF: COM interrupt flag

This flag is set by hardware on COM event (when capture/compare Control bits - CCxE, CCxNE, OCxM - have been updated). It is cleared by software.

0: No COM event occurred.

1: COM interrupt pending.

Bit 4 CC4IF: Capture/compare 4 interrupt flag

Refer to CC1IF description

Bit 3 CC3IF: Capture/compare 3 interrupt flag

Refer to CC1IF description

Bit 2 CC2IF : Capture/compare 2 interrupt flag

Refer to CC1IF description

Bit 1 CC1IF : Capture/compare 1 interrupt flag

This flag is set by hardware. It is cleared by software (input capture or output compare mode) or by reading the TIMx_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 TIMx_CNT matches the content of the TIMx_CCR1 register. When the content of TIMx_CCR1 is greater than the content of TIMx_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 TIMx_CR1 register for the full description.

If channel CC1 is configured as input: this bit is set when counter value has been captured in TIMx_CCR1 register (an edge has been detected on IC1, as per the edge sensitivity defined with the CC1P and CC1NP bits setting, in TIMx_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:

29.6.6 TIM1 event generation register (TIM1_EGR)

Address offset: 0x014

Reset value: 0x0000

1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.B2GBGTGCOMGCC4GCC3GCC2GCC1GUG
wwwwwwwww

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

Bit 8 B2G : Break 2 generation

This bit is set by software in order to generate an event, it is automatically cleared by hardware.

0: No action

1: A break 2 event is generated. MOE bit is cleared and B2IF flag is set. Related interrupt can occur if enabled.

Bit 7 BG : Break generation

This bit is set by software in order to generate an event, it is automatically cleared by hardware.

0: No action

1: A break event is generated. MOE bit is cleared and BIF flag is set. Related interrupt or DMA transfer can occur if enabled.

Bit 6 TG : Trigger generation

This bit is set by software in order to generate an event, it is automatically cleared by hardware.

0: No action

1: The TIF flag is set in TIMx_SR register. Related interrupt or DMA transfer can occur if enabled.

Bit 5 COMG : Capture/compare control update generation

This bit can be set by software, it is automatically cleared by hardware

0: No action

1: CCxE, CCxNE and OCxM bits update (providing CCPC bit is set)

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

Bit 4 CC4G : Capture/compare 4 generation

Refer to CC1G description

Bit 3 CC3G : Capture/compare 3 generation

Refer to CC1G description

Bit 2 CC2G : Capture/compare 2 generation

Refer to CC1G description

Bit 1 CC1G : Capture/compare 1 generation

This bit is set by software in order to generate an event, it is automatically cleared by hardware.

0: No action

1: A capture/compare event is generated on channel 1:

If channel CC1 is configured as output:

CC1IF flag is set, Corresponding interrupt or DMA request is sent if enabled.

If channel CC1 is configured as input:

The current value of the counter is captured in TIMx_CCR1 register. The CC1IF flag is set, the corresponding interrupt or DMA request is sent if enabled. The CC1OF flag is set if the CC1IF flag was already high.

Bit 0 UG : Update generation

This bit can be set by software, it is automatically cleared by hardware.

0: No action

1: Reinitialize the counter and generates an update of the registers. Note that the prescaler counter is cleared too (anyway the prescaler ratio is not affected). The counter is cleared if the center-aligned mode is selected or if DIR = 0 (upcounting), else it takes the autoreload value (TIMx_ARR) if DIR = 1 (downcounting).

29.6.7 TIM1 capture/compare mode register 1 (TIM1_CCMR1)

Address offset: 0x018

Reset value: 0x0000 0000

The same register can be used for input capture mode (this section) or for output compare mode (next section). The direction of a channel is defined by configuring the corresponding CCxS bits. All the other bits of this register have a different function for input capture and for output compare modes. It is possible to combine both modes independently (for example channel 1 in input capture mode and channel 2 in output compare mode).

31302928272625242322212019181716
ResResResResResResResResResResResResResResResRes
1514131211109876543210
IC2F[3:0]IC2PSC[1:0]CC2S[1:0]IC1F[3:0]IC1PSC[1:0]CC1S[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
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

This bitfield defines the direction of the channel (input/output) as well as the used input.

00: CC2 channel is configured as output

01: CC2 channel is configured as input, tim_ic2 is mapped on tim_ti2

10: CC2 channel is configured as input, tim_ic2 is mapped on tim_ti1

11: CC2 channel is configured as input, tim_ic2 is mapped on tim_trc. This mode is working only if an internal trigger input is selected through TS bit (TIMx_SMCR register)

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

Bits 7:4 IC1F[3:0] : Input capture 1 filter

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

0000: No filter, sampling is done at \( f_{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 (TIMx_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 (TIMx_SMCR register)

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

29.6.8 TIM1 capture/compare mode register 1 [alternate] (TIM1_CCMR1)

Address offset: 0x018

Reset value: 0x0000 0000

The same register can be used for output compare mode (this section) or for input capture mode (previous section). The direction of a channel is defined by configuring the corresponding CCxS bits. All the other bits of this register have a different function for input capture and for output compare modes. It is possible to combine both modes independently (for example channel 1 in input capture mode and channel 2 in output compare mode).

31302928272625242322212019181716
ResResResResResResResOC2M[3]ResResResResResResResOC1M[3]
rwrw
1514131211109876543210
OC2 CEOC2M[2:0]OC2 PEOC2 FECC2S[1:0]OC1 CEOC1M[2:0]OC1 PEOC1 FECC1S[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Output compare mode:

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

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

Bit 15 OC2CE : Output compare 2 clear enable

Bits 24, 14:12 OC2M[3:0] : Output compare 2 mode

Bit 11 OC2PE : Output compare 2 preload enable

Bit 10 OC2FE : Output compare 2 fast enable

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 (TIMx_SMCR register)

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

Bit 7 OC1CE : Output compare 1 clear enable

0: tim_oc1ref is not affected by the tim_ocref_clr_int signal

1: tim_oc1ref is cleared as soon as a High level is detected on tim_ocref_clr_int signal (tim_ocref_clr input or tim_etrfr input)

Bits 16, 6:4 OC1M[3: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.

0000: Frozen - The comparison between the output compare register TIMx_CCR1 and the counter TIMx_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.

0001: Set channel 1 to active level on match. tim_oc1ref signal is forced high when the counter TIMx_CNT matches the capture/compare register 1 (TIMx_CCR1).

0010: Set channel 1 to inactive level on match. tim_oc1ref signal is forced low when the counter TIMx_CNT matches the capture/compare register 1 (TIMx_CCR1).

0011: Toggle - tim_oc1ref toggles when TIMx_CNT = TIMx_CCR1.

0100: Force inactive level - tim_oc1ref is forced low.

0101: Force active level - tim_oc1ref is forced high.

0110: PWM mode 1 - In upcounting, channel 1 is active as long as TIMx_CNT < TIMx_CCR1 else inactive. In downcounting, channel 1 is inactive (tim_oc1ref = 0) as long as TIMx_CNT > TIMx_CCR1 else active (tim_oc1ref = 1).

0111: PWM mode 2 - In upcounting, channel 1 is inactive as long as TIMx_CNT < TIMx_CCR1 else active. In downcounting, channel 1 is active as long as TIMx_CNT > TIMx_CCR1 else inactive.

1000: 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 channel 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 channel becomes inactive again at the next update.

1001: 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 channel 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 channel becomes active again at the next update.

1010: Reserved,

1011: Reserved,

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

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

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

1111: 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 TIMx_BDTR register) and CC1S = 00 (the channel is configured in output).

Note: In PWM mode, the OCREF level changes when the result of the comparison changes, when the output compare mode switches from “frozen” mode to “PWM” mode and when the output compare mode switches from “force active/inactive” mode to “PWM” mode.

Note: On channels having a complementary output, this bitfield is preloaded. If the CCPC bit is set in the TIMx_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 TIMx_CCR1 disabled. TIMx_CCR1 can be written at anytime, the new value is taken in account immediately.

1: Preload register on TIMx_CCR1 enabled. Read/Write operations access the preload register. TIMx_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 TIMx_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 TIMx_CR1 register), to have the output pulse starting as soon as possible after the starting trigger.

0: CC1 behaves normally depending on counter and CCR1 values even when the trigger is ON. The minimum delay to activate CC1 output when an edge occurs on the trigger input is 5 clock cycles.

1: An active edge on the trigger input acts like a compare match on CC1 output. Then, OC is set to the compare level independently from the result of the comparison. Delay to sample the trigger input and to activate CC1 output is reduced to 3 clock cycles. OCFE acts only if the channel is configured in PWM1 or PWM2 mode.

Bits 1:0 CC1S[1:0] : Capture/compare 1 selection

This bitfield defines the direction of the channel (input/output) as well as the used input.

00: CC1 channel is configured as output

01: CC1 channel is configured as input, tim_ic1 is mapped on tim_ti1

10: CC1 channel is configured as input, tim_ic1 is mapped on tim_ti2

11: CC1 channel is configured as input, tim_ic1 is mapped on tim_trc. This mode is working only if an internal trigger input is selected through TS bit (TIMx_SMCR register)

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

29.6.9 TIM1 capture/compare mode register 2 (TIM1_CCMR2)

Address offset: 0x01C

Reset value: 0x0000 0000

The same register can be used for input capture mode (this section) or for output compare mode (next section). The direction of a channel is defined by configuring the corresponding CCxS bits. All the other bits of this register have a different function for input capture and for output compare modes. It is possible to combine both modes independently (for example channel 3 in input capture mode and channel 4 in output compare mode).

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
IC4F[3:0]IC4PSC[1:0]CC4S[1:0]IC3F[3:0]IC3PSC[1:0]CC3S[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Input capture mode

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

Bits 15:12 IC4F[3:0] : Input capture 4 filter

Bits 11:10 IC4PSC[1:0] : Input capture 4 prescaler

Bits 9:8 CC4S[1:0] : Capture/compare 4 selection

This bitfield defines the direction of the channel (input/output) as well as the used input.

00: CC4 channel is configured as output

01: CC4 channel is configured as input, tim_ic4 is mapped on tim_ti4

10: CC4 channel is configured as input, tim_ic4 is mapped on tim_ti3

11: CC4 channel is configured as input, tim_ic4 is mapped on tim_trc. This mode is working only if an internal trigger input is selected through TS bit (TIMx_SMCR register)

Note: CC4S bits are writable only when the channel is OFF (CC4E = 0 in TIMx_CCER).

Bits 7:4 IC3F[3:0] : Input capture 3 filter

Bits 3:2 IC3PSC[1:0] : Input capture 3 prescaler

Bits 1:0 CC3S[1:0] : Capture/compare 3 selection

This bitfield defines the direction of the channel (input/output) as well as the used input.

00: CC3 channel is configured as output

01: CC3 channel is configured as input, tim_ic3 is mapped on tim_ti3

10: CC3 channel is configured as input, tim_ic3 is mapped on tim_ti4

11: CC3 channel is configured as input, tim_ic3 is mapped on tim_trc. This mode is working only if an internal trigger input is selected through TS bit (TIMx_SMCR register)

Note: CC3S bits are writable only when the channel is OFF (CC3E = 0 in TIMx_CCER).

29.6.10 TIM1 capture/compare mode register 2 [alternate] (TIM1_CCMR2)

Address offset: 0x01C

Reset value: 0x0000 0000

The same register can be used for output compare mode (this section) or for input capture mode (previous section). The direction of a channel is defined by configuring the corresponding CCxS bits. All the other bits of this register have a different function for input capture and for output compare modes. It is possible to combine both modes independently (for example channel 3 in input capture mode and channel 4 in output compare mode).

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.OC4M[3]Res.Res.Res.Res.Res.Res.Res.OC3M[3]
rwrw
1514131211109876543210
OC4CEOC4M[2:0]OC4PEOC4FECC4S[1:0]OC3CEOC3M[2:0]OC3PEOC3FECC3S[1:0]
rwrwrw

Output compare mode

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

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

Bit 15 OC4CE : Output compare 4 clear enable

Bits 24, 14:12 OC4M[3:0] : Output compare 4 mode

Refer to OC3M[3:0] bit description

Bit 11 OC4PE : Output compare 4 preload enable

Bit 10 OC4FE : Output compare 4 fast enable

Bits 9:8 CC4S[1:0] : Capture/compare 4 selection

This bitfield defines the direction of the channel (input/output) as well as the used input.

00: CC4 channel is configured as output

01: CC4 channel is configured as input, tim_ic4 is mapped on tim_ti4

10: CC4 channel is configured as input, tim_ic4 is mapped on tim_ti3

11: CC4 channel is configured as input, tim_ic4 is mapped on tim_trc. This mode is working only if an internal trigger input is selected through TS bit (TIMx_SMCR register)

Note: CC4S bits are writable only when the channel is OFF (CC4E = 0 in TIMx_CCER).

Bit 7 OC3CE : Output compare 3 clear enable

Bits 16, 6:4 OC3M[3:0] : Output compare 3 mode

These bits define the behavior of the output reference signal tim_oc3ref from which tim_oc3 and tim_oc3n are derived. tim_oc3ref is active high whereas tim_oc3 and tim_oc3n active level depends on CC3P and CC3NP bits.

0000: Frozen - The comparison between the output compare register TIMx_CCR3 and the counter TIMx_CNT has no effect on the outputs. (this mode is used to generate a timing base).

0001: Set channel 3 to active level on match. tim_oc3ref signal is forced high when the counter TIMx_CNT matches the capture/compare register 3 ( TIMx_CCR3 ).

0010: Set channel 3 to inactive level on match. tim_oc3ref signal is forced low when the counter TIMx_CNT matches the capture/compare register 3 ( TIMx_CCR3 ).

0011: Toggle - tim_oc3ref toggles when TIMx_CNT = TIMx_CCR3 .

0100: Force inactive level - tim_oc3ref is forced low.

0101: Force active level - tim_oc3ref is forced high.

0110: PWM mode 1 - In upcounting, channel 3 is active as long as TIMx_CNT < TIMx_CCR3 else inactive. In downcounting, channel 3 is inactive ( tim_oc3ref = 0 ) as long as TIMx_CNT > TIMx_CCR3 else active ( tim_oc3ref = 1 ).

0111: PWM mode 2 - In upcounting, channel 3 is inactive as long as TIMx_CNT < TIMx_CCR3 else active. In downcounting, channel 3 is active as long as TIMx_CNT > TIMx_CCR3 else inactive.

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

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

1010: Pulse on compare: a pulse is generated on tim_oc3ref upon CCR3 match event, as per PWPRSC[2:0] and PW[7:0] bitfields programming in TIMx_ECR .

1011: Direction output. The tim_oc3ref signal is overridden by a copy of the DIR bit.

1100: Combined PWM mode 1 - tim_oc3ref has the same behavior as in PWM mode 1. tim_oc3refc is the logical OR between tim_oc3ref and tim_oc4ref .

1101: Combined PWM mode 2 - tim_oc3ref has the same behavior as in PWM mode 2. tim_oc3refc is the logical AND between tim_oc3ref and tim_oc4ref .

1110: Asymmetric PWM mode 1 - tim_oc3ref has the same behavior as in PWM mode 1. tim_oc3refc outputs tim_oc3ref when the counter is counting up, tim_oc4ref when it is counting down.

1111: Asymmetric PWM mode 2 - tim_oc3ref has the same behavior as in PWM mode 2. tim_oc3refc outputs tim_oc3ref when the counter is counting up, tim_oc4ref when it is counting down.

Note: These bits can not be modified as long as LOCK level 3 has been programmed (LOCK bits in TIMx_BDTR register) and CC1S = 00 (the channel is configured in output).

Note: In PWM mode, the OCREF level changes only when the result of the comparison changes or when the output compare mode switches from “frozen” mode to “PWM” mode.

On channels having a complementary output, this bitfield is preloaded. If the CCPC bit is set in the TIMx_CR2 register then the OC3M active bits take the new value from the preloaded bits only when a COM event is generated.

Bit 3 OC3PE : Output compare 3 preload enable

Bit 2 OC3FE : Output compare 3 fast enable

Bits 1:0 CC3S[1:0] : Capture/compare 3 selection

This bitfield defines the direction of the channel (input/output) as well as the used input.

00: CC3 channel is configured as output

01: CC3 channel is configured as input, tim_ic3 is mapped on tim_ti3

10: CC3 channel is configured as input, tim_ic3 is mapped on tim_ti4

11: CC3 channel is configured as input, tim_ic3 is mapped on tim_trc. This mode is working only if an internal trigger input is selected through TS bit (TIMx_SMCR register)

Note: CC3S bits are writable only when the channel is OFF (CC3E = 0 in TIMx_CCER).

29.6.11 TIM1 capture/compare enable register (TIM1_CCER)

Address offset: 0x020

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CC6PCC6ERes.Res.CC5PCC5E
rwrwrwrw
1514131211109876543210
CC4NPCC4NECC4PCC4ECC3NPCC3NECC3PCC3ECC2NPCC2NECC2PCC2ECC1NPCC1NECC1PCC1E
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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

Bit 21 CC6P : Capture/compare 6 output polarity

Refer to CC1P description

Bit 20 CC6E : Capture/compare 6 output enable

Refer to CC1E description

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

Bit 17 CC5P : Capture/compare 5 output polarity

Refer to CC1P description

Bit 16 CC5E : Capture/compare 5 output enable

Refer to CC1E description

Bit 15 CC4NP : Capture/compare 4 complementary output polarity

Refer to CC1NP description

Bit 14 CC4NE : Capture/compare 4 complementary output enable

Refer to CC1NE description

Bit 13 CC4P : Capture/compare 4 output polarity

Refer to CC1P description

Bit 12 CC4E : Capture/compare 4 output enable

Refer to CC1E description

Bit 11 CC3NP : Capture/compare 3 complementary output polarity

Refer to CC1NP description

Bit 10 CC3NE : Capture/compare 3 complementary output enable
Refer to CC1NE description

Bit 9 CC3P : Capture/compare 3 output polarity
Refer to CC1P description

Bit 8 CC3E : Capture/compare 3 output enable
Refer to CC1E description

Bit 7 CC2NP : Capture/compare 2 complementary output polarity
Refer to CC1NP description

Bit 6 CC2NE : Capture/compare 2 complementary output enable
Refer to CC1NE description

Bit 5 CC2P : Capture/compare 2 output polarity
Refer to CC1P description

Bit 4 CC2E : Capture/compare 2 output enable
Refer to CC1E description

Bit 3 CC1NP : Capture/compare 1 complementary output polarity

CC1 channel configured as output:

0: tim_oc1n active high.

1: tim_oc1n active low.

CC1 channel configured as input:

This bit is used in conjunction with CC1P to define the polarity of tim_ti1fp1 and tim_ti2fp1.
Refer to CC1P description.

Note: This bit is not writable as soon as LOCK level 2 or 3 has been programmed (LOCK bits in TIMx_BDTR register) and CC1S = 00 (channel configured as output).

Note: On channels having a complementary output, this bit is preloaded. If the CCPC bit is set in the TIMx_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.

Note: On channels having a complementary output, this bit is preloaded. If the CCPC bit is set in the TIMx_CR2 register then the CC1NE active bit takes the new value from the preloaded bit only when a Commutation event is generated.

Bit 1 CC1P : Capture/compare 1 output polarity

0: OC1 active high (output mode) / Edge sensitivity selection (input mode, see below)

1: OC1 active low (output mode) / Edge sensitivity selection (input mode, see below)

When CC1 channel is configured as input, both CC1NP/CC1P bits select the active polarity of TI1FP1 and TI2FP1 for trigger or capture operations.

CC1NP = 0, CC1P = 0: non-inverted/rising edge. The circuit is sensitive to TIxFP1 rising edge (capture or trigger operations in reset, external clock or trigger mode), TIxFP1 is not inverted (trigger operation in gated mode or encoder mode).

CC1NP = 0, CC1P = 1: inverted/falling edge. The circuit is sensitive to TIxFP1 falling edge (capture or trigger operations in reset, external clock or trigger mode), TIxFP1 is inverted (trigger operation in gated mode or encoder mode).

CC1NP = 1, CC1P = 1: non-inverted/both edges/ The circuit is sensitive to both TIxFP1 rising and falling edges (capture or trigger operations in reset, external clock or trigger mode), TIxFP1 is not inverted (trigger operation in gated mode). This configuration must not be used in encoder mode.

CC1NP = 1, CC1P = 0: the configuration is reserved, it must not be used.

Note: This bit is not writable as soon as LOCK level 2 or 3 has been programmed (LOCK bits in TIMx_BDTR register).

Note: On channels having a complementary output, this bit is preloaded. If the CCPC bit is set in the TIMx_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 274 for details.

Note: On channels having a complementary output, this bit is preloaded. If the CCPC bit is set in the TIMx_CR2 register then the CC1E active bit takes the new value from the preloaded bit only when a Commutation event is generated.

Table 274. Output control bits for complementary tim_ocx and tim_ocxn channels with break feature

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
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
X11OCREF + Polarity + dead-timeComplementary to OCREF (not OCREF) + Polarity + dead-time
101Off-State (output enabled with inactive state)
tim_ocx = CCxP
tim_ocxref + Polarity
tim_ocxn = tim_ocxref x or 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 (if tim_brk or tim_brk2 is triggered).

Then (this is valid only if tim_brk is triggered), if the clock is present: tim_ocx = OISx and tim_ocxn = OISxN after a dead-time, assuming that OISx and OISxN do not correspond to OCX and tim_ocxn both in active state (may cause a short circuit when driving switches in half-bridge configuration).
Note: tim_brk2 can only be used if OSSI = OSSR = 1.
10
11

1. When both outputs of a channel are not used (control taken over by GPIO), the OISx, OISxN, CCxP and CCxNP bits must be kept cleared.

Note: The state of the external I/O pins connected to the complementary tim_ocx and tim_ocxn channels depends on the tim_ocx and tim_ocxn channel state and the GPIO registers.

29.6.12 TIM1 counter (TIM1_CNT)

Address offset: 0x024

Reset value: 0x0000 0000

31302928272625242322212019181716
UIF
CPY
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 of the TIMx_ISR register. If the UIFREMAP bit in the TIMxCR1 is reset, bit 31 is reserved and read at 0.

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

Bits 15:0 CNT[15:0] : Counter value

Non-dithering mode (DITHEN = 0)

The register holds the counter value.

Dithering mode (DITHEN = 1)

The register only holds the non-dithered part in CNT[15:0]. The fractional part is not available.

29.6.13 TIM1 prescaler (TIM1_PSC)

Address offset: 0x028

Reset value: 0x0000

1514131211109876543210
PSC[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 15:0 PSC[15:0] : Prescaler value

The counter clock frequency ( \( f_{\text{tim\_cnt\_ck}} \) ) is equal to \( f_{\text{tim\_psc\_ck}} / (\text{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 TIMx_EGR register or through trigger controller when configured in “reset mode”).

29.6.14 TIM1 autoreload register (TIM1_ARR)

Address offset: 0x02C

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] : Autoreload value

ARR is the value to be loaded in the actual autoreload register.

Refer to the Section 29.3.3: Time-base unit for more details about ARR update and behavior.

The counter is blocked while the autoreload value is null.

Non-dithering mode (DITHEN = 0)

The register holds the autoreload value.

Dithering mode (DITHEN = 1)

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

29.6.15 TIM1 repetition counter register (TIM1_RCR)

Address offset: 0x030

Reset value: 0x0000

1514131211109876543210
REP[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 15:0 REP[15:0] : Repetition counter reload value

This bitfield defines the update rate of the compare registers (i.e. periodic transfers from preload to active registers) when preload registers are enable. It also defines the update interrupt generation rate, if this interrupt is enable.

When the repetition down-counter reaches zero, an update event is generated and it restarts counting from REP value. As the repetition counter is reloaded with REP value only at the repetition update event UEV, any write to the TIMx_RCR register is not taken in account until the next repetition update event.

It means in PWM mode (REP+1) corresponds to:

29.6.16 TIM1 capture/compare register 1 (TIM1_CCR1)

Address offset: 0x034

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

29.6.17 TIM1 capture/compare register 2 (TIM1_CCR2)

Address offset: 0x038

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 TIMx_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 TIMx_CNT and signaled on tim_oc2 output.

Non-dithering mode (DITHEN = 0)

The register holds the compare value in CCR2[15:0]. The CCR2[19:16] bits are reset.

Dithering mode (DITHEN = 1)

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

If channel CC2 is configured as input: CCR2 is the counter value transferred by the last input capture 2 event (tim_ic2). The TIMx_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.

29.6.18 TIM1 capture/compare register 3 (TIM1_CCR3)

Address offset: 0x03C

Reset value: 0x0000 0000

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

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

Bits 19:0 CCR3[19:0] : Capture/compare value

If channel CC3 is configured as output: CCR3 is the value to be loaded in the actual capture/compare 3 register (preload value).

It is loaded permanently if the preload feature is not selected in the TIMx_CCMR2 register (bit OC3PE). Else the preload value is copied in the active capture/compare 3 register when an update event occurs.

The active capture/compare register contains the value to be compared to the counter TIMx_CNT and signaled on tim_oc3 output.

Non-dithering mode (DITHEN = 0)

The register holds the compare value in CCR3[15:0]. The CCR3[19:16] bits are reset.

Dithering mode (DITHEN = 1)

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

If channel CC3 is configured as input: CCR3 is the counter value transferred by the last input capture 3 event (tim_ic3). The TIMx_CCR3 register is read-only and cannot be programmed.

Non-dithering mode (DITHEN = 0)

The register holds the capture value in CCR3[15:0]. The CCR3[19:16] bits are reset.

Dithering mode (DITHEN = 1)

The register holds the capture in CCR3[19:4]. The CCR3[3:0] bits are reset.

29.6.19 TIM1 capture/compare register 4 (TIM1_CCR4)

Address offset: 0x040

Reset value: 0x0000 0000

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

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

Bits 19:0 CCR4[19:0] : Capture/compare value

If channel CC4 is configured as output: CCR4 is the value to be loaded in the actual capture/compare 4 register (preload value).

It is loaded permanently if the preload feature is not selected in the TIMx_CCMR2 register (bit OC4PE). Else the preload value is copied in the active capture/compare 4 register when an update event occurs.

The active capture/compare register contains the value to be compared to the counter TIMx_CNT and signalled on tim_oc4 output.

Non-dithering mode (DITHEN = 0)

The register holds the compare value in CCR4[15:0]. The CCR4[19:16] bits are reset.

Dithering mode (DITHEN = 1)

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

If channel CC4 is configured as input: CCR4 is the counter value transferred by the last input capture 4 event (tim_ic4). The TIMx_CCR4 register is read-only and cannot be programmed.

Non-dithering mode (DITHEN = 0)

The register holds the capture value in CCR4[15:0]. The CCR4[19:16] bits are reset.

Dithering mode (DITHEN = 1)

The register holds the capture in CCR4[19:4]. The CCR4[3:0] bits are reset.

29.6.20 TIM1 break and dead-time register (TIM1_BDTR)

Address offset: 0x044

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.BK2BIDBKBIDBK2DSRMBKDSRMBK2PBK2EBK2F[3:0]BKF[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
MOEAOEBKPBKEOSSROSSILOCK[1:0]DTG[7:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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

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

Bit 29 BK2BID : Break2 bidirectional

Refer to BKBID description

Bit 28 BKBID : Break bidirectional

0: Break input tim_brk in input mode

1: Break input tim_brk in bidirectional mode

In the bidirectional mode (BKBID bit set to 1), the break input is configured both in input mode and in open drain output mode. Any active break event asserts a low logic level on the Break input to indicate an internal break event to external devices.

Note: This bit cannot be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

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

Bit 27 BK2DSRM : Break2 disarm

Refer to BKDSRM description

Bit 26 BKDSRM : Break disarm

0: Break input tim_brk is armed

1: Break input tim_brk is disarmed

This bit is cleared by hardware when no break source is active.

The BKDSRM bit must be set by software to release the bidirectional output control (open-drain output in Hi-Z state) and then be polled it until it is reset by hardware, indicating that the fault condition has disappeared.

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

Bit 25 BK2P : Break 2 polarity

0: Break input tim_brk2 is active low

1: Break input tim_brk2 is active high

Note: This bit cannot be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

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

Bit 24 BK2E : Break 2 enable

This bit enables the complete break 2 protection, see Figure 202: Break and Break2 circuitry overview .

0: Break2 function disabled

1: Break2 function enabled

Note: The BRKIN2 must only be used with OSSR = OSSI = 1.

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

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

Bits 23:20 BK2F[3:0] : Break 2 filter

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

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

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

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

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

Bit 15 MOE: Main output enable

This bit is cleared asynchronously by hardware as soon as one of the break inputs is active (tim_brk or tim_brk2). It is set by software or automatically depending on the AOE bit. It is acting only on the channels which are configured in output.

0: In response to a break 2 event. OC and OCN outputs are disabled

In response to a break event or if MOE is written to 0: OC and OCN outputs are disabled or forced to idle state depending on the OSSI bit.

1: OC and OCN outputs are enabled if their respective enable bits are set (CCxE, CCxNE in TIMx_CCER register).

See OC/OCN enable description for more details ( Section 29.6.11: TIM1 capture/compare enable register (TIM1_CCER) ).

Bit 14 AOE: Automatic output enable

0: MOE can be set only by software

1: MOE can be set by software or automatically at the next update event (if none of the break inputs tim_brk and tim_brk2 is active)

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_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 TIMx_BDTR register).

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

Bit 12 BKE: Break enable

This bit enables the complete break protection (including all sources connected to tim_sys_brk and BKIN sources, as per Figure 202: Break and Break2 circuitry overview ).

0: Break function disabled

1: Break function enabled

Note: This bit cannot be modified when LOCK level 1 has been programmed (LOCK bits in TIMx_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 having a complementary output which are configured as outputs. OSSR is not implemented if no complementary output is implemented in the timer.

See OC/OCN enable description for more details ( Section 29.6.11: TIM1 capture/compare enable register (TIM1_CCER) ).

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

1: When inactive, OC/OCN outputs are enabled with their inactive level as soon as CCxE = 1 or CCxNE = 1 (the output is still controlled by the timer).

Note: This bit can not be modified as soon as the LOCK level 2 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 10 OSSI : Off-state selection for idle mode

This bit is used when MOE = 0 due to a break event or by a software write, on channels configured as outputs.
See OC/OCN enable description for more details ( Section 29.6.11: TIM1 capture/compare enable register (TIM1_CCER) ).

0: When inactive, OC/OCN outputs are disabled (the timer releases the output control which is taken over by the GPIO logic and which imposes a Hi-Z state).

1: When inactive, OC/OCN outputs are first forced with their inactive level then forced to their idle level after the deadtime. The timer maintains its control over the output.

Note: This bit can not be modified as soon as the LOCK level 2 has been programmed (LOCK bits in TIMx_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 TIMx_BDTR register, OISx and OISxN bits in TIMx_CR2 register and BKBID/BK2BID/BKE/BKP/AOE bits in TIMx_BDTR register can no longer be written.

10: LOCK Level 2 = LOCK Level 1 + CC Polarity bits (CCxP/CCxNP bits in TIMx_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 TIMx_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 TIMx_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 => DT = DTG[7:0] × \( t_{dtg} \) with \( t_{dtg} = t_{DTS} \) .
DTG[7:5] = 10x => DT = (64+DTG[5:0]) × \( t_{dtg} \) with \( T_{dtg} = 2 × t_{DTS} \) .
DTG[7:5] = 110 => DT = (32+DTG[4:0]) × \( t_{dtg} \) with \( T_{dtg} = 8 × t_{DTS} \) .
DTG[7:5] = 111 => DT = (32+DTG[4:0]) × \( t_{dtg} \) with \( T_{dtg} = 16 × 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 TIMx_BDTR register).

29.6.21 TIM1 capture/compare register 5 (TIM1_CCR5)

Address offset: 0x048

Reset value: 0x0000 0000

31302928272625242322212019181716
GC5C3GC5C2GC5C1Res.Res.Res.CCR5[19:16]
rwrwrwrwrwrwrw
1514131211109876543210
CCR5[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bit 31 GC5C3 : Group channel 5 and channel 3

Distortion on channel 3 output:

0: No effect of tim_oc5ref on tim_oc3refc

1: tim_oc3refc is the logical AND of tim_oc3ref and tim_oc5ref

This bit can either have immediate effect or be preloaded and taken into account after an update event (if preload feature is selected in TIMxCCMR2).

Note: it is also possible to apply this distortion on combined PWM signals.

Bit 30 GC5C2 : Group channel 5 and channel 2

Distortion on channel 2 output:

0: No effect of tim_oc5ref on tim_oc2refc

1: tim_oc2refc is the logical AND of tim_oc2ref and tim_oc5ref

This bit can either have immediate effect or be preloaded and taken into account after an update event (if preload feature is selected in TIMxCCMR1).

Note: it is also possible to apply this distortion on combined PWM signals.

Bit 29 GC5C1 : Group channel 5 and channel 1

Distortion on channel 1 output:

0: No effect of oc5ref on oc1refc

1: oc1refc is the logical AND of oc1ref and oc5ref

This bit can either have immediate effect or be preloaded and taken into account after an update event (if preload feature is selected in TIMxCCMR1).

Note: it is also possible to apply this distortion on combined PWM signals.

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

Bits 19:0 CCR5[19:0] : Capture/compare 5 value

CCR5 is the value to be loaded in the actual capture/compare 5 register (preload value).

It is loaded permanently if the preload feature is not selected in the TIMx_CCMR3 register (bit OC5PE). Else the preload value is copied in the active capture/compare 5 register when an update event occurs.

The active capture/compare register contains the value to be compared to the counter TIMx_CNT and signaled on tim_oc5 output.

Non-dithering mode (DITHEN = 0)

The register holds the compare value in CCR5[15:0]. The CCR5[19:16] bits are reset.

Dithering mode (DITHEN = 1)

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

29.6.22 TIM1 capture/compare register 6 (TIM1_CCR6)

Address offset: 0x04C

Reset value: 0x0000 0000

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

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

Bits 19:0 CCR6[19:0] : Capture/compare 6 value

CCR6 is the value to be loaded in the actual capture/compare 6 register (preload value).

It is loaded permanently if the preload feature is not selected in the TIMx_CCMR3 register (bit OC6PE). Else the preload value is copied in the active capture/compare 6 register when an update event occurs.

The active capture/compare register contains the value to be compared to the counter TIMx_CNT and signaled on tim_oc6 output.

Non-dithering mode (DITHEN = 0)

The register holds the compare value in CCR6[15:0]. The CCR6[19:16] bits are reset.

Dithering mode (DITHEN = 1)

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

29.6.23 TIM1 capture/compare mode register 3 (TIM1_CCMR3)

Address offset: 0x050

Reset value: 0x0000 0000

Refer to the above CCMR1 register description. Channels 5 and 6 can only be configured in output.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.OC6M[3]Res.Res.Res.Res.Res.Res.Res.OC5M[3]
rwrw
1514131211109876543210
OC6CEOC6M[2:0]OC6PEOC6FERes.Res.OC5CEOC5M[2:0]OC5PEOC5FERes.Res.
rwrwrwrwrwrwrwrwrwrwrwrw

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

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

Bit 15 OC6CE : Output compare 6 clear enable

Bits 24, 14:12 OC6M[3:0] : Output compare 6 mode

Bit 11 OC6PE : Output compare 6 preload enable

Bit 10 OC6FE : Output compare 6 fast enable

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

Bit 7 OC5CE : Output compare 5 clear enable

Bits 16, 6:4 OC5M[3:0] : Output compare 5 mode

Bit 3 OC5PE : Output compare 5 preload enable

Bit 2 OC5FE : Output compare 5 fast enable

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

29.6.24 TIM1 timer deadtime register 2 (TIM1_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

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

Bit 16 DTAE : Deadtime asymmetric enable

Note: This bit can not be modified as long as LOCK level 1, 2 or 3 has been programmed (LOCK bits in TIMx_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 => DTF = DTGF[7:0] × \( t_{dtg} \) with \( t_{dtg} = t_{DTS} \) .
DTGF[7:5] = 10x => DTF = (64+DTGF[5:0]) × \( t_{dtg} \) with \( T_{dtg} = 2 imes t_{DTS} \) .
DTGF[7:5] = 110 => DTF = (32+DTGF[4:0]) × \( t_{dtg} \) with \( T_{dtg} = 8 imes t_{DTS} \) .
DTGF[7:5] = 111 => DTF = (32+DTGF[4:0]) × \( t_{dtg} \) with \( T_{dtg} = 16 imes 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 TIMx_BDTR register).

29.6.25 TIM1 timer encoder control register (TIM1_ECR)

Address offset: 0x058

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.PWPRSC[2:0]PW[7:0]
rwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.IPOS[1:0]FIDXIBLK[1:0]IDIR[1:0]IE
rwrwrwrwrwrwrwrw

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

Bits 26:24 PWPRSC[2:0] : Pulse width prescaler

This bitfield sets the clock prescaler for the pulse generator, as following:

\[ t_{PWG} = (2^{(PWPRSC[2:0])}) \times t_{tim\_ker\_ck} \]

Bits 23:16 PW[7:0] : Pulse width

This bitfield defines the pulse duration, as following:

\[ t_{PW} = PW[7:0] \times t_{PWG} \]

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

Bits 7:6 IPOS[1:0] : Index positioning

In quadrature encoder mode (SMS[3:0] = 0001, 0010, 0011, 1110, 1111), this bit indicates in which AB input configuration the Index event resets the counter.

In directional clock mode or clock plus direction mode (SMS[3:0] = 1010, 1011, 1100, 1101), these bits indicates on which level the Index event resets the counter. In bidirectional clock mode, this applies for both clock inputs.

Note: IPOS[1] bit is not significant

Bit 5 FIDX : First index

This bit indicates if the first index only is taken into account

Bits 4:3 IBLK[1:0] : Index blanking

This bit indicates if the Index event is conditioned by the tim_ti3 or tim_ti4 input

00: Index always active

01: Index disabled when tim_ti3 input is active, as per CC3P bitfield

10: Index disabled when tim_ti4 input is active, as per CC4P bitfield

11: Reserved

Bits 2:1 IDIR[1:0] : Index direction

This bit indicates in which direction the Index event resets the counter.

00: Index resets the counter whatever the direction

01: Index resets the counter when up-counting only

10: Index resets the counter when down-counting only

11: Reserved

Bit 0 IE : Index enable

This bit indicates if the Index event resets the counter.

0: Index disabled

1: Index enabled

29.6.26 TIM1 timer input selection register (TIM1_TISEL)

Address offset: 0x05C

Reset value: 0x0000 0000

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

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

Bits 27:24 TI4SEL[3:0] : Selects tim_ti4[15:0] input

0000: tim_ti4_in0: TIMx_CH4

0001: tim_ti4_in1

...

1111: tim_ti4_in15

Refer to Section 29.3.2: TIM1 pins and internal signals for interconnects list.

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

Bits 19:16 TI3SEL[3:0] : Selects tim_ti3[15:0] input

0000: tim_ti3_in0: TIMx_CH2

0001: tim_ti3_in1

...

1111: tim_ti3_in15

Refer to Section 29.3.2: TIM1 pins and internal signals for interconnects list.

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

Bits 11:8 TI2SEL[3:0] : Selects tim_ti2[15:0] input

0000: tim_ti2_in0: TIMx_CH2

0001: tim_ti2_in1

...

1111: tim_ti2_in15

Refer to Section 29.3.2: TIM1 pins and internal signals for interconnects list.

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

Bits 3:0 TI1SEL[3:0] : Selects tim_ti1[15:0] input

0000: tim_ti1_in0: TIMx_CH1

0001: tim_ti1_in1

...

1111: tim_ti1_in15

Refer to Section 29.3.2: TIM1 pins and internal signals for interconnects list.

29.6.27 TIM1 alternate function option register 1 (TIM1_AF1)

Address offset: 0x060

Reset value: 0x0000 0001

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ETRSEL[3:2]
rwrw
1514131211109876543210
ETRSEL[1:0]BK
CMP4P
BK
CMP3P
BK
CMP2P
BK
CMP1P
BKINPBK
CMP8E
BK
CMP7E
BK
CMP6E
BK
CMP5E
BK
CMP4E
BK
CMP3E
BK
CMP2E
BK
CMP1E
BKINE
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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

Bits 17:14 ETRSEL[3:0] : etr_in source selection

These bits select the etr_in input source.

0000: tim_etr0: TIMx_ETR input

0001: tim_etr1

...

1111: tim_etr15

Refer to Section 29.3.2: TIM1 pins and internal signals for product specific implementation.

Note: These bits can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 13 BKCMP4P : tim_brk_cmp4 input polarity

This bit selects the tim_brk_cmp4 input sensitivity. It must be programmed together with the BKP polarity bit.

0: tim_brk_cmp4 input polarity is not inverted (active low if BKP = 0, active high if BKP = 1)

1: tim_brk_cmp4 input polarity is inverted (active high if BKP = 0, active low if BKP = 1)

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 12 BKCMP3P : tim_brk_cmp3 input polarity

This bit selects the tim_brk_cmp3 input sensitivity. It must be programmed together with the BKP polarity bit.

0: tim_brk_cmp3 input polarity is not inverted (active low if BKP = 0, active high if BKP = 1)

1: tim_brk_cmp3 input polarity is inverted (active high if BKP = 0, active low if BKP = 1)

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 11 BKCMP2P : tim_brk_cmp2 input polarity

This bit selects the tim_brk_cmp2 input sensitivity. It must be programmed together with the BKP polarity bit.

0: tim_brk_cmp2 input polarity is not inverted (active low if BKP = 0, active high if BKP = 1)

1: tim_brk_cmp2 input polarity is inverted (active high if BKP = 0, active low if BKP = 1)

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 10 BKCMP1P : tim_brk_cmp1 input polarity

This bit selects the tim_brk_cmp1 input sensitivity. It must be programmed together with the BKP polarity bit.

0: tim_brk_cmp1 input polarity is not inverted (active low if BKP = 0, active high if BKP = 1)

1: tim_brk_cmp1 input polarity is inverted (active high if BKP = 0, active low if BKP = 1)

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_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 polarity is not inverted (active low if BKP = 0, active high if BKP = 1)

1: TIMx_BKIN input polarity is inverted (active high if BKP = 0, active low if BKP = 1)

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_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 TIMx_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 TIMx_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 TIMx_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 TIMx_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 TIMx_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 TIMx_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 TIMx_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 TIMx_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 TIMx_BDTR register).

Note: Refer to Section 29.3.2: TIM1 pins and internal signals for product specific implementation.

29.6.28 TIM1 alternate function register 2 (TIM1_AF2)

Address offset: 0x064

Reset value: 0x0000 0001

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OCRSEL[2:0]
rwrwrw
1514131211109876543210
Res.Res.BK2C
MP4P
BK2C
MP3P
BK2C
MP2P
BK2C
MP1P
BK2IN
P
BK2CM
P8E
BK2C
MP7E
BK2C
MP6E
BK2C
MP5E
BK2C
MP4E
BK2CMP
3E
BK2CMP
2E
BK2CM
P1E
BK2INE
rwrwrwrwrwrwrwrwrwrwrwrwrwrw

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

Bits 18:16 OCRSEL[2:0] : ocref_clr source selection

These bits select the ocref_clr input source.

000: tim_ocref_clr0

001: tim_ocref_clr1

...

111: tim_ocref_clr7

Refer to Section 29.3.2: TIM1 pins and internal signals for product specific information.

Note: These bits can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

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

Bit 13 BK2CMP4P : tim_brk2_cmp4 input polarity

This bit selects the tim_brk2_cmp4 input sensitivity. It must be programmed together with the BK2P polarity bit.

0: tim_brk2_cmp4 input polarity is not inverted (active low if BK2P = 0, active high if BK2P = 1)

1: tim_brk2_cmp4 input polarity is inverted (active high if BK2P = 0, active low if BK2P = 1)

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 12 BK2CMP3P : tim_brk2_cmp3 input polarity

This bit selects the tim_brk2_cmp3 input sensitivity. It must be programmed together with the BK2P polarity bit.

0: tim_brk2_cmp3 input polarity is not inverted (active low if BK2P = 0, active high if BK2P = 1)

1: tim_brk2_cmp3 input polarity is inverted (active high if BK2P = 0, active low if BK2P = 1)

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 11 BK2CMP2P : tim_brk2_cmp2 input polarity

This bit selects the tim_brk2_cmp2 input sensitivity. It must be programmed together with the BK2P polarity bit.

0: tim_brk2_cmp2 input polarity is not inverted (active low if BK2P = 0, active high if BK2P = 1)

1: tim_brk2_cmp2 input polarity is inverted (active high if BK2P = 0, active low if BK2P = 1)

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 10 BK2CMP1P : tim_brk2_cmp1 input polarity

This bit selects the tim_brk2_cmp1 input sensitivity. It must be programmed together with the BK2P polarity bit.

0: tim_brk2_cmp1 input polarity is not inverted (active low if BK2P = 0, active high if BK2P = 1)

1: tim_brk2_cmp1 input polarity is inverted (active high if BK2P = 0, active low if BK2P = 1)

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 9 BK2INP : TIMx_BKIN2 input polarity

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

0: TIMx_BKIN2 input polarity is not inverted (active low if BK2P = 0, active high if BK2P = 1)

1: TIMx_BKIN2 input polarity is inverted (active high if BK2P = 0, active low if BK2P = 1)

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 8 BK2CMP8E : tim_brk2_cmp8 enable

This bit enables the tim_brk2_cmp8 for the timer's tim_brk2 input. tim_brk2_cmp8 output is 'ORed' with the other tim_brk2 sources.

0: tim_brk2_cmp8 input disabled

1: tim_brk2_cmp8 input enabled

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 7 BK2CMP7E : tim_brk2_cmp7 enable

This bit enables the tim_brk2_cmp7 for the timer's tim_brk2 input. tim_brk2_cmp7 output is 'ORed' with the other tim_brk2 sources.

0: tim_brk2_cmp7 input disabled

1: tim_brk2_cmp7 input enabled

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 6 BK2CMP6E : tim_brk2_cmp6 enable

This bit enables the tim_brk2_cmp6 for the timer's tim_brk2 input. tim_brk2_cmp6 output is 'ORed' with the other tim_brk2 sources.

0: tim_brk2_cmp6 input disabled

1: tim_brk2_cmp6 input enabled

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 5 BK2CMP5E : tim_brk2_cmp5 enable

This bit enables the tim_brk2_cmp5 for the timer's tim_brk2 input. tim_brk2_cmp5 output is 'ORed' with the other tim_brk2 sources.

0: tim_brk2_cmp5 input disabled

1: tim_brk2_cmp5 input enabled

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 4 BK2CMP4E : tim_brk2_cmp4 enable

This bit enables the tim_brk2_cmp4 for the timer's tim_brk2 input. tim_brk2_cmp4 output is 'ORed' with the other tim_brk2 sources.

0: tim_brk2_cmp4 input disabled

1: tim_brk2_cmp4 input enabled

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 3 BK2CMP3E : tim_brk2_cmp3 enable

This bit enables the tim_brk2_cmp3 for the timer's tim_brk2 input. tim_brk2_cmp3 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp3 input disabled
1: tim_brk2_cmp3 input enabled

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 2 BK2CMP2E : tim_brk2_cmp2 enable

This bit enables the tim_brk2_cmp2 for the timer's tim_brk2 input. tim_brk2_cmp2 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp2 input disabled
1: tim_brk2_cmp2 input enabled

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 1 BK2CMP1E : tim_brk2_cmp1 enable

This bit enables the tim_brk2_cmp1 for the timer's tim_brk2 input. tim_brk2_cmp1 output is 'ORed' with the other tim_brk2 sources.
0: tim_brk2_cmp1 input disabled
1: tim_brk2_cmp1 input enabled

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Bit 0 BK2INE : TIMx_BKIN2 input enable

This bit enables the TIMx_BKIN2 alternate function input for the timer's tim_brk2 input.
TIMx_BKIN2 input is 'ORed' with the other tim_brk2 sources.
0: TIMx_BKIN2 input disabled
1: TIMx_BKIN2 input enabled

Note: This bit can not be modified as long as LOCK level 1 has been programmed (LOCK bits in TIMx_BDTR register).

Note: Refer to Section 29.3.2: TIM1 pins and internal signals for product specific implementation.

29.6.29 TIM1 DMA control register (TIM1_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 TIMx_DMAR address).

0000: Reserved

0001: Update

0010: CC1

0011: CC2

0100: CC3

0101: CC4

0110: COM

0111: Trigger

Others: reserved

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

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

This 5-bit vector defines the length of DMA transfers (the timer recognizes a burst transfer when a read or a write access is done to the TIMx_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

...

11010: 26 transfers

Example: Let us consider the following transfer: DBL = 7 bytes & DBA = TIM2_CR1.

–If DBL = 7 bytes and DBA = TIM2_CR1 represents the address of the byte to be transferred, the address of the transfer is given by the following equation:

(TIMx_CR1 address) + DBA + (DMA index), where DMA index = DBL

In this example, 7 bytes are added to (TIMx_CR1 address) + DBA, which gives us the address from/to which the data are copied. In this case, the transfer is done to 7 registers starting from the following address: (TIMx_CR1 address) + DBA

According to the configuration of the DMA Data Size, several cases may occur:

–If the DMA Data Size is configured in half-words, 16-bit data are transferred to each of the 7 registers.

–If the DMA Data Size is configured in bytes, the data are also transferred to 7 registers: the first register contains the first MSB byte, the second register, the first LSB byte and so on.

So with the transfer Timer, one also has to specify the size of data transferred by DMA.

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

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

This 5-bits vector defines the base-address for DMA transfers (when read/write access are done through the TIMx_DMAR address). DBA is defined as an offset starting from the address of the TIMx_CR1 register.

Example:

00000: TIMx_CR1

00001: TIMx_CR2

00010: TIMx_SMCR

...

29.6.30 TIM1 DMA address for full transfer (TIM1_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 (TIMx_CR1 address) + (DBA + DMA index) x 4

where TIMx_CR1 address is the address of the control register 1, DBA is the DMA base address configured in TIMx_DCR register, DMA index is automatically controlled by the DMA transfer, and ranges from 0 to DBL (DBL configured in TIMx_DCR).

29.6.31 TIM1 register map

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

Table 275. TIM1 register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x000TIMx_CR1Res.Res.Res.Res.DITHENUIFREMARes.CKD[1:0]ARPECMS[1:0]DIROPMURSUDISCEN
Reset value000000000000
0x004TIMx_CR2Res.MMS[3]Res.MMS2[3:0]Res.OIS6Res.OIS5OIS4NOIS4OIS3NOIS3OIS2NOIS2OIS1NOIS1TI1SMMS[2:0]CCDSCCUSRes.CCPC
Reset value0000000000000000000000
0x008TIMx_SMCRRes.SMSPSSMSPERes.TS[4:3]Res.SMS[3]ETPECEETPS[1:0]ETF[3:0]MSMTS[2:0]OCCSSMS[2:0]
Reset value000000000000000000000
0x00CTIMx_DIERRes.TERRIEIERIEDIRIEIDXIERes.TDECOMDECC4DECC3DECC2DECC1DEUDEBIETIECOMIECC4IECC3IECC2IECC1IEUIE
Reset value0000000000000000000
0x010TIMx_SRRes.TERRFIERRFDIRFIDXFRes.CC6IFCC5IFRes.SBIFCC4OFCC3OFCC2OFCC1OFB2IFBIFTIFCOMIFCC4IFCC3IFCC2IFCC1IFUIF
Reset value000000000000000000000
0x014TIMx_EGRRes.B2GBGTGCOMGCC4GCC3GCC2GCC1GUG
Reset value000000000

Table 275. TIM1 register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x018TIMx_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]
CC2
S
[1:0]
IC1F[3:0]IC1
PSC
[1:0]
CC1
S
[1:0]
Reset value0000000000000000
TIMx_CCMR1
Output Compare mode
Res.Res.Res.Res.Res.Res.Res.OC2M[3]Res.Res.Res.Res.Res.Res.Res.OC1M[3]OC2CEOC2M[2:0]OC2PEOC2FECC2
S
[1:0]
OC1CEOC1M[2:0]OC1PEOC1FECC1
S
[1:0]
Reset value000000000000000000
0x01CTIMx_CCMR2Res.Res.Res.Res.Res.Res.Res.OC4M[3]Res.Res.Res.Res.Res.Res.Res.OC3M[3]OC4CEOC4M[2:0]OC4PEOC4FECC4
S
[1:0]
OC3CEOC3M[2:0]OC3PEOC3FECC3
S
[1:0]
Reset value000000000000000000
TIMx_CCMR2Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.IC4F[3:0]IC4
PSC
[1:0]
CC4
S
[1:0]
IC3F[3:0]IC3
PSC
[1:0]
CC3
S
[1:0]
Reset value0000000000000000
0x020TIMx_CCERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.CC6PCC6ERes.Res.CC5PCC5ECC4NPCC4NECC4PCC4ECC3NPCC3NECC3PCC3ECC2NPCC2NECC2PCC2ECC1NPCC1NECC1PCC1E
Reset value00000000000000000000
0x024TIMx_CNTUIFCPYRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CNT[15:0]
Reset value00000000000000000
0x028TIMx_PSCRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.PSC[15:0]
Reset value0000000000000000
0x02CTIMx_ARRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ARR[19:0]
Reset value00001111111111111111
0x030TIMx_RCRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.REP[15:0]
Reset value0000000000000000
0x034TIMx_CCR1Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CCR1[19:0]
Reset value00000000000000000000
0x038TIMx_CCR2Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CCR2[19:0]
Reset value00000000000000000000
0x03CTIMx_CCR3Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CCR3[19:0]
Reset value00000000000000000000
0x040TIMx_CCR4Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CCR4[19:0]
Reset value00000000000000000000
0x044TIMx_BDTRRes.Res.BK2BIDBKBIDBK2DSRMBKDSRMBK2PBK2EBK2F[3:0]BKF[3:0]MOEAOEBKPBKEOSSROSSILOC
K
[1:0]
DT[7:0]
Reset value000000000000000000000000000000

Table 275. TIM1 register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x048TIMx_CCR5GC5C3GC5C2GC5C1Res.Res.Res.Res.Res.Res.Res.Res.Res.CCR5[19:0]
Reset value00000000000000000000000
0x04CTIMx_CCR6Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CCR6[19:0]
Reset value00000000000000000000
0x050TIMx_CCMR3Res.Res.Res.Res.Res.Res.Res.OC6M[3]Res.Res.Res.Res.Res.Res.Res.OC5M[3]OC6CEOC6M [2:0]OC6PEOC6FERes.Res.OC5CEOC5M [2:0]OC5PEOC5FERes.Res.Res.Res.
Reset value0000000000000
0x054TIMx_DTR2Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DTPEDTAERes.Res.Res.Res.Res.Res.Res.Res.DTGF[7:0]
Reset value00000000000
0x058TIMx_ECRRes.Res.Res.Res.Res.PWPRSC[2:0]PW[7:0]Res.Res.Res.Res.Res.Res.Res.Res.IPOS [1:0]FIDXIBLK [1:0]IDIR [1:0]IE
Reset value0000000000000000000
0x05CTIMx_TISELRes.Res.Res.Res.TI4SEL[3:0]Res.Res.Res.Res.TI3SEL[3:0]Res.Res.Res.Res.TI2SEL[3:0]Res.Res.Res.Res.TI1SEL[3:0]
Reset value0000000000000000
0x060TIMx_AF1Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res ETRSEL [3:0]BK2CMP4PBK2CMP3PBK2CMP2PBK2CMP1PBKINPBK2CMP8EBK2CMP7EBK2CMP6EBK2CMP5EBK2CMP4EBK2CMP3EBK2CMP2EBK2CMP1EBKINE
Reset value000000000000000001
0x064TIMx_AF2Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OCRSEL [2:0]Res.BK2CMP4PBK2CMP3PBK2CMP2PBK2CMP1PBK2INPBK2CMP8EBK2CMP7EBK2CMP6EBK2CMP5EBK2CMP4EBK2CMP3EBK2CMP2EBK2CMP1EBK2INE
Reset value00000000000000001
0x068..0x3D8ReservedRes.
0x3DCTIMx_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
0x3E0TIMx_DMARDMAB[31:0]
Reset value00000000000000000000000000000000
Refer to Section 2.3: Memory organization for the register boundary addresses.