23.3.2.6 TCD Counter Capture

Because the TCD counter is asynchronous to the system clock it is not possible to read out the counter value directly. It is possible to capture the TCD counter value, synchronized to the I/O clock domain in two different ways:
  • 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 read by reading first TCDn.CAPTURExL and then TCDn.CAPTURExH registers.

Captures Triggered by Input Events

To enable capture on input event, write a ‘1’ to the ACTION bit in the respective Event Control x register (TCDn.EVCTRL) when configuring an event input.

When a capture has occurred, the TRIGA/B flag is raised in the Interrupt Flags register (TCDn.INTFLAGS). The according TRIGA/B interrupt is executed if enabled by writing a ‘1’ to the respective Trigger Interrupt x Enable bit (TRIGx) in the Interrupt Control register (TCDn.INTCTRL). By polling TRIGx in TCDn.INTFLAGS, the user knows that a CAPTUREx value is available, and can read out the value by reading first the TCDn.CAPTURExL and then TCDn.CAPTURExH registers.

PWM Capture

In order to do 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.

Capture Triggered by Software

The software can capture the TCD value by writing a ‘1’ to respective Software Capture A/B Strobe bit (SCAPTUREx) in the Control E register (TCDn.CTRLE). When this command is executed and the Command Ready bit (CMDRDY) in the Status register (TCDn.STATUS) reads ‘1’ again, the CAPTUREA/B value is available. It can now be read by reading first the TCDn.CAPTURExL and then the TCDn.CAPTURExH registers.

Using Capture Together with Input Modes

The capture functionality can be used together with 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 the TCDn.INPUTCTRLB register to 0x08.