Datasheet
80
8024A–AVR–04/08
ATmega8HVA/16HVA
17.5 Modes of Operation
The mode of operation is defined by the Timer/Counter Width (TCWn), Input Capture Enable
(ICENn) and the Waveform Generation Mode (WGMn0)bits in ”TCCRnA – Timer/Counter n
Control Register A” on page 90. Table 17-2 on page 80 shows the different Modes of Operation.
17.5.1 Normal 8-bit Mode
In the normal mode, the counter (TCNTnL) is incrementing until it overruns when it passes its
maximum 8-bit value (MAX = 0xFF) and then restarts from the bottom (0x00), see Table 17-2 on
page 80 for bit settings. The Overflow Flag (TOVn) will be set in the same timer clock cycle as
the TCNTnL becomes zero. The TOVn Flag in this case behaves like a ninth bit, except that it is
only set, not cleared. However, combined with the timer overflow interrupt that automatically
clears the TOVn Flag, the timer resolution can be increased by software. There are no special
cases to consider in the Normal 8-bit mode, a new counter value can be written anytime. The
Output Compare Unit can be used to generate interrupts at some given time.
17.5.2 Clear Timer on Compare Match (CTC) 8-bit Mode
In Clear Timer on Compare or CTC mode, the OCRnA Register is used to manipulate the
counter resolution, see Table 17-2 on page 80 for bit settings. In CTC mode the counter is
cleared to zero when the counter value (TCNTn) matches the OCRnA. The OCRnA defines the
top value for the counter, hence also its resolution. This mode allows greater control of the Com-
pare Match output frequency. It also simplifies the operation of counting external events.
The timing diagram for the CTC mode is shown in Figure 17-3 on page 81. The counter value
(TCNTn) increases until a Compare Match occurs between TCNTn and OCRnA, and then
counter (TCNTn) is cleared.
Table 17-2. Modes of Operation
Mode ICENn TCWn WGMn0
Timer/Counter Mode
of Operation TOP
Update of
OCRx at
TOV Flag
Set on
0 0 0 0 Normal 8-bit Mode 0xFF Immediate MAX (0xFF)
1 0 0 1 8-bit CTC OCRnA Immediate MAX (0xFF)
2 0 1 0 16-bit Mode 0xFFFF Immediate MAX (0xFFFF)
3 0 1 1 16-bit CTC
OCRnB,
OCRnA
Immediate MAX (0xFFFF)
410 0
8-bit Input Capture
mode
0xFF – MAX (0xFF)
511 0
16-bit Input Capture
mode
0xFFFF – MAX (0xFFFF)