/* p11_2.c Using TCC0 PWM Output * * This program uses TCC0 to generate periodic waveform outputs. * The GCLK_TCC0 is running at 1 MHz. Prescaler is not used so * the timer counter clock is 1 MHz as well. * TCC0 is set up to run 24-bit Normal PWM mode, in * which the counter counts up to PER as the TOP value and wraps * around. The channel 0 output is set when on wraparound * and clear on match of CC0. * PER is set to 16,666-1 which gives the output of channel 0 * 1,000,000 / 16,666 = 60 Hz. * CC10 is set to 1/3 of the value of PER so that the outputs of * channel 1 has 33.3% dutycycle. * PB30 is used for TCC0 output channel 0 (TCC0/WO[0]). * * Tested with Atmel Studio 7 v7.0.1006 and Keil MDK-ARM v5.21a. */ #include "samd21.h" unsigned char* ARRAY_PORT_PINCFG1 = (unsigned char*)®_PORT_PINCFG1; unsigned char* ARRAY_PORT_PMUX1 = (unsigned char*)®_PORT_PMUX1; int main (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 = 2; /* Normal PWM */ REG_TCC0_PER = 16666 - 1; /* period */ REG_TCC0_CC0 = 5555 - 1; /* pulse width */ REG_TCC0_CTRLA |= 2; /* enable */ ARRAY_PORT_PINCFG1[30] |= 1; /* make PB30 output for TCC0 */ ARRAY_PORT_PMUX1[15] = 0x04; /* PB30 = TCC0/WO[0] */ while(1) { } }