
80
ATmega8515(L)
2512A–AVR–04/02
The OCR0 Register isdouble bufferedwhen using any of thePulse WidthModulation
(PWM) modes. For thenormal andClear Timer on Compare (CTC) modes of operation,
the double buffering isdisabled.The double buffering synchronizes theupdate of the
OCR0 CompareRegister to either top orbottom of the counting sequence. The synchro-
nization prevents theoccurrenceof odd-length, non-symmetrical PWM pulses, thereby
making the output glitch-free.
The OCR0 Register access mayseem complex, but this is not case. When the double
buffering is enabled, the CPUhas access to the OCR0 Buffer Register, and ifdouble
buffering isdisabled the CPUwill access the OCR0 directly.
Force Output Compare Innon-PWM waveform generation modes, thematch output of the comparatorcan be
forcedbywriting a one to the Force Output Compare (FOC0)bit. Forcing compare
match will not set the OCF0 flag orreload/clear thetimer, but the OC0 pin will be
updated as if a realcomparematch had occurred(the COM01:0 bitssettingsdefine
whether the OC0 pin isset,cleared or toggled).
Compare Match Blocking by
TCNT0 Write
All CPUwrite operations to theTCNT0 Registerwill block anycomparematch that
occur in thenexttimerclock cycle, even when thetimer isstopped.Thisfeatureallows
OCR0 to beinitialized to the same value as TCNT0 without triggering an interrupt when
theTimer/Counterclock is enabled.
Using the Output Compare
Unit
Since writing TCNT0 in any modeof operation will block all comparematchesfor one
timerclock cycle, thereare risks involvedwhen changing TCNT0 when using the output
compare channel, independently ofwhether theTimer/Counter isrunning or not. If the
value written to TCNT0 equals the OCR0 value, the comparematch will bemissed,
resulting in incorrect waveformgeneration. Similarly, donotwrite theTCNT0 value
equal to BOTTOM when the counter isdowncounting.
The setup of the OC0 should be performedbefore setting the Data Direction Registerfor
the port pin to output. Theeasiest way ofsetting the OC0value is to usethe Force Out-
put Compare (FOC0)strobe bits in Normal mode. The OC0 Registerkeeps its value
even when changing between Waveform Generation modes.
Beawarethat the COM01:0 bits are not double buffered togetherwith the compare
value. Changing the COM01:0 bitswill takeeffectimmediately.
Komentarze do niniejszej Instrukcji