Datasheet

Table Of Contents
145
ATmega640/V-1280/V-1281/V-2560/V-2561/V [DATASHEET]
2549Q–AVR–02/2014
Note: 1. The CTCn and PWMn1:0 bit definition names are obsolete. Use the WGMn2:0 definitions. However, the functional-
ity and location of these bits are compatible with previous versions of the timer.
For detailed timing information refer to “Timer/Counter Timing Diagrams” on page 152.
17.9.1 Normal Mode
The simplest mode of operation is the Normal mode (WGMn3:0 = 0). In this mode the counting direction is always
up (incrementing), and no counter clear is performed. The counter simply overruns when it passes its maximum
16-bit value (MAX = 0xFFFF) and then restarts from the BOTTOM (0x0000). In normal operation the Timer/Coun-
ter Overflow Flag (TOVn) will be set in the same timer clock cycle as the TCNTn becomes zero. The TOVn Flag in
this case behaves like a 17
th
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 mode, a new counter value can be written anytime.
The Input Capture unit is easy to use in Normal mode. However, observe that the maximum interval between the
external events must not exceed the resolution of the counter. If the interval between events are too long, the timer
overflow interrupt or the prescaler must be used to extend the resolution for the capture unit.
The Output Compare units can be used to generate interrupts at some given time. Using the Output Compare to
generate waveforms in Normal mode is not recommended, since this will occupy too much of the CPU time.
17.9.2 Clear Timer on Compare Match (CTC) Mode
In Clear Timer on Compare or CTC mode (WGMn3:0 = 4 or 12), the OCRnA or ICRn Register are used to manipu-
late the counter resolution. In CTC mode the counter is cleared to zero when the counter value (TCNTn) matches
either the OCRnA (WGMn3:0 = 4) or the ICRn (WGMn3:0 = 12). The OCRnA or ICRn define the top value for the
Table 17-2. Waveform Generation Mode Bit Description
(1)
Mode WGMn3
WGMn2
(CTCn)
WGMn1
(PWMn1)
WGMn0
(PWMn0)
Timer/Counter
Mode of Operation TOP
Update of
OCRnx at
TOVn Flag
Set on
00 0 0 0 Normal 0xFFFF Immediate MAX
10 0 0 1PWM, Phase Correct, 8-bit 0x00FF TOP BOTTOM
20 0 1 0PWM, Phase Correct, 9-bit 0x01FF TOP BOTTOM
30 0 1 1PWM, Phase Correct, 10-bit 0x03FF TOP BOTTOM
4 0 1 0 0 CTC OCRnA Immediate MAX
50 1 0 1 Fast PWM, 8-bit 0x00FF BOTTOM TOP
60 1 1 0 Fast PWM, 9-bit 0x01FF BOTTOM TOP
70 1 1 1 Fast PWM, 10-bit 0x03FF BOTTOM TOP
81 0 0 0
PWM, Phase and Frequency
Correct
ICRn BOTTOM BOTTOM
91 0 0 1
PWM,Phase and Frequency
Correct
OCRnA BOTTOM BOTTOM
101010PWM, Phase Correct ICRn TOP BOTTOM
111011PWM, Phase Correct OCRnA TOP BOTTOM
12 1 1 0 0 CTC ICRn Immediate MAX
131101 (Reserved)
141110 Fast PWMICRnBOTTOMTOP
151111 Fast PWM OCRnA BOTTOM TOP