Datasheet
150
7766F–AVR–11/10
ATmega16/32U4
Waveform Output is cleared on the Compare Match. In inverting Compare Output Mode the
Waveform Output is set on Compare Match.
The timing diagram for the Normal mode is shown in Figure 15-12. The counter value (TCNT4)
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 (OCW4x) in toggle Compare Mode. The small horizontal line
marks on the TCNT4 slopes represent Compare Matches between OCR4x and TCNT4.
Figure 15-12. Normal Mode, Timing Diagram
The Timer/Counter Overflow Flag (TOV4) is set in the same clock cycle as the TCNT4 becomes
zero. The TOV4 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 TOV4 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 OCW4x output can be set to
toggle its logical level on each Compare Match by setting the Compare Output mode bits to tog-
gle mode (COM4x1:0 = 1). The OC4x value will not be visible on the port pin unless the data
direction for the pin is set to output. The waveform generated will have a maximum frequency of
f
OC4x
= f
clkT4
/4 when OCR4C is set to zero. The waveform frequency is defined by the following
equation:
Resolution shows how many bit is required to express the value in the OCR4C register. It is cal-
culated by following equation:
Resolution
PWM
= log
2
(OCR4C + 1).
TCNTn
OCWnx
(COMnx=1)
OCnx Interrupt Flag Set
1 4
Period
2 3
TOVn Interrupt Flag Set
f
OC4x
f
clkT4
21OCR4C+()⋅
-------------------------------------------=