8-bit AVR Microcontrollers

Compare Match Output Unit

The Compare Output mode (TCCRnA.COMnx[1:0]) bits have two functions. The waveform generator uses the TCCRnA.COMnx[1:0] bits for defining the Output Compare (OCnx) state at the next compare match. Secondly the TCCRnA.COMnx[1:0] bits control the OCnx pin output source. The figure below shows a simplified schematic of the logic affected by the TCCRnA.COMnx[1:0] bit setting. 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 (DDR and PORT) that are affected by the TCCRnA.COMnx[1:0] bits are shown. When referring to the OCnx state, the reference is for the internal OCnx register, not the OCnx pin. If a System Reset occurs, the OCnx register is reset to “0”.

Figure 1. Compare Match Output Unit, Schematic
Note: The “n” in the register and bit names indicates the device number (n = 1, 3, 4 for Timer/Counter 1, 3, 4), and the “x” indicates output compare unit (A/B).

The general I/O port function is overridden by the Output Compare (OCnx) from the waveform generator if either of the TCCRnA.COMnx[1:0] bits are set. However, the OCnx pin direction (input or output) is still controlled by the Data Direction Register (DDR) for the port pin. The DDR bit for the OCnx pin (DDR_OCnx) must be set as output before the OCnx value is visible on the pin. The port override function is generally independent of the waveform generation mode, but there are some exceptions.

The design of the output compare pin logic allows initialization of the OCnx state before the output is enabled. Note that some TCCRnA.COMnx[1:0] bit settings are reserved for certain modes of operation.

The TCCRnA.COMnx[1:0] bits have no effect on the input capture unit.