Datasheet

Figure 15-3. Output Compare Unit, Block Diagram
OCFnx (Int.Req.)
= (8-bit Comparator )
OCRnx
OCnx
DATA BUS
TCNTn
WGMn[1:0]
Waveform Generator
top
FOCn
COMnx[1:0]
bottom
Note:  The “n” in the register and bit names indicates the device number (n = 0 for Timer/Counter 0), and
the “x” indicates Output Compare unit (A/B).
The OCR0x Registers are double buffered when using any of the Pulse Width Modulation (PWM) modes.
When double buffering is enabled, the CPU has access to the OCR0x Buffer Register. The double
buffering synchronizes the update of the OCR0x Compare Registers to either top or bottom of the
counting sequence. The synchronization prevents the occurrence of odd-length, non-symmetrical PWM
pulses, thereby making the output glitch-free.
The double buffering is disabled for the normal and Clear Timer on Compare (CTC) modes of operation,
and the CPU will access the OCR0x directly.
15.5.1. Force Output Compare
In non-PWM waveform generation modes, the match output of the comparator can be forced by writing a
'1' to the Force Output Compare (TCCR0C.FOCx) bit. Forcing compare match will not set the OCFx Flag
or reload/clear the timer, but the OCx pin will be updated as if a real compare match had occurred (the
TCCRA.COMx[1:0] bits define whether the OCx pin is set, cleared or toggled).
15.5.2. Compare Match Blocking by TCNT Write
All CPU write operations to the TCNT Register will block any compare match that occur in the next timer
clock cycle, even when the timer is stopped. This feature allows OCRx to be initialized to the same value
as TCNT without triggering an interrupt when the Timer/Counter clock is enabled.
15.5.3. Using the Output Compare Unit
Since writing TCNT in any mode of operation will block all compare matches for one timer clock cycle,
there are risks involved when changing TCNT when using the Output Compare Unit, independently of
whether the Timer/Counter is running or not. If the value written to TCNT equals the OCRx value, the
compare match will be missed, resulting in incorrect waveform generation. Similarly, do not write the
TCNT value equal to BOTTOM when the counter is down counting.
Atmel ATmega16M1/32M1/64M1 [DATASHEET]
Atmel-8209F-ATmega16M1/32M1/64M1_Datasheet_Complete-10/2016
130