37
ATmega103(L)
0945G–09/01
Figure 31.
Timer/Counter2 Block Diagram
The 8-bit Timer/Counter0 can select clock source from PCK0 or prescaled PCK0. The 8-
bit Timer/Counter2 can select clock source from CK, prescaled CK or an external pin.
Both Timer/Counters can be stopped as described in the specification for the
Timer/Counter Control Registers – TCCR0 and TCCR2.
The different status flags (overflow, compare match and capture event) are found in the
Timer/Counter Interrupt Flag Register (TIFR). Control signals are found in the
Timer/Counter Control Registers – TCCR0 and TCCR2. The interrupt enable/disable
settings are found in the Timer/Counter Interrupt Mask Register (TIMSK).
When Timer/Counter2 is externally clocked, the external signal is synchronized with the
oscillator frequency of the CPU. To assure proper sampling of the external clock, the
minimum time between two external clock transitions must be at least one internal CPU
clock period. The external clock signal is sampled on the rising edge of the internal CPU
clock.
The 8-bit Timer/Counters feature a high-resolution and a high-accuracy usage with the
lower prescaling opportunities. Similarly, the high prescaling opportunities make these
units useful for lower speed functions or exact timing functions with infrequent actions.
Both Timer/Counters support two Output Compare functions using the output compare
registers (OCR0 and OCR2) as the data source to be compared to the Timer/Counter
contents. The Output Compare functions include optional clearing of the counter on
compare match and action on the output compare pins – PB4(OC0/PWM0) and
PB7(OC2/PWM2) – on compare match.
Timer/Counters 0 and 2 can also be used as 8-bit Pulse Width Modulators. In this mode
the Timer/Counter and the output compare register serve as a glitch-free, stand-alone
PWM with centered pulses. Refer to page 40 for a detailed description of this function.
8-BIT D
A
TA
B
U
S
T/C2 CONTROL
REGISTER (TCCR2)
TIMER INT. FLAG
REGISTER (TIFR)
TIMER/COUNTER2
(TCNT2)
8-BIT COMPARATOR
OUTPUT COMPARE
REGISTER2 (OCR2)
TIMER INT. MASK
REGISTER (TIMSK)
0
0
0
7
7
7
T/C CLK SOURCE
UP/DOWN
T/C CLEAR
CONTROL
LOGIC
CS22
COM21
PWM2
OCF0
TO
V
0
TO
V
1
OCF2A
OCF2B
ICF1
TO
V
2
OCF2
OCF2
TO
V
2
OCIE0
T
O
IE0
T
O
IE1
OCIE1A
OCIE1B
TICIE1
T
O
IE2
OCIE2
CS21
COM20
CS20
CTC2
CK
T/C2 OVER-
FLOW IRQ
T/C2 COMPARE
MATCH IRQ
T2