RM0016 16-bit advanced control timer (TIM1)
Doc ID 14587 Rev 8 171/449
17.5.7 PWM mode
Pulse width modulation mode allows you to generate a signal with a frequency determined
by the value of the TIM1_ARR register and a duty cycle determined by the value of the
TIM1_CCRi registers.
The PWM mode can be selected independently on each channel (one PWM per OCi output)
by writing 110 (PWM mode 1) or 111 (PWM mode 2) in the OCiM bits in the TIM1_CCMRi
registers. The corresponding preload register must be enabled by setting the OCiPE bits in
the TIM1_CCMRi registers. The auto-reload preload register (in up-counting or center-
aligned modes) may be optionally enabled by setting the ARPE bit in the TIM1_CR1
register.
As the preload registers are transferred to the shadow registers only when an UEV occurs,
all registers have to be initialized by setting the UG bit in the TIM1_EGR register before
starting the counter.
OCi polarity is software programmable using the CCiP bits in the TIM1_CCERi registers. It
can be programmed as active high or active low. The OCi output is enabled by a
combination of CCiE, MOE, OISi, OSSR and OSSI bits (TIM1_CCERi and TIM1_BKR
registers). Refer to the TIM1_CCERi register descriptions for more details.
In PWM mode (1 or 2), TIM1_CNT and TIM1_CCRi are always compared to determine
whether TIM1_CCRi ≤ TIM1_CNT or TIM1_CNT≤ TIM1_CCRi (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 TIM1_CR1 register.
PWM edge-aligned mode
Up-counting configuration
Up-counting is active when the DIR bit in the TIM1_CR1 register is low.
Example
This example uses PWM mode 1. The reference PWM signal, OCiREF, is high as long as
TIM1_CNT < TIM1_CCRi. Otherwise, it becomes low. If the compare value in TIM1_CCRi is
greater than the auto-reload value (in TIM1_ARR) then OCiREF is held at 1. If the compare
value is 0, OCiREF is held at 0. Figure 70 shows some edge-aligned PWM waveforms in an
example where TIM1_ARR = 8.