Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
AVR / datasheets / attiny_261_461_861.pdf
Скачиваний:
52
Добавлен:
20.03.2015
Размер:
2.26 Mб
Скачать

internal clock source, selected by the Clock Select bits (CS02:0). When no clock source is selected (CS02:0 = 0) the timer is stopped. However, the TCNT0 value can be accessed by the CPU, regardless of whether clkT0 is present or not. A CPU write overrides (has priority over) all counter clear or count operations. The Timer/Counter Overflow Flag (TOV0) is set when the counter reaches the maximum value and it can be used for generating a CPU interrupt.

14.5Modes of Operation

The mode of operation is defined by the Timer/Counter Width (TCW0), Input Capture Enable (ICEN0) and Wave Generation Mode (WGM00) bits in ”TCCR0A – Timer/Counter0 Control Register A” on page 84. Table 14-3 shows the different Modes of Operation.

Table 14-3.

Modes of operation

 

 

 

 

 

 

 

 

 

Timer/Counter Mode

 

Update of

TOV Flag

Mode

 

ICEN0

TCW0

WGM00

of Operation

TOP

OCRx at

Set on

 

 

 

 

 

 

 

 

 

0

 

0

0

0

Normal 8-bit Mode

0xFF

Immediate

MAX (0xFF)

 

 

 

 

 

 

 

 

 

1

 

0

0

1

8-bit CTC

OCR0A

Immediate

MAX (0xFF)

 

 

 

 

 

 

 

 

 

2

 

0

1

X

16-bit Mode

0xFFFF

Immediate

MAX (0xFFFF)

 

 

 

 

 

 

 

 

 

3

 

1

0

X

8-bit Input Capture Mode

0xFF

Immediate

MAX (0xFF)

 

 

 

 

 

 

 

 

 

4

 

1

1

X

16-bit Input Capture Mode

0xFFFF

Immediate

MAX (0xFFFF)

 

 

 

 

 

 

 

 

 

14.5.1Normal 8-bit Mode

In the Normal 8-bit mode, see Table 14-3 on page 74, the counter (TCNT0L) is incrementing until it overruns when it passes its maximum 8-bit value (MAX = 0xFF) and then restarts from the bottom (0x00). The Overflow Flag (TOV0) will be set in the same timer clock cycle as the TCNT0L becomes zero. The TOV0 Flag in this case behaves like a ninth bit, except that it is only set, not cleared. However, combined with the timer overflow interrupt that automatically clears the TOV0 Flag, the timer resolution can be increased by software. There are no special cases to consider in the Normal 8-bit mode, a new counter value can be written anytime. The Output Compare Unit can be used to generate interrupts at some given time.

14.5.2Clear Timer on Compare Match (CTC) 8-bit Mode

In Clear Timer on Compare or CTC mode, see Table 14-3 on page 74, the OCR0A Register is used to manipulate the counter resolution. In CTC mode the counter is cleared to zero when the counter value (TCNT0) matches the OCR0A. The OCR0A defines the top value for the counter, hence also its resolution. This mode allows greater control of the Compare Match output frequency. It also simplifies the operation of counting external events.

The timing diagram for the CTC mode is shown in Figure 14-2. The counter value (TCNT0) increases until a Compare Match occurs between TCNT0 and OCR0A, and then counter (TCNT0) is cleared.

74 ATtiny261/461/861

2588B–AVR–11/06

ATtiny261/461/861

Figure 14-2. CTC Mode, Timing Diagram

OCnx Interrupt Flag Set

TCNTn

Period 1 2 3 4

An interrupt can be generated each time the counter value reaches the TOP value by using the OCF0A Flag. If the interrupt is enabled, the interrupt handler routine can be used for updating the TOP value. However, changing TOP to a value close to BOTTOM when the counter is running with none or a low prescaler value must be done with care since the CTC mode does not have the double buffering feature. If the new value written to OCR0A is lower than the current value of TCNT0, the counter will miss the Compare Match. The counter will then have to count to its maximum value (0xFF) and wrap around starting at 0x00 before the Compare Match can occur. As for the Normal mode of operation, the TOV0 Flag is set in the same timer clock cycle that the counter counts from MAX to 0x00.

14.5.316-bit Mode

In 16-bit mode, see Table 14-3 on page 74, the counter (TCNT0H/L) is a incrementing until it overruns when it passes its maximum 16-bit value (MAX = 0xFFFF) and then restarts from the bottom (0x0000). The Overflow Flag (TOV0) will be set in the same timer clock cycle as the TCNT0H/L becomes zero. The TOV0 Flag in this case behaves like a 17th bit, except that it is only set, not cleared. However, combined with the timer overflow interrupt that automatically clears the TOV0 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 Output Compare Unit can be used to generate interrupts at some given time.

14.5.48-bit Input Capture Mode

The Timer/Counter0 can also be used in an 8-bit Input Capture mode, see Table 14-3 on page 74 for bit settings. For full description, see the section ”Input Capture Unit” on page 76.

14.5.516-bit Input Capture Mode

The Timer/Counter0 can also be used in a 16-bit Input Capture mode, see Table 14-3 on page 74 for bit settings. For full description, see the section ”Input Capture Unit” on page 76.

75

2588B–AVR–11/06

Соседние файлы в папке datasheets