4
AVR1306
8045A-AVR-02/08
•
Timer
overflow.
•
Timer error (Input capture data lost because input capture buffer is full).
•
Compare or capture. Separate interrupts for each channel.
3.4 Period Setting
Each TC module has a period register (PER[H:L]) that controls the TOP value of the
counter (except in frequency generation mode).
The PER[H:L] register is double buffered through the PERBUF[H:L] register. Double
buffered registers are covered in section 3.7.
The PER[H:L] register is automatically initialized to 0xFFFF after a reset.
3.5 Capture or Compare Channels
Each TC module has two or four capture or compare channels. The channels can be
set up for either input capture or compare match. It is not possible to use the same
TC module for both input capture and compare match at the same time. Input capture
can be used to time stamp event, measuring waveform parameters like frequency or
duty cycle. The compare match feature can be used to generate interrupts or events
at certain time points, or for PWM/waveform generation.
The compare or capture channels consist of a set of 16-bit registers named CCx[H:L],
where x indicates the channel. Timer0, with 4 channels, has CCA[H:L], CCB[H:L],
CCC[H:L] and CCD[H:L], while Timer1 has CCA[H:L] and CCB[H:L]. In addition, each
CCx[H:L] register has an associated buffer register CCxBUF[H:L]. Double buffered
registers are covered in detail in section 3.7.
When used for input capture, the value of the PER register determines how input
capture values are interpreted. If bit 15 of PER is set to one, the entire 16 bit counter
value is stored in the capture buffer. If bit 15 of PER is zero, the event polarity is
stored in bit 15 in the capture buffer. This can be used to measure frequency
parameters like duty cycle using only one input pin and one capture channel.
3.6 Event Input Selection
The TC input capture system uses the XMEGA event system to trigger an input
capture. Refer to application note AVR1001 for more information about the XMEGA
event system.
When the TC is used for input capture, all enabled input capture channels must be
associated with an event channel. The EVSEL[3:0] bits of the CTRLD register select
the event channels that are associated with the input capture channels. EVSEL3 must
be 1 to select an event source. EVSEL[2:0] selects between the 8 event channels.
The event channels associated with the different channels cannot be selected
individually. Table 3-2 shows the mapping between global event channels and input
capture channels when EVSEL3 = 1 and EVSEL[2:0] = N. The “%” is the modulo
operator. Note that when a set of event channels have been selected for the TC, this
does not mean that these event channels are used exclusively by the TC. The TC
simply “listens” to the selected channels and is able to receive events on these event
channels.