Timer/counter register – tcnt2, Output compare register – ocr2, Timer/counter interrupt mask register – timsk – Rainbow Electronics ATmega128L User Manual

Page 153: Atmega128(l)

Advertising
background image

153

ATmega128(L)

2467B–09/01

If external pin modes are used for the Timer/Counter2, transitions on the T2 pin will
clock the counter even if the pin is configured as an output. This feature allows software
control of the counting.

Timer/Counter Register –
TCNT2

The Timer/Counter Register gives direct access, both for read and write operations, to
the Timer/Counter unit 8-bit counter. Writing to the TCNT2 register blocks (removes) the
compare match on the following timer clock. Modifying the counter (TCNT2) while the
counter is running, introduces a risk of missing a compare match between TCNT2 and
the OCR2 register.

Output Compare Register –
OCR2

The Output Compare Register contains an 8-bit value that is continuously compared
with the counter value (TCNT2). A match can be used to generate an output compare
interrupt, or to generate a waveform output on the OC2 pin.

Timer/Counter Interrupt Mask
Register – TIMSK

• Bit 7- OCIE2: Timer/Counter2 Output Compare Match Interrupt Enable

When the OCIE2 bit is written to one, and the I-bit in the Status Register is set (one), the
Timer/Counter2 Compare Match interrupt is enabled. The corresponding interrupt is
executed if a compare match in Timer/Counter2 occurs, i.e. when the OCF2 bit is set in
the Timer/Counter Interrupt Flag Register – TIFR.

Table 68. Clock Select Bit Description

CS22

CS21

CS20

Description

0

0

0

No clock source (Timer/counter stopped)

0

0

1

clk

I/O

/(No prescaling)

0

1

0

clk

I/O

/8 (From prescaler)

0

1

1

clk

I/O

/32 (From prescaler)

1

0

0

clk

I/O

/256 (From prescaler)

1

0

1

clk

I/O

/1024 (From prescaler)

1

1

0

External clock source on T2 pin. Clock on falling edge

1

1

1

External clock source on T2 pin. Clock on rising edge

Bit

7

6

5

4

3

2

1

0

TCNT2[7:0]

TCNT2

Read/Write

R/W

R/W

R/W

R/W

R/W

R/W

R/W

R/W

Initial value

0

0

0

0

0

0

0

0

Bit

7

6

5

4

3

2

1

0

OCR2[7:0]

OCR2

Read/Write

R/W

R/W

R/W

R/W

R/W

R/W

R/W

R/W

Initial value

0

0

0

0

0

0

0

0

Bit

7

6

5

4

3

2

1

0

OCIE2

TOIE2

TICIE1

OCIE1A

OCIE1B

TOIE1

OCIE0

TOIE0

TIMSK

Read/Write

R/W

R/W

R/W

R/W

R/W

R/W

R/W

R/W

Initial value

0

0

0

0

0

0

0

0

Advertising