Waveform Generation Modes

The compare channels can be used for waveform generation on the corresponding port pins. Each Compare Channel n continuously compares the counter value (TCAn.CNT) with the Compare n (TCAn.CMPn) register. If TCAn.CNT equals TCAn.CMPn, the Comparator n signals a match. This signal is then used for waveform generation, function by the WGMODE bit field selection in the TCAn.CTRLB register.

Note: One single waveform mode is available for all the compare channels since the WGMODE bit field is common to all channels.

AVR® Dx - TCA Initialization, Single-Scope PWM Mode

voidTCA0_init(void){/* set waveform output on PORT A */
    PORTMUX.TCAROUTEA = PORTMUX_TCA0_PORTA_gc;

    TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm     /* enable compare channel 0 */| TCA_SINGLE_WGMODE_SINGLESLOPE_gc;/* set single slope PWM mode *//* disable event counting */
    TCA0.SINGLE.EVCTRL &=~(TCA_SINGLE_CNTEI_bm);/* set PWM frequency and duty cycle (50%) */
    TCA0.SINGLE.PERBUF = PERIOD_EXAMPLE_VALUE;
    TCA0.SINGLE.CMP0BUF = DUTY_CYCLE_EXAMPLE_VALUE;

    TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV4_gc /* set clock source (sys_clk/4) */| TCA_SINGLE_ENABLE_bm;/* start timer */}

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