AVR1306
15
8045A-AVR-02/08
6.6 Setting up a 32-bit Timer/Counter With Input Capture
Task: Configure TCC0 and TCC1 as one 32-bit TC with input capture channel A
triggered by a falling edge on PC0. Event channel 0 is used for overflow propagation,
while the input capture signal from PC0 is routed through event channel 1.
1. Configure PC0 for input, triggered on falling edge.
2. Select PC0 as multiplexer input for event channel 1.
3. Select TCC0 overflow as multiplexer input for event channel 0.
4. Configure TCC0 and TCC1 for input capture with event channel 1 as trigger.
5. Enable event delay on TCC1. (This will delay the input capture event by one clock
cycle to allow the overflow from TCC0 to propagate to TCC1 before the input
capture happens.)
6. Enable Input Capture Channel A on TCC0 and TCC1.
7. Select event channel 0 as clock source for TCC1 (CLKSEL in CTRLA).
8. Start the TCC0 by selecting system clock as clock source (CLKSEL in CTRLA).
9. Wait for TCC0 (or TCC1) input capture interrupt flag A in INTFLAGS to be set.
10. Read low word input capture value from the TCC0.CCA[H:L] register.
11. Read high word input capture value from the TCC1.CCA[H:L] register.
12. Combine low word and high word to a 32-bit input capture value.
13. Go to step 9.
7 Advanced Features
In this application note, the Timer/Counter modules have been used as standalone
modules. There are some advanced features on the XMEGA that can be used as
“glue” between modules to reduce the amount of code needed and automate parts of
the application.
7.1 DMA Controller
Instead of using polling or interrupt handlers to read input capture values, it is
possible to use the XMEGA DMA controller to move data from one or more registers
to memory buffers or other peripheral modules. This moving of data is done without
CPU intervention and leaves the CPU ready for other tasks; even without executing
interrupt handlers.
For more information, please refer to the device datasheet or the application note
AVR1304.
7.2 Event Generation
The event system has been used in this application note as triggering and clock
sources. The XMEGA TCs can be also be used as event sources for other parts of
the system. The TC modules can generate the following events
•
Timer
overflow.
•
Timer error. (Input capture data lost because input capture buffer is full).
•
Separate events for compare or capture on all channels.