Datasheet

152
ATmega16U4/32U4 [DATASHEET]
Atmel-7766J-USB-ATmega16U4/32U4-Datasheet_04/2016
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 Output 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 toggle 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 calculated by
following equation:
Resolution
PWM
= log
2
(OCR4C + 1).
The Output Compare Pin configurations in Normal Mode are described in the table below.
15.8.2 Fast PWM Mode
The fast Pulse Width Modulation or fast PWM mode (PWM4x = 1 and WGM40 = 0) provides a high frequency
PWM waveform generation option. The fast PWM differs from the other PWM option by its single-slope
Table 15-1. Output Compare Pin Configurations in Normal Mode
COM4x1 COM4x0 OC4x Pin OC4x Pin
0 0 Disconnected Disconnected
0 1 Disconnected OC4x
1 0 Disconnected OC4x
1 1 Disconnected OC4x
TCNTn
OCWnx
(COMnx=1)
OCnx Interrupt Flag Set
1 4
Period
2 3
TOVn Interrupt Flag Set
f
OC4x
f
clkT4
21OCR4C+
-------------------------------------------=