Advanced-control timers (TIM1/TIM8/TIM20) RM0440
1166/2126 RM0440 Rev 4
input stage) on page 1111). The captured value, which corresponds to the time elapsed
between 2 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.
Example: one wants to change the PWM configuration of the advanced-control timer after a
programmed delay each time a change occurs on the Hall inputs connected to one of the
TIMx timers.
• Configure 3 timer inputs ORed to the tim_ti1 input channel by writing the TI1S bit in the
TIMx_CR2 register to ‘1’,
• Program the time base: write the TIMx_ARR to the max value (the counter must be
cleared by the tim_ti1 change. Set the prescaler to get a maximum counter period
longer than the time between 2 changes on the sensors,
• Program the channel 1 in capture mode (tim_trc selected): write the CC1S bits in the
TIMx_CCMR1 register to ‘01’. The digital filter can also be programmed if needed,
• Program the channel 2 in PWM 2 mode with the desired delay: write the OC2M bits to
‘111’ and the CC2S bits to ‘00’ in the TIMx_CCMR1 register,
• Select tim_oc2ref as trigger output on tim_trgo: write the MMS bits in the TIMx_CR2
register to ‘101’,
In the advanced-control timer, the right tim_itrx input must be selected as trigger input, the
timer is programmed to generate PWM signals, the capture/compare control signals are
preloaded (CCPC=1 in the 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).
The Figure 353 describes this example.