English
Language : 

RM0365 Datasheet, PDF (580/1076 Pages) STMicroelectronics – This reference manual targets application developers
RM0365
General-purpose timers (TIM2/TIM3/TIM4)
Table 118. Counting direction versus encoder signals
Active edge
Level on opposite
signal (TI1FP1 for
TI2, TI2FP2 for TI1)
TI1FP1 signal
Rising
Falling
TI2FP2 signal
Rising
Falling
Counting on
TI1 only
High
Low
Down
Up
Up
Down
No Count
No Count
No Count
No Count
Counting on
TI2 only
Counting on
TI1 and TI2
High
Low
High
Low
No Count
No Count
Down
Up
No Count
No Count
Up
Down
Up
Down
Up
Down
Down
Up
Down
Up
An external incremental encoder can be connected directly to the MCU without external
interface logic. However, comparators are normally be used to convert the encoder’s
differential outputs to digital signals. This greatly increases noise immunity. The third
encoder output which indicate the mechanical zero position, may be connected to an
external interrupt input and trigger a counter reset.
Figure 225 gives an example of counter operation, showing count signal generation and
direction control. It also shows how input jitter is compensated where both edges are
selected. This might occur if the sensor is positioned near to one of the switching points. For
this example we assume that the configuration is the following:
• CC1S= 01 (TIMx_CCMR1 register, TI1FP1 mapped on TI1)
• CC2S= 01 (TIMx_CCMR2 register, TI2FP2 mapped on TI2)
• CC1P and CC1NP = ‘0’ (TIMx_CCER register, TI1FP1 noninverted, TI1FP1=TI1)
• CC2P and CC2NP = ‘0’ (TIMx_CCER register, TI2FP2 noninverted, TI2FP2=TI2)
• SMS= 011 (TIMx_SMCR register, both inputs are active on both rising and falling
edges)
• CEN= 1 (TIMx_CR1 register, Counter is enabled)
Figure 225. Example of counter operation in encoder interface mode
IRUZDUG
MLWWHU
EDFNZDUG
MLWWHU
IRUZDUG
7,
7,
&RXQWHU
XS
GRZQ
XS
069
Figure 226 gives an example of counter behavior when TI1FP1 polarity is inverted (same
configuration as above except CC1P=1).
DocID025202 Rev 4
580/1077
615