The counter will start counting clock ticks according to the prescaler setting in the Clock Select bit
field (CLKSEL) in TCAn.CTRLA.
•
Optional: By writing a '1' to the Enable Count on Event Input bit (CNTEI) in the Event Control
register (TCAn.EVCTRL), event inputs are counted instead of clock ticks.
•
The counter value can be read from the Counter bit field (CNT) in the Counter register
(TCAn.CNT).
19.3.3
Operation
19.3.3.1 Normal Operation
In normal operation, the counter is counting clock ticks in the direction selected by the Direction bit (DIR)
in the Control E register (TCAn.CTRLE), until it reaches TOP or BOTTOM. The clock ticks are from the
peripheral clock CLK_PER, optionally prescaled, depending on the Clock Select bit field (CLKSEL) in the
Control A register (TCAn.CTRLA).
When up-counting and TOP are reached, the counter will wrap to zero at the next clock tick. When down-
counting, the counter is reloaded with the Period register value (TCAn.PER) when BOTTOM is reached.
Figure 19-4. Normal Operation
CNT
DIR
It is possible to change the counter value in the Counter register (TCAn.CNT) when the counter is
running. The write access to TCAn.CNT has higher priority than count, clear, or reload, and will be
immediate. The direction of the counter can also be changed during normal operation by writing to DIR in
TCAn.CTRLE.
19.3.3.2 Double Buffering
The Period register value (TCAn.PER) and the Compare n register values (TCAn.CMPn) are all double
buffered (TCAn.PERBUF and TCAn.CMPnBUF).
Each buffer register has a Buffer Valid flag (PERBV, CMPnBV) in the Control F register (TCAn.CTRLF),
which indicates that the buffer register contains a valid, i.e. new, value that can be copied into the
corresponding Period or Compare register. When the Period register and Compare n registers are used
for a compare operation, the BV flag is set when data is written to the buffer register and cleared on an
UPDATE condition. This is shown for a Compare register (CMPn) below.
©
2018 Microchip Technology Inc.
MAX
TOP
BOTTOM
16-bit Timer/Counter Type A (TCA)
CNT written
Datasheet Preliminary
®
megaAVR
0-Series
"update"
DS40002015A-page 188
Need help?
Do you have a question about the megaAVR 0 Series and is the answer not in the manual?
Questions and answers