General-purpose timers (TIM15/TIM16/TIM17) RM0440
1364/2126 RM0440 Rev 4
30.4.9 PWM input mode (only for TIM15)
This mode allows to measure both the period and the duty cycle of a PWM signal connected
to single tim_tix input:
• The TIMx_CCR1 register holds the period value (interval between two consecutive
rising edges)
• The TIMx_CCR2 register holds the pulsewidth (interval between two consecutive rising
and falling edges
This mode is a particular case of input capture mode. The set-up procedure is similar with
the following differences:
• Two tim_icx signals are mapped on the same tim_tix input.
• These 2 tim_icx signals are active on edges with opposite polarity.
• One of the two tim_tixfpy signals is selected as trigger input and the slave mode
controller is configured in reset mode.
For example, one can measure the period (in TIMx_CCR1 register) and the duty cycle (in
TIMx_CCR2 register) of the PWM applied on tim_ti1 using the following procedure
(depending on tim_ker_ck frequency and prescaler value):
1. Select the proper tim_ti1_in[0.15] source (internal or external) with the TI1SEL[3:0] bits
in the TIMx_TISEL register.
2. Select the active input for TIMx_CCR1: write the CC1S bits to 01 in the TIMx_CCMR1
register (tim_ti1 selected).
3. Select the active polarity for tim_ti1fp1 (used both for capture in TIMx_CCR1 and
counter clear): write the CC1P and CC1NP bits to ‘0’ (active on rising edge).
4. Select the active input for TIMx_CCR2: write the CC2S bits to 10 in the TIMx_CCMR1
register (tim_ti1 selected).
5. Select the active polarity for tim_ti1fp2 (used for capture in TIMx_CCR2): write the
CC2P and CC2NP bits to ‘10’ (active on falling edge).
6. Select the valid trigger input: write the TS bits to 00101 in the TIMx_SMCR register
(tim_ti1fp1 selected).
7. Configure the slave mode controller in reset mode: write the SMS bits to 100 in the
TIMx_SMCR register.
8. Enable the captures: write the CC1E and CC2E bits to ‘1’ in the TIMx_CCER register.