beautypg.com

Atmega161(l), Tccr0” and “timer/counter2 control register – Rainbow Electronics ATmega161L User Manual

Page 41

background image

41

ATmega161(L)

1228C–AVR–08/02

Figure 32. Timer/Counter2 Block Diagram

The 8-bit Timer/Counter0 can select clock source from CK, prescaled CK or an external
pin.The 8-bit Timer/Counter2 can select clock source from CK, prescaled CK or external
TOSC1.

Both Timer/Counters can be stopped as described in sections “Timer/Counter0 Control
Register

TCCR0” and “Timer/Counter2 Control Register

TCCR2”.

T h e va r io u s Sta tu s F l a g s ( O ve rfl o w an d C om pa r e M a tch ) ar e fo un d i n th e
Timer/Counter Interrupt Flag Register (TIFR). Control signals are found in the
Timer/Counter Control Register (TCCR0 and TCCR2). The interrupt enable/disable set-
tings are found in the Timer/Counter Interrupt Mask Register (TIMSK).

When Timer/Counter0 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 both a high resolution and a high accuracy usage with
the lower prescaling opportunities. Similarly, the high prescaling opportunities make the
Timer/Counter0 useful for lower speed functions or exact timing functions with infre-
quent actions.

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 44 for a detailed description of
this function.

8-BIT DATA BUS

8-BIT ASYNCH T/C2 DATA BUS

ASYNCH. STATUS

REGISTER (ASSR)

TIMER INT. FLAG

REGISTER (TIFR)

TIMER/COUNTER2

(TCNT2)

SYNCH UNIT

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

OCF2

TOV2

TOIE0

TOIE1

OCIE1A

OCIE1B

TICIE1

TOIE2

OCIE2

OCR2UB

TC2UB

ICR2UB

TOSC1

CK

TCK2

T/C2 OVER-

FLOW IRQ

T/C2 COMPARE

MATCH IRQ

AS2

TOV1

OCF1B

OCF1A

ICF1

TOV2

OCF2

OCF0

TOV0

OCIE0

T/C2 CONTROL

REGISTER (TCCR2)

CS22

COM21

PWM2

CS21

COM20

CS20

CTC2

FOC2

PSR2

PSR10

SPECIAL FUNCTIONS
IO REGISTER (SFIOR)

CK