General-purpose timers (TIM2 to TIM5)
RM0090
598/1731
DocID018909 Rev 11
Figure 161. Output stage of capture/compare channel (channel 1)
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.
18.3.5 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 over-capture 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 you write it to 0.
The following example shows how to capture the counter value in TIMx_CCR1 when TI1
input rises. To do this, use the following procedure:
•
Select the active input: TIMx_CCR1 must be linked to the TI1 input, so write the CC1S
bits to 01 in the TIMx_CCMR1 register. As soon as CC1S becomes different from 00,
the channel is configured in input and the TIMx_CCR1 register becomes read-only.
•
Program the input filter duration you need with respect to the signal you connect to the
timer (by programming the ICxF bits in the TIMx_CCMRx register if the input is one of
the TIx inputs). Let’s imagine that, when toggling, the input signal is not stable during at
must 5 internal clock cycles. We must program a filter duration longer than these 5
clock cycles. We can validate a transition on TI1 when 8 consecutive samples with the
KƵƚƉƵƚŵŽĚĞ
EdхZϭ
EdсZϭ
ĐŽŶƚƌŽůůĞƌ
d/DdžͺDZϭ
KϭDϮ͗Ϭ
ŽĐϭƌĞĨ
Ϭ
ϭ
ϭW
d/DdžͺZ
KƵƚƉƵƚ
ŶĂďůĞ
ŝƌĐƵŝƚ
Kϭ
ϭ
d/DdžͺZ
dŽƚŚĞŵĂƐƚĞƌŵŽĚĞ
ĐŽŶƚƌŽůůĞƌ
dZ&
Ϭ
ϭ
KZ&ͺ>Z
KZ&ͺ>Zͺ/Ed
K^
d/Ddžͺ^DZ
Ăŝϭϳϭϴϳ