AT32F421
Series Reference Manual
2022.11.11
Page 257
Rev 2.02
Figure 14-92 Count clock
0
1
External clock mode B
(ECMBEN=1)
TMRx_EXT
ESF
filter
0
1
External clock mode A
(SMSEL=3'b111)
TRGIN
STIS[1:0]
IS0
IS3
IS2
IS1
STIS[1:0]
EXT
C1INC
C1IFP1
C2IPF2
0
1
STIS[2]
External trigger
Internal trigger
0
1
Encoder mode
(SMSEL=3'b001/010/011)
CI1FP1/CI2FP2
CK_INT(form CRM)
DIV_counter
CK_CNT
CNT_counter
ESP
ESDIV
polarity edge
detector
prescaler
Internal clock (CK_INT)
By default, the CK_INT divided by the prescaler is used to drive the counter to start counting. The
configuration process is as follows:
-
Set the CLKDIV[1:0] bit in the TMRx_CTRL1 register to set the CK_INT frequency;
-
Set the TWCMSEL[1:0] bit in the TMRx_CTRL1 register to select count mode. If the one-way count
direction is set, configure OWCDIR bit in the TMRx_CTRL1 register to select the specific direction.
-
Set the TMRx_DIV register to set the counting frequency;
-
Set the TMRx_PR register to set the counting period;
-
Set the TMREN bit in the TMRx_CTRL1 register to enable the counter.
Figure 14-93
Use CK_INT to drive counter, with TMRx_DIV=0x0 and TMRx_PR=0x16
CK_INT
TMREN
COUNTER
12
11
13
14
15
16
00
01
02
03
04
05
06
07
overflow
OVFIF
External clock
(
TRGIN/EXT
)
The counter clock can be provided by two external clock sources, namely, TRGIN and EXT signals.
When SMSEL=3’b111, external clock mode A is selected. Set the STIS[2:0] bit to select TRGIN signal
to drive the counter to start counting. The external clock sources include: C1INC (STIS=3’b100, channel
1 rising edge and falling edge), C1IFP1 (STIS=3’b101, channel 1 signal with filtering and polarity
selection), C2IFP2 (STIS=3’b110, channel 2 signal with filtering and polarity selection) and EXT
(STIS=3’b111, external input signal after polarity selection, frequency division and filtering).
When ECMBEN=1, external clock mode B is selected. The counter is driven by the external input signal
EXT that has gone through polarity selection, frequency division and filtering. External clock mode B is
equivalent to external clock mode A with EXT signal as the TRGIN.
To use external clock mode A, follow the configuration steps as below:
–
Configure the external clock source TRGIN.
When TMRx_CH1 is selected as the TRGIN, configure the channel 1 input filter (by setting the
C1DF[3:0] bit in the TMRx_CM1 register) and channel 1 input polarity (by setting the C1P/C1CP in
the TMRx_CCTRL register).
When TMRx_CH2 is selected as the TRGIN, configure the channel 2 input filter (by setting the
C2DF[3:0] bit in the TMRx_CM1 register) and channel 1 input polarity (by setting the C2P/C2CP in
the TMRx_CCTRL register).