WCH CH32V003 Series Reference Manual page 118

Table of Contents

Advertisement

CH32V003 Reference Manual
OC1REF
ATRLR
CHxCVR
As shown in Figure 11-4, a positive pulse of length Tpulse needs to be generated on OC1 after a delay Tdelay
at the beginning of a rising edge detected on the TI2 input pin.
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 defined by the Compare Capture Register and Tpulse is determined by the value of the Auto
Reload Value Register and the Compare Capture Register.
11.3.7 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 encoderwill add or subtract one from the core counter. 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 the comparison capture channels 1 and 2, and set a reload
value counter value, 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 11-1 Relationship between counting direction and encoder signal of timer encoder mode
Counting effective edges
Counting at TI1 edge only
Counting at TI2 edge only
Double edge counting at
TI1 and TI2
V1.3
Figure 11-4 Event Generation and Impulse Response
TI2
OC1
0
t
DELAY
The level
of relative
signals
High
Low
High
Low
High
Low
t
PULSE
TI1FP1 signal edge
Rising
Falling
edge
edge
Downward
Upward
counting
counting
Upward
Downward
counting
counting
No count
Downward
Upward
counting
counting
Upward
Downward
counting
counting
118
http://wch.cn
t
TI2FP2 signal edge
Rising
Falling
edge
edge
No count
Upward
Downward
counting
counting
Downward
Upward
counting
counting
Upward
Downward
counting
counting
Downward
Upward
counting
counting

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents