Datasheet
The setup of the OCx should be performed before setting the Data Direction Register for the port pin to
output. The easiest way of setting the OCx value is to use the Force Output Compare (FOCx) strobe bits
in Normal mode. The OCx Registers keep their values even when changing between Waveform
Generation modes.
Be aware that the TCCRA.COMx[1:0] bits are not double buffered together with the compare value.
Changing the TCCRA.COMx[1:0] bits will take effect immediately.
15.6. Compare Match Output Unit
The Compare Output mode bits in the Timer/Counter Control Register A (TCCR0A.COM0x) have two
functions:
• The Waveform Generator uses the COM0x bits for defining the Output Compare (OC0x) register
state at the next compare match.
• The COM0x bits control the OC0x pin output source
The figure below shows a simplified schematic of the logic affected by COM0x. The I/O Registers, I/O
bits, and I/O pins in the figure are shown in bold. Only the parts of the general I/O port control registers
that are affected by the COM0x bits are shown, namely PORT and DDR.
On system reset the OC0x Register is reset to 0x00.
Note: 'OC0x state' is always referring to internal OC0x registers, not the OC0x pin.
Figure 15-4. Compare Match Output Unit, Schematic
PORT
DDR
D Q
D Q
OCnx
Pin
OCnx
D Q
Waveform
Generator
COMnx[1]
COMnx[0]
0
1
DATA BUS
FOCnx
clk
I/O
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 general I/O port function is overridden by the Output Compare (OC0x) from the Waveform Generator
if either of the COM0x[1:0] bits are set. However, the OC0x pin direction (input or output) is still controlled
by the Data Direction Register (DDR) for the port pin. In the Data Direction Register, the bit for the OC1x
Atmel ATmega16M1/32M1/64M1 [DATASHEET]
Atmel-8209F-ATmega16M1/32M1/64M1_Datasheet_Complete-10/2016
131