Configuring the Timer/Event Counter Input Clock Source
The Timer/Event Counter clock source can originate from various sources, an internal clock or an
external pin. The internal clock source is used when the timer is in the timer mode or in the pulse width
capture mode. For some Timer/Event Counters, this internal clock source may be first divided by a
prescaler, the division ratio of which is conditioned by the Timer Control Register bits. An external
clock source is used when the timer is in the event counting mode, the clock source being provided on
an external timer pin TC1. Depending upon the condition of the T1EG bit, each high to low, or low to
high transition on the external timer pin will increment the counter by one.
Timer Register
-
TMR, TMR0, TMR1L, TMR1H
The timer registers are special function registers located in the Special Purpose Data Memory and is
the place where the actual timer value is stored. These registers are known as TMR, TMR0, TMR1L
and TMR1H. The value in the timer registers increases by one each time an internal clock pulse is
received or an external transition occurs on the external timer pin. The timer will count from the initial
value loaded by the preload register to the full count of FFH for the 8-bit Timer/Event Counter or
FFFFH for the 16-bit Timer/Event Counters, at which point the timer overflows and an internal
interrupt signal is generated. The timer value will then be reset with the initial preload register value
and continue counting. Note that to achieve a maximum full range count of FFH or FFFFH, the
preload register must first be cleared to all zeros. It should be noted that after power-on, the preload
registers will be in an unknown condition.
Note that if the Timer/Event Counter is in an OFF condition and data is written to its preload register,
this data will be immediately written into the actual counter. However, if the counter is enabled and
counting, any new data written into the preload data register during this period will remain in the
preload register and will only be written into the actual counter the next time an overflow occurs.
Timer Control Register
-
TMRC, TMR0C, TMR1C
The flexible features of the Holtek microcontroller Timer/Event Counters enable them to operate in
three different modes, the options of which are determined by the contents of their respective control
register.
The Timer Control Register is known as TMRC, TMR0C and TMR1C. The TMRC or TMR0C is used
to control the 8-bit Timer while the TMR1C are used for 16-bit Timer. It is the Timer Control Register
together with its corresponding timer register that control the full operation of the Timer/Event
Counter. Before the timer can be used, it is essential that the Timer Control Register is fully
programmed with the right data to ensure its correct operation, a process that is normally carried out
during program initialisation.
The timer-on bit, which is bit 4 of the Timer Control Register and known as TON, T0ON or T1ON bit,
provides the basic on/off control of the respective timer. Setting the bit high allows the counter to run,
clearing the bit stops the counter. Bits 0~2 of the TMRC or TMR0C registers determine the division
ratio of the input clock prescaler. In addition, the TS, T0S and T1S bits select the internal clock source.
Rev. 1.50
68
April 28, 2020
BS83B08-3/B12-3/B16-3/B16G-3/C24-3
8-Bit Touch Key Flash MCU
f
S Y S
/ 4
M
U
X
T 1 S
T 1 O N
P r e l o a d R e g i s t e r
U p C o u n t e r
D a t a B u s
P F D
2
¸
T C 1
T 1 E G
M o d e C o n t r o l
O v e r f l o w
t o I n t e r r u p t
T 1 M 1 , T 1 M 0
T 1 O V
f
L I R C
16-bit Timer/Event Counter 1