AT90S/LS4434 and AT90S/LS8535
43
Note that in PWM mode, the Output Compare Register is transferred to a temporary location when written. The value is
latched when the Timer/Counter reaches $FF. This prevents the occurrence of odd-length PWM pulses (glitches) in the
event of an unsynchronized OCR2 write. See Figure 35 for an example.
Figure 35.
Effects of Unsynchronized OCR Latching
During the time between the write and the latch operation, a read from OCR2 will read the contents of the temporary loca-
tion. This means that the most recently written value always will read out of OCR2.
When the OCR register (not the temporary register) is updated to $00 or $FF, the PWM output changes to low or high
immediately according to the settings of COM21/COM20. This is shown in Table 21.
In PWM mode, the Timer Overflow Flag (TOV2) is set when the counter advances from $00. Timer Overflow Interrupt2
operates exactly as in normal Timer/Counter mode, i.e., it is executed when TOV2 is set, provided that Timer Overflow
Interrupt and global interrupts are enabled. This also applies to the Timer Output Compare flag and interrupt.
The frequency of the PWM will be Timer Clock Frequency divided by 510.
Table 20.
Compare Mode Select in PWM Mode
COM21
COM20
Effect on Compare Pin
0
0
Not connected
0
1
Not connected
1
0
Cleared on compare match, up-counting. Set on compare match, down-counting (non-inverted PWM).
1
1
Cleared on compare match, down-counting time-out. Set on compare match, up-counting (inverted PWM).
Table 21.
PWM Outputs OCR2 = $00 or $FF
COM21
COM20
OCR2
Output PWMn
1
0
$00
L
1
0
$FF
H
1
1
$00
H
1
1
$FF
L
Counter Value
Compare Value
PWM Output
Synchronized OCR Latch
Counter Value
Compare Value
PWM Output
Unsynchronized OCR Latch
Glitch
Compare Value changes
Compare Value changes