7 TCD with XOSCHF

To use XOSCHF as clock source for TCD0, first enable the XOSCHF similarly to the first two use cases. The crystal or input clock frequency can be up to 32 MHz.

	/* Enable crystal oscillator with frequency range 16 MHz and 4K cycles start-up time */
	ccp_write_io((uint8_t *) &CLKCTRL.XOSCHFCTRLA, CLKCTRL_RUNSTDBY_bm
	             | CLKCTRL_CSUTHF_4K_gc
	             | CLKCTRL_FRQRANGE_16M_gc
	             | CLKCTRL_SELHF_CRYSTAL_gc
	             | CLKCTRL_ENABLE_bm);

	/* Confirm crystal oscillator start-up */
	while(!(CLKCTRL.MCLKSTATUS & CLKCTRL_EXTS_bm))
	{
		;
	}

	/* Clear RUNSTDBY for power save during sleep */
	ccp_write_io((uint8_t *) &CLKCTRL.XOSCHFCTRLA, 
	             CLKCTRL.XOSCHFCTRLA & ~CLKCTRL_RUNSTDBY_bm);

To select the XOSCHF as clock source for TCD0, the EXTCLK setting must be written to the Clock Select (CLKSEL) bit field in the Control A (TCD0.CTRLA) register.

Figure 7-1. TCD0.CTRLA – Enable TCD0 with PLL as source

	/* Configure the TCD with XOSCHF (16 MHz) as source */
	TCD0.CTRLA = TCD_CLKSEL_EXTCLK_gc | TCD_CNTPRES_DIV1_gc | TCD_SYNCPRES_DIV1_gc;

	/* Replace with your application configuration */

	/* Enable TCD0 */
	TCD0.CTRLA |= TCD_ENABLE_bm;

The code for this example is available in the TCD-with-XOSCHF folder in these github repositories: