AT32F421
Series Reference Manual
2022.11.11
Page 182
Rev 2.02
Figure 14-17 Overflow event when PRBEN=1
0
1
2
3
...
21
22
0
1
2
3
...
31
32
0
1
2
3
COUNTER
31
32
0
1
32
...
PR[15:0]
OVFIF
TMR_CLK
0
DIV[15:0]
22
Clear
Clear
Clear
Downcounting mode
Set CMSEL[1:0]=2’b00 and OWCDIR=1’b1 in the TMRx_CTRL1 register to enable downcounting mode.
In downcounting mode, the counter counts from the value programmed in the TMRx_PR register down
to 0, and restarts from the value programmed, and generates a counter underflow event.
Figure 14-18 Counter timing diagram, internal clock divided by 4
TMR_CLK
CNT_CLK
COUNTER
OVFIF
0
1
2
3
4
DIV[15
:
0]
32
31
30
32
PR[15
:
0]
Clear
Up/down counting mode
Set CMSEL[1:0]≠2’b00 in the TMRx_CTRL1 register to enable up/down counting mode. In up/down
counting mode, the counter counts up/down alternatively. When the counter counts from the value
programmed in the TMRx_PR register down to 1, an underflow event is generated, and then restarts
counting from 0; When the counter counts from 0 to the value of the TMRx_PR register -1, an overflow
event is generated, and then restarts counting from the value of the TMRx_PR register. The OWCDIR
bit indicates the current counting direction.
The TWCMSEL[1:0] bit in the TMRx_CTRL1 register is also used to select the CxIF flag setting method
in up/down counting mode. In up/down counting mode 1 (T
WCMSEL[1:0]=2’b01), CxIF flag can only be
set when the counter counts down; in up/down counting mode 2 (T
WCMSEL[1:0]=2’b10), CxIF flag can
only be set when the counter counts up; in up/down counting mode 3 (T
WCMSEL[1:0]=2’b11), CxIF flag
can be set when the counter counts up/down.
Note: The OWCDIR is ready-only in up/down counting mode.