2.5.3 TCD - Timer/Counter Type D

The Timer/Counter type D (TCD) is a high-performance waveform generator that consists of an asynchronous counter, a prescaler, and compare, capture and control logic. The TCD counter can run on a clock which is asynchronous to the peripheral clock. It contains compare logic that generates two independent outputs with optional dead-time. It is connected to the Event System for capture and deterministic Fault control. The timer/counter can generate interrupts and events on compare match and overflow.

Similar to other AVR Dx timers, the TCD can be used to generate PWM waveforms. Even if the waveform generation modes are similar to TCA or TCB (one ramp, two ramp, four ramp, dual slope), the TCD compare logic allows conditional waveform generation on external events like Fault handling, input blanking, overload protection, and fast emergency stop by hardware. Those features, together with dead-time support, make the TCD an ideal choice for applications that require hardware support for half-bridge and full-bridge signals.

The TCD waveform output signals are controlled by the Compare Enable (CMPxEN) bits in the TCDn.FAULTCTRL register and are available internally or on the pins. Similar to other AVR Dx peripherals, the TCD overwrites the functionality of the pin but does not configure the pin as an output. If the waveform outputs are needed on the pins, the software must configure those pins as outputs.

The following code shows TCD initialization for the generation of complementary driving signals, with dead-time:

AVR® Dx - TCD Initialization in Half-Bridge Mode

void TCD0_init(void)
{
    /* set the waveform mode */
    TCD0.CTRLB = TCD_WGMODE_DS_gc;

    /* set the signal period */
    TCD0.CMPBCLR = SIGNAL_PERIOD_EXAMPLE_VALUE;

    /* the signals are alternatively active and a small symmetric dead-time is needed */
    TCD0.CMPBSET = SIGNAL_DUTY_CYCLE_EXAMPLE_VALUE + 1;
    TCD0.CMPASET = SIGNAL_DUTY_CYCLE_EXAMPLE_VALUE - 1;

    /* ensure ENRDY bit is set */
    while(!(TCD0.STATUS & TCD_ENRDY_bm))
    {
    ;
    }

    TCD0.CTRLA = TCD_CLKSEL_20MHZ_gc     /* choose the timer’s clock */
               | TCD_CNTPRES_DIV1_gc     /* choose the prescaler */
               | TCD_ENABLE_bm;          /* enable the timer */
}

Note: For more details and code examples, refer to TB3212 - Getting Started with TCD.