
CH32V003
Reference Manual
V1.3
94
Figure 10-5 Generation of single pulse
1)
Set TI2 to trigger. Setting the CC2S field to 01b to map TI2FP2 to TI2; setting the CC2P bit to 0b to set
TI2FP2 as rising edge detection; setting the TS field to 110b to set TI2FP2 as trigger source; setting the
SMS field to 110b to set TI2FP2 to be used to start the counter.
2)
Tdelay is determined by the value of the Compare Capture Register, and Tpulse is determined by the
value of the Auto Reload Value Register and the Compare Capture Register.
10.3.9 Encoder mode
The encoder mode is a typical application of the timer and can be used to access the biphasic output of the
encoder. The counting direction of the core counter is synchronized with the direction of the encoder's rotation
axis, and each pulse output from the encoder will cause the core counter to add or subtract one. To use the
encoder, set the SMS field to 001b (count only on TI2 edge), 010b (count only on TI1 edge) or 011b (count on
both TI1 and TI2 edges), connect the encoder to the input of comparison capture channels 1 and 2, and set a
value for the reload value register, which can be set to a larger value. When in encoder mode, the internal
compare capture register, prescaler, repeat count register, etc. of the timer are working normally. The following
table shows the relationship between the counting direction and the encoder signal.
Table 10-1 Relationship between counting direction and encoder signal of timer encoder mode
Counting effective edges
The level
of
relative
signals
TI1FP1 signal edge
TI2FP2 signal
Rising
edge
Falling
edge
Rising
edge
Falling
edge
Counting at TI1 edge only
high
Downward
counting
Upward
counting
No count
low
Upward
counting
Downward
counting
Counting at TI2 edge only
high
No count
Upward
counting
Downward
counting
low
Downward
counting
Upward
counting
Double edge counting at
TI1 and TI2
high
Downward
counting
Upward
counting
向上计数
Downward
counting
low
Upward
counting
Downward
counting
Downward
counting
Upward
counting
Co
un
te
r