This example shows how to configure the Timer Counter in both waveform and capture operating modes. In capture mode, a pulse signal (output from PIN_TC_WAVEFORM) is connected to PIN_TC_CAPTURE, and Register A (RA) and Register B (RB) will be loaded when their programmed event occurs.
When the Timer Counter interrupt occurs, its interrupt handler reads the RA and RB register values (for computing pulse frequency) and also increases the total pulse count number. The current pulse frequency and total pulse count number are both output via the debug UART.
Select pre-defined waveform frequency and duty cycle to be generated
Configure TC_CHANNEL_WAVEFORM as waveform output
Configure TC_CHANNEL_CAPTURE as a capture input
Configure capture Register A (RA) to be loaded when a rising edge on TIOA occurs
Configure capture Register B (RB) to be loaded when a falling edge on TIOA occurs
Configure a Timer Counter interrupt and enable the RB load interrupt
Pressing 'c' in the terminal window, starts capture
Pressing 's' in the terminal window, stops capture and dumps the information captured so far