196
8331B–AVR–03/12
Atmel AVR XMEGA AU
Figure 15-4.
Changing the period.
15.6
Compare Channel
Each compare channel continuously compares the counter value with the CMPx register. If CNT
equals CMPx, the comparator signals a match. For the low-byte timer/counter, the match will set
the compare channel's interrupt flag at the next timer clock cycle, and the event and optional
interrupt is generated. The high-byte timer/counter does not have compare interrupt/event.
15.6.1
Waveform Generation
The compare channels can be used for waveform generation on the corresponding port pins. To
make the waveform visible on the connected port pin, the following requirements must be
fulfilled:
1.
The compare channels to be used must be enabled. This will override the correspond-
ing port pin output register.
2.
The direction for the associated port pin must be set to output.
Inverted waveform output can be achieved by setting invert I/O on the port pin. Refer to
for more details.
15.6.2
Single-slope PWM Generation
For PWM generation, the period (T) is controlled by the PER register, while the CMPx registers
control the duty cycle of the waveform generator (WG) output.
shows
how the counter counts from TOP to BOTTOM, and then restarts from TOP. The WG output is
set on the compare match between the CNT and CMPx registers, and cleared at BOTTOM.
Figure 15-5.
Single-slope pulse width modulation.
CNT
MAX
New TOP written to
PER that is higher
than current CNT
New TOP written to
PER that is lower
than current CNT
"reload"
"write"
BOTTOM
CNT
MAX
TOP
Period (T)
"match"
BOTTOM
WG Output
CMPx=BOT
CMPx
CMPx=TOP