41.6.2.7 Capture Operations
To enable and use capture operations, the Match or Capture Channel x Event Input Enable bit in the Event Control register (EVCTRL.MCEIx) must be written to ‘1
’. The capture channels to be used must also be enabled in the Capture Channel x Enable bit in the Control A register (CTRLA.CPTENx) before capturing can be performed.
Event Capture Action
The compare/capture channels can be used as input capture channels to capture events from the Event System and give them a timestamp. The following figure illustrates four capture events for one capture channel. Event system channels must be configured to operate in asynchronous mode when used for capture operations.
For input capture, the Buffer register and the corresponding CCx act like a FIFO. When CCx is empty or read, any content in CCBUFx is transferred to CCx. The Buffer Valid flag is passed to set the CCx Interrupt flag (IF) and generate the optional interrupt, event or DMA request. The CCBUFx register value cannot be read; all captured data must be read from the CCx register.
The TCC can detect capture overflow of the input capture channels. When a new capture event is detected while the Capture Buffer Valid flag (STATUS.CCBUFV) is still set, the new timestamp will not be stored and INTFLAG.ERR is set.
Period and Pulse-Width (PPW) Capture Action
The TCC can perform two input captures and restart the counter on one of the edges. This enables the TCC to measure the pulse-width and period and to characterize the frequency f and dutyCycle of an input signal, illustrated as follows.
Selecting PWP or PPW in the Timer/Counter Event Input 1 Action bit group in the Event Control register (EVCTRL.EVACT1) enables the TCC to perform one capture action on the rising edge and the other one on the falling edge. When using the PPW event action, period T is captured into CC0 and the pulse-width tp into CC1. The PWP (Pulse-width and Period) event action offers the same functionality, but T is captured into CC1 and tp into CC0.
The Timer/Counter Event x Invert Enable bit in the Event Control register (EVCTRL.TCEINVx) is
used for event source x to select whether the wraparound must occur on the rising edge
or the falling edge. If EVCTRL.TCEINVx = 1
, the wraparound will happen
on the falling edge.
The corresponding capture is done only if the channel is enabled in Capture mode (CTRLA.CPTENx =
1
). If not, the capture action is ignored and the channel is
enabled in compare mode of the operation. When only one of these channels is required,
the other channel can be used for other purposes.
The TCC can detect capture overflow of the input capture channels. When a new capture event is detected while the INTFLAG.MCx is still set, the new timestamp will not be stored and INTFLAG.ERR is set.
- When up-counting (CTRLBSET.DIR = 0), counter values lower than
‘
1
’ cannot be captured in Capture Minimum mode (FCTRLn.CAPTURE = CAPTMIN). To capture the full range including value ‘0
’, the TCC must be configured in Down-counting mode (CTRLBSET.DIR =0
). - In dual-slope PWM operation and when TOP is lower than MAX/2, the CCx MSB
captures the CTRLB.DIR state to identify the ramp where the capture was done.
For rising ramps CCx[MSB] is ‘
0
’; for falling ramps CCx[MSB] =1
.