25.3.3.6 TCD Counter Capture
- Capture value on input events
- Software capture
The capture logic contains two separate capture blocks, CAPTUREA and CAPTUREB, that can capture and synchronize the TCD counter value to the I/O clock domain. CAPTUREA/B can be triggered by input event A/B or by software.
The capture values can be obtained by reading first the TCDn.CAPTUREAL/TCDn.CAPTUREBL registers and then the TCDn.CAPTUREAH/TCDn.CAPTUREBH registers.
Captures Triggered by Input Events
To enable the capture on an input event, write a ‘1
’ to the ACTION
bit in the respective Event Control (TCDn.EVCTRLA or TCDn.EVCTRLB) register when
configuring an event input.
When a capture has occurred, the TRIGA/B flag is raised in the Interrupt Flags
(TCDn.INTFLAGS) register. The corresponding TRIGA/B interrupt can be enabled by
writing a ‘1
’ to the respective Trigger Interrupt Enable (TRIGA or
TRIGB) bit in the Interrupt Control (TCDn.INTCTRL) register. By polling TRIGA or
TRIGB in TCDn.INTFLAGS, the user knows that a CAPTURE value is available and can
read out the value by reading first the TCDn.CAPTUREAL or TCDn.CAPTUREBL register
and then the TCDn.CAPTUREAH or TCDn.CAPTUREBH register.
PWM Capture
To perform a PWM capture, connect both event A and event B to the same asynchronous event channel that contains the PWM signal. To get information on the PWM signal, configure one event input to capture the rising edge of the signal. Configure the other event input to capture the falling edge of the signal.
▲ Event trigger
* Interrupt trigger
Capture Triggered by Software
The software can capture the TCD value by writing a ‘1
’ to the
respective Software Capture A/B Strobe (SCAPTUREx) bit in the Control E (TCDn.CTRLE)
register. When this command is executed, and the Command Ready (CMDRDY) bit in the
Status (TCDn.STATUS) register reads ‘1
’ again, the CAPTUREA/B value
is available. It can now be read by reading first the TCDn.CAPTUREAL or
TCDn.CAPTUREBL register and then the TCDn.CAPTUREAH or the TCDn.CAPTUREBH
register.
Using Capture Together with Input Modes
The capture functionality can be used together with the input modes. The same event will then both capture the counter value and trigger a change in the counter flow, depending on the input mode selected.
Reset One Ramp Mode by Input Event Capture
In One Ramp mode, the counter can be reset by an input event capture. To achieve
this, use input event B and write 0x08
to the INPUTMODE bit field
in the Input Control B (TCDn.INPUTCTRLB) register.