AT32F421
Series Reference Manual
2022.11.11
Page 258
Rev 2.02
When TMRx_EXT is selected as the TRGIN, configure the external signal polarity (by setting the
ESP bit in the TMRx_STCTRL register), external signal division (by setting the ESDIV[1:0] bit in the
TMRx_STCTRL register) and external signal filter (by setting the ESF[3:0] bit in the TMRx_STCTRL
register).
–
Set the TRGIN signal source by setting the STIS[1:0] bit in the TMRx_STCTRL register.
–
Enable external clock mode A by setting
SMSEL=3’b111 in the TMRx_STCTRL register.
–
Set counter counting frequency by setting the DIV[15:0] bit in the TMRx_DIV register.
–
Set counter counting period by setting the PR[15:0] bit in the TMRx_PR register.
–
Enable counter by setting the TMREN bit in the TMRx_CTRL1 register.
To use external clock mode B, follow the configuration steps as below:
–
Set external signal polarity by setting the ESP bit in the TMRx_STCTRL register.
–
Set external signal frequency division by setting the ESDIV[1:0] bit in the TMRx_STCTRL register.
–
Set external signal filter by setting the ESF[3:0] bit in the TMRx_STCTRL register.
–
Enable external clock mode B by setting the ECMBEN bit in the TMRx_STCTRL register.
–
Set counter counting frequency by setting the DIV[15:0] bit in the TMRx_DIV register.
–
Set counter counting period by setting the PR[15:0] bit in the TMRx_PR register.
Enable counter by setting the TMREN bit in the TMRx_CTRL1 register.
Figure 14-94
Block diagram of external clock mode A
EXT
C1IFP2
C1IFP1
C1INC
ISx
CK_DIV
Trigger select
Slave mode
control
External clock
control
CI1RAW
Filter
Edge detector
C2IF_Rising
C2IF_Falling
Polarity
selection
Note: The delay between the signal on the input side and the actual clock of the counter is due to the
synchronization circuit.
Figure 14-95 Counting in external clock mode A, with PR=0x32 and DIV=0x0
30
COUNTER
OVFIF
TMR_CLK
110
STIS[2:0]
Clear
CNT_CLK
C2IRAW
000
C2IF[2:0]
31
32
0
1
2
3
4