179
8331B–AVR–03/12
Atmel AVR XMEGA AU
to TOP and then restarts from BOTTOM. The waveform generator (WG) output is set on the
compare match between the CNT and CCx registers and cleared at TOP.
Figure 14-15.
Single-slope pulse width modulation.
The PER register defines the PWM resolution. The minimum resolution is 2 bits (PER=0x0003),
and the maximum resolution is 16 bits (PER=MAX).
The following equation calculate the exact resolution for single-slope PWM (R
PWM_SS
):
The single-slope PWM frequency (f
PWM_SS
) depends on the period setting (PER) and the periph-
eral clock frequency (fclk
PER
), and can be calculated by the following equation:
where N represents the prescaler divider used. The waveform generated will have a maximum
frequency of half of the peripheral clock frequency (fclk
PER
) when CCA is set to zero (0x0000)
and no prescaling is used. This also applies when using the hi-res extension, since this
increases the resolution and not the frequency.
14.8.4
Dual-slope PWM
For dual-slope PWM generation, the period (T) is controlled by PER, while CCx registers control
the duty cycle of the WG output.
shows how for dual-slope PWM the counter
counts repeatedly from BOTTOM to TOP and then from TOP to BOTTOM. The waveform gener-
ator output is set on BOTTOM, cleared on compare match when up-counting, and set on
compare match when down-counting.
CNT
MAX
TOP
Period (T)
"match"
BOTTOM
WG Output
CCx=BOTTOM
CCx
CCx=TOP
"update"
R
PWM_SS
PER
1
+
(
)
log
2
( )
log
-----------------------------------
=
f
PWM_SS
fclk
PER
N
PER
1
+
(
)
-------------------------------
=