
Rev. 1.00
226 of 576
January 28, 2022
32-Bit Arm
®
Cortex
®
-M0+ MCU
HT32F54231/HT32F54241/HT32F54243/HT32F54253
14 General-Purpose T
imer (GPTM)
Center-Aligned Counting
In the center-aligned counting mode, the counter counts up from 0 to the counter-reload value
and then counts down to 0 alternatively. The Timer module generates an overflow event when the
counter counts to the counter-reload value in the up-counting mode and generates an underflow
event when the counter counts to 0 in the down-counting mode. The counting direction bit DIR in
the CNTCFR register is read-only and indicates the counting direction when in the center-aligned
mode. The counting direction is updated by hardware automatically.
Setting the UEVG bit in the EVGR register will initialize the counter value to 0 irrespective of
whether the counter is counting up or down in the center-aligned counting mode.
The update event interrupt flag bit in the INTSR register will be set to 1, when an overflow or
underflow event occurs.
CK_PSC
CNT_EN
F3
F4
4
CK_CNT
F2
F5
CNTR
CRR Shadow
Register
CRR
4
F5
4
3
2
1
0
Counter Underflow
Update Event Flag
Software clearing
Write a new value
Counter Overflow
1
2
3
Software clearing
Figure 42. Center-aligned Counting Example
Clock Controller
The following describes the Timer Module clock controller which determines the clock source of
the internal prescaler counter.
▆
Internal APB clock f
CLKIN
:
The default internal clock source is the APB clock f
CLKIN
used to drive the counter prescaler when
the slave mode is disabled. When the slave mode selection bits SMSEL in the MDCFR register
are set to 0x4, 0x5 or 0x6, the internal APB clock f
CLKIN
is the counter prescaler driving clock
source. If the slave mode controller is enabled by setting SMSEL field in the MDCFR register
to an available value including 0x1, 0x2, 0x3 and 0x7, the prescaler is clocked by other clock
sources selected by the TRSEL field in the TRCFR register and described as follows.
▆
Quadrature Decoder:
To select Quadrature Decoder mode the SMSEL field should be set to 0x1, 0x2 or 0x3 in the
MDCFR register. The Quadrature Decoder function uses two input states of the GT_CH0 and
GT_CH1 pins to generate the clock pulse to drive the counter prescaler. The counting direction
bit DIR is modified by hardware automatically at each transition on the input source signal. The
input source signal can be derived from the GT_CH0 pin only, the GT_CH1 pin only or both
GT_CH0 and GT_CH1 pins.