10 timer/counter timing diagrams, Atmega128rfa1 – Rainbow Electronics ATmega128RFA1 User Manual
Page 264

264
8266A-MCU Wireless-12/09
ATmega128RFA1
The definition of TOP with the ICRn Register works well when using fixed TOP values.
Combined with ICRn the OCRnA Register is available for generating a PWM output on
OCnA. However, if the base PWM frequency is actively changed by modifying the TOP
value, using the OCRnA as TOP is clearly a better choice due to its double buffer
feature.
In phase and frequency correct PWM mode, the compare units allow generating PWM
waveforms on the OCnx pins. Setting the COMnx1:0 bits to 2 will produce a non-
inverted PWM. An inverted PWM output can be generated by setting the COMnx1:0 to
3 (see
). The actual OCnx value will only be visible at the port
pin if the data direction of the port pin is set to output (DDR_OCnx). The PWM
waveform is generated by setting (or clearing) the OCnx Register at the compare match
between OCRnx and TCNTn when the counter increments, and by clearing (or setting)
the OCnx Register at compare match between OCRnx and TCNTn when the counter
decrements. The PWM frequency of the output f
OCnxPFCPWM
when using phase and
frequency correct PWM can be calculated with the following equation:
)
2
/
_
TOP
N
f
f
O
I
clk
OCnxPFCPWM
⋅
⋅
=
The N variable represents the prescaler divider (1, 8, 64, 256, or 1024).
The extreme values for the OCRnx Register represent special cases when generating a
PWM waveform output in the phase correct PWM mode. If the OCRnx is set equal to
BOTTOM the output will be continuously low and if set equal to TOP the output will be
set to high for non-inverted PWM mode. For inverted PWM the output will have the
opposite logic values. If OCR1A is used to define the TOP value (WGM13:0 = 9) and
COM1A1:0 = 1, the OC1A output will toggle with a 50% duty cycle.
18.10 Timer/Counter Timing Diagrams
The Timer/Counter is a synchronous design and the timer clock (clk
Tn
) is therefore
shown as a clock enable signal in the following figures. The figures include information
on when Interrupt Flags are set and when the OCRnx Register is updated with the
OCRnx buffer value (only for modes utilizing double buffering). Figure 18-10 shows a
timing diagram for the setting of OCFnx.
Figure 18-10. Timer/Counter Timing Diagram, Setting of OCFnx, no Prescaling
clk
Tn
(clk
I/O
/1)
OCFnx
clk
I/O
OCRnx
TCNTn
OCRnx Value
OCRnx - 1
OCRnx
OCRnx + 1
OCRnx + 2