Datasheet

Figure 19-3. 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 = 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.
19.7.1 Compare Output Mode and Waveform Generation
The waveform generator uses the TCCRnA.COMnx[1:0] bits differently in normal, CTC, and PWM
modes. For all modes, setting the TCCRnA.COMnx[1:0] = 0 tells the waveform generator that no action
on the OCnx register is to be performed on the next compare match. Refer also to the descriptions of the
output modes.
A change of the TCCRnA.COMnx[1:0] bits state will have effect at the first compare match after the bits
are written. For non-PWM modes, the action can be forced to have immediate effect by using the
TCCRnC.FOCnx strobe bits.
19.8 Output Compare Units
The 16-bit comparator continuously compares TCNTn with the Output Compare Register (OCRnx). If
TCNT equals OCRnx the comparator signals a match. A match will set the Output Compare Flag
(TIFRn.OCFx) at the next timer clock cycle. If enabled (TIMSKn.OCIEx = 1), the output compare flag
generates an output compare interrupt. The OCFx is automatically cleared when the interrupt is
executed. Alternatively, the OCFx can be cleared by software by writing a logical one to its I/O bit
location. The waveform generator uses the match signal to generate an output according to operating
mode set by the Waveform Generation mode (WGMn[3:0]) bits and Compare Output mode (COMnx[1:0])
ATmega328PB
TC1, 3, 4 - 16-bit Timer/Counter1, 3, 4 with PWM
© 2018 Microchip Technology Inc.
Datasheet Complete
DS40001906C-page 166