Datasheet

Table 22-1. Definitions
Constant Description
BOTTOM The counter reaches the BOTTOM when it becomes zero (0x00).
MAX The counter reaches its maximum when it becomes 0xFF (decimal 255).
TOP The counter reaches the TOP when it becomes equal to the highest value in the count
sequence. The TOP value can be assigned to be the fixed value 0xFF (MAX) or the value
stored in the OCR2A Register. The assignment is dependent on the mode of operation.
22.2.2 Registers
The Timer/Counter (TCNT2) and Output Compare Register (OCR2A and OCR2B) are 8-bit registers.
Interrupt request (shorten as Int.Req.) signals are all visible in the Timer Interrupt Flag Register (TIFR2).
All interrupts are individually masked with the Timer Interrupt Mask register (TIMSK2). TIFR2 and
TIMSK2 are not shown in the figure.
The timer/counter can be clocked internally, via the prescaler, or asynchronously clocked from the
TOSC1/2 pins, as detailed later in this section. The asynchronous operation is controlled by the
Asynchronous Status Register (ASSR). The clock select logic block controls which clock source the timer/
counter uses to increment (or decrement) its value. The timer/counter is inactive when no clock source is
selected. The output from the clock select logic is referred to as the timer clock (clk
T2
).
The double buffered Output Compare Register (OCR2A and OCR2B) are compared with the timer/
counter value at all times. The result of the compare can be used by the waveform generator to generate
a PWM or variable frequency output on the Output Compare pins (OC2A and OC2B). See 19.5 Output
Compare Unit for details. The compare match event will also set the Compare Flag (OCF2A or OCF2B),
which can be used to generate an output compare interrupt request.
22.3 Timer/Counter Clock Sources
The timer/counter can be clocked by an internal synchronous or an external asynchronous clock source:
The clock source clk
T2
is by default equal/synchronous to the MCU clock, clk
I/O
.
When the Asynchronous TC2 bit in the Asynchronous Status Register (ASSR.AS2) is written to '1', the
clock source is taken from the Timer/Counter Oscillator connected to TOSC1 and TOSC2.
For details on asynchronous operation, see the description of the ASSR. For details on clock sources and
prescaler, see Timer/Counter Prescaler.
22.4 Counter Unit
The main part of the 8-bit timer/counter is the programmable bi-directional counter unit. Below is the block
diagram of the counter and its surroundings.
ATmega48PA/88PA/168PA
8-bit Timer/Counter2 (TC2) with PWM and A...
© 2018 Microchip Technology Inc.
Datasheet Complete
DS40002011A-page 201