/* p11_6.c Dead-time creation with CC0 and CC1 of TCC0 * * See text for detailed description. * * PA08 = TCC0/WO[0], PA09 = TCC0/WO[1] * * Tested with Atmel Studio 7 v7.0.1006 and Keil MDK-ARM v5.21a. */ #include "samd21.h" void TCC0_init(void); void TCC1_init(void); unsigned char* ARRAY_PORT_PINCFG0 = (unsigned char*)®_PORT_PINCFG0; unsigned char* ARRAY_PORT_PMUX0 = (unsigned char*)®_PORT_PMUX0; int main(void) { TCC0_init(); while (1) { } } void TCC0_init(void) { REG_GCLK_CLKCTRL = 0x401A; /* GCLK0 -> TCC0, TCC1 */ REG_PM_APBCMASK |= 0x00000100; /* enable TCC0 Clock in PM */ REG_TCC0_CTRLA = 1; /* reset */ while (REG_TCC0_CTRLA & 1) {} /* wait till out of reset */ REG_TCC0_WAVE = 7; /* dual-slope TOP PWM */ REG_TCC0_PER = 5000; /* period */ REG_TCC0_CC0 = 2625; /* pulse width for channel 0 */ REG_TCC0_CC1 = 2375; /* pulse width for channel 1 */ REG_TCC0_DRVCTRL |= 0x00020000; /* invert ch1 output */ REG_TCC0_CTRLA |= 2; /* enable */ ARRAY_PORT_PINCFG0[8] |= 1; /* make PA08 output for TCC0/WO[0] */ ARRAY_PORT_PINCFG0[9] |= 1; /* make PA09 output for TCC0/WO[1] */ ARRAY_PORT_PMUX0[4] = 0x44; /* PA08 = TCC0/WO[0], PA09 = TCC0/WO[1] */ }