Closed
Description
There is something missing in the void configureTCC function.
Here is a working example using TCC_WAVE_WAVEGEN_DSTOP. This example is setting PA22.
I do not see the PORT_PMUX_PMUXE or PORT_PMUX_PMUXO being set anywhere?
Im not sure about the clock though?
Setting the prescaler to TCC_CTRLA_PRESCALER_DIV64, I have strobe lighting from the led´s. I do not have a analyser.
Commenting out the PORT_PMUX_PMUXE / PORT_PMUX_PMUXO part, the example does not work....
void config(){
// Set up the generic clock (GCLK7) to clock timer TCC0
GCLK->GENCTRL[7].reg = GCLK_GENCTRL_DIV(1) | // Divide the 48MHz clock source by divisor 1: 48MHz/1 = 48MHz
GCLK_GENCTRL_IDC | // Set the duty cycle to 50/50 HIGH/LOW
GCLK_GENCTRL_GENEN | // Enable GCLK7
GCLK_GENCTRL_SRC_DFLL; // Select 48MHz DFLL clock source
//GCLK_GENCTRL_SRC_DPLL1; // Select 100MHz DPLL clock source
//GCLK_GENCTRL_SRC_DPLL0; // Select 120MHz DPLL clock source
while (GCLK->SYNCBUSY.bit.GENCTRL7); // Wait for synchronization
GCLK->PCHCTRL[25].reg = GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN_GCLK7;
MCLK->APBBMASK.reg |= MCLK_APBBMASK_TCC0;
TCC0->CTRLA.reg = TCC_CTRLA_SWRST; // Reset
while(TCC0->SYNCBUSY.reg & TCC_SYNCBUSY_SWRST);
TCC0->CTRLA.bit.ENABLE = 0; //Disable
while (TCC0->SYNCBUSY.bit.ENABLE);
TCC0->WAVE.reg |= TCC_WAVE_POL(0xF)|TCC_WAVE_WAVEGEN_DSTOP;
while (TCC0->SYNCBUSY.bit.WAVE == 1 );
PORT->Group[0].PINCFG[22].reg = PORT_PINCFG_PMUXEN; // Group[0] Port A - Pin 22
PORT->Group[0].PMUX[22/2].reg |= PORT_PMUX_PMUXE(6); // PMUX for even pin_number (pin/2)
// PMUXE(6) - Peripheral G (TCC0)
TCC0->PER.reg = 4096;
while ( TCC0->SYNCBUSY.bit.PER); // wait for sync
TCC0->CTRLA.reg |= TCC_CTRLA_ENABLE | TCC_CTRLA_PRESCALER_DIV1; //48Mhz/1=48Mhz/2(up/down)=24MHz/1024=24KHz
while ( TCC0->SYNCBUSY.bit.ENABLE == 1 ); // wait for sync
TCC0->CC[2].reg = 100;
while(true);
}