7 modes of operation, 1 normal mode – Rainbow Electronics ATtiny861_V User Manual

Page 101

Advertising
background image

101

2588B–AVR–11/06

ATtiny261/461/861

16.7

Modes of Operation

The mode of operation, i.e., the behavior of the Timer/Counter and the Output Compare pins, is
defined by the combination of the Waveform Generation mode (bits PWM1x and WGM10) and
Compare Output mode (COM1x1:0) bits. The Compare Output mode bits do not affect the
counting sequence, while the Waveform Generation mode bits do. The COM1x1:0 bits control
whether the PWM output generated should be inverted, non-inverted or complementary. For
non-PWM modes the COM1x1:0 bits control whether the output should be set, cleared, or tog-
gled at a Compare Match.

16.7.1

Normal Mode

The simplest mode of operation is the Normal mode (PWM1x = 0), the counter counts from
BOTTOM to TOP (defined as OCR1C) then restarts from BOTTOM. The OCR1C defines the
TOP value for the counter, hence also its resolution, and allows control of the Compare Match
output frequency. In toggle Compare Output Mode the Waveform Output (OCW1x) is cleared on
the Compare Match between TCNT1 and OCR1x and set at BOTTOM. In non-inverting Com-
pare Output Mode the Waveform Output is cleared on the Compare Match and set at BOTTOM.
In inverting Compare Output Mode the Waveform Output is set on Compare Match and cleared
at BOTTOM.

The timing diagram for the Normal mode is shown in

Figure 16-10

. The counter value (TCNT1)

that is shown as a histogram in the timing diagram is incremented until the counter value
matches the TOP value. The counter is then cleared at the following clock cycle The diagram
includes the Waveform Output (OCW1x) in toggle Compare Mode. The small horizontal line
marks on the TCNT1 slopes represent Compare Matches between OCR1x and TCNT1.

Figure 16-10. Normal Mode, Timing Diagram

The Timer/Counter Overflow Flag (TOV1) is set in the same clock cycle as the TCNT1 becomes
zero. The TOV1 Flag in this case behaves like a 11th bit, except that it is only set, not cleared.
However, combined with the timer overflow interrupt, that automatically clears the TOV1 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. Using the Out-
put Compare to generate waveforms in Normal mode is not recommended, since this will
occupy too much of the CPU time. For generating a waveform, the OCW1x output can be set to

TCNTn

OCWnx
(COMnx=1)

OCnx Interrupt Flag Set

1

4

Period

2

3

TOVn Interrupt Flag Set

Advertising