In general, the term timer is used when the timer/counter is counting periodic clock ticks. The term
counter is used when the input signal has sporadic or irregular ticks.
20.3.2
Initialization
By default, the TCB is in Periodic Interrupt mode. Follow these steps to start using it:
•
Write a TOP value to the Compare/Capture register (TCBn.CCMP).
•
Enable the counter by writing a '1' to the ENABLE bit in the Control A register (TCBn.CTRLA).
The counter will start counting clock ticks according to the prescaler setting in the Clock Select bit
field (CLKSEL in TCBn.CTRLA).
•
The counter value can be read from the Count register (TCBn.CNT). The peripheral will generate
an interrupt when the CNT value reaches TOP.
20.3.3
Operation
20.3.3.1 Modes
The timer can be configured to run in one of the eight different modes listed below. The event pulse
needs to be longer than one system clock cycle in order to ensure edge detection.
Periodic Interrupt Mode
In the Periodic Interrupt mode, the counter counts to the capture value and restarts from zero. An
interrupt is generated when the counter is equal to TOP. If TOP is updated to a value lower than count,
the counter will continue until MAX and wrap around without generating an interrupt.
Figure 20-2. Periodic Interrupt Mode
MAX
TOP
CNT
BOTTOM
Time-Out Check Mode
In this mode, the counter counts to MAX and wraps around. On the first edge the counter is restarted and
on the second edge, the counter is stopped. If the count register (TCBn.CNT) reaches TOP before the
second edge, an interrupt will be generated. In Freeze state, the counter will restart on a new edge.
Reading count (TCBn.CNT) or compare/capture (TCBn.CCMP) register, or writing run bit (RUN in
TCBn.STATUS) in Freeze state will have no effect.
©
2018 Microchip Technology Inc.
TOP changed to a value
lower than CNT
Datasheet Preliminary
megaAVR
16-bit Timer/Counter Type B (TCB)
Counter wraps around
DS40002015A-page 236
®
0-Series
"Interrupt"
Need help?
Do you have a question about the megaAVR 0 Series and is the answer not in the manual?