Compare match output unit, Compare output mode and waveform generation, Atmega128(l) – Rainbow Electronics ATmega128L User Manual

Page 91

Advertising
background image

91

ATmega128(L)

2467B–09/01

The setup of the OC0 should be performed before setting the data direction register for
the port pin to output. The easiest way of setting the OC0 value is to use the force output
compare (FOC0) strobe bit in normal mode. The OC0 register keeps its value even
when changing between waveform generation modes.

Be aware that the COM01:0 bits are not double buffered together with the compare
value. Changing the COM01:0 bits will take effect immediately.

Compare Match Output
Unit

The compare output mode (COM01:0) bits have two functions. The waveform generator
uses the COM01:0 bits for defining the output compare (OC0) state at the next compare
match. Also, the COM01:0 bits control the OC0 pin output source.

Figure 36 shows a

simplified schematic of the logic affected by the COM01: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 COM01:0 bits are
shown. When referring to the OC0 state, the reference is for the internal OC0 register,
not the OC0 pin.

Figure 36. Compare Match Output Unit, Schematic

The general I/O port function is overridden by the output compare (OC0) from the wave-
form generator if either of the COM01:0 bits are set. However, the OC0 pin direction
(input or output) is still controlled by the data direction register (DDR) for the port pin.
The data direction register bit for the OC0 pin (DDR_OC0) must be set as output before
the OC0 value is visible on the pin. The port override function is independent of the
waveform generation mode.

The design of the output compare pin logic allows initialization of the OC0 state before
the output is enabled. Note that some COM01:0 bit settings are reserved for certain
modes of operation.

See “8-bit Timer/Counter Register Description” on page 98.

Compare Output Mode and
Waveform Generation

The waveform generator uses the COM01:0 bits differently in normal, CTC, and PWM
modes. For all modes, setting the COM01:0 = 0 tells the waveform generator that no
action on the OC0 register is to be performed on the next compare match. For compare
output actions in the non-PWM modes refer to

Table 53 on page 99. For fast PWM

PORT

DDR

D

Q

D

Q

OCn

Pin

OCn

D

Q

Waveform

Generator

COMn1

COMn0

0

1

D

ATA

B

U

S

FOCn

clk

I/O

Advertising