General-purpose timers (TIM2 to TIM5)
RM0090
594/1731
DocID018909 Rev 11
Internal clock source (CK_INT)
If the slave mode controller is disabled (SMS=000 in the TIMx_SMCR register), 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 CK_INT.
shows the behavior of the control circuit and the upcounter in normal mode,
without prescaler.
Figure 154. Control circuit in normal mode, internal clock divided by 1
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 155. TI2 external clock connection example
For example, to configure the upcounter to count in response to a rising edge on the TI2
input, use the following procedure:
1.
Configure channel 2 to detect rising edges on the TI2 input by writing CC2S= ‘01 in the
TIMx_CCMR1 register.
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).
CK_INT
00
Counter clock = CK_CNT = CK_PSC
COUNTER REGISTER
01 02 03 04 05 06 07
32 33 34 35 36
31
CEN=CNT_EN
UG
CNT_INIT
CK_INT
encoder
mode
external clock
mode 1
external clock
mode 2
internal clock
mode
ETRF
TRGI
TI1F
TI2F
or
or
or
(internal clock)
CK_PSC
ECE
TIMx_SMCR
SMS[2:0]
ITRx
TI1F_ED
TI1FP1
TI2FP2
ETRF
TIMx_SMCR
TS[2:0]
TI2
0
1
TIMx_CCER
CC2P
Filter
ICF[3:0]
TIMx_CCMR1
Edge
Detector
TI2F_Rising
TI2F_Falling
110
001
100
101
111