Hi all.
I have a strange problem on a zero clone that I use for test.
I need 4 PWM output @ 50Hz to drive LEDS. I want to use TCC0 [ 0 to 3 ] for that.
For now, I use this part of code to initialize PWM:
void Init_PWM () {
REG_GCLK_GENDIV = GCLK_GENDIV_DIV ( 0x40 ) | // Division de l'horloge par 64 ( 48MHz / 64 = 750kHz ).
GCLK_GENDIV_ID ( 0x4 );
while ( GCLK -> STATUS.bit.SYNCBUSY );
REG_GCLK_GENCTRL = GCLK_GENCTRL_IDC |
GCLK_GENCTRL_GENEN |
GCLK_GENCTRL_SRC_DFLL48M |
GCLK_GENCTRL_ID ( 0x4 );
while ( GCLK -> STATUS.bit.SYNCBUSY );
REG_GCLK_CLKCTRL = GCLK_CLKCTRL_CLKEN |
GCLK_CLKCTRL_GEN_GCLK4 |
GCLK_CLKCTRL_ID_TCC0_TCC1;
while ( GCLK -> STATUS.bit.SYNCBUSY );
REG_TCC0_WAVE |= TCC_WAVE_WAVEGEN_NPWM;
while ( TCC0 -> SYNCBUSY.bit.WAVE );
REG_TCC0_PER = 15000; // Configuration de la période: 750kHz / 15000 = 50Hz !
while ( TCC0 -> SYNCBUSY.bit.PER );
REG_TCC0_CC0 = 0;
while ( TCC0 -> SYNCBUSY.bit.CC0 );
REG_TCC0_CC1 = 0;
while ( TCC0 -> SYNCBUSY.bit.CC1 );
REG_TCC0_CC2 = 0;
while ( TCC0 -> SYNCBUSY.bit.CC2 );
REG_TCC0_CC3 = 0;
while ( TCC0 -> SYNCBUSY.bit.CC3 );
REG_TCC0_CTRLA |= TCC_CTRLA_PRESCALER_DIV1 |
TCC_CTRLA_RUNSTDBY |
TCC_CTRLA_ENABLE;
while ( TCC0 -> SYNCBUSY.bit.ENABLE );
}
and only this to set the output:
PORT -> Group [ g_APinDescription [ LIGHTS ].ulPort ].PINCFG [ g_APinDescription [ LIGHTS ].ulPin ].bit.PMUXEN = 1;
PORT -> Group [ g_APinDescription [ LIGHTS ].ulPort ].PMUX [ g_APinDescription [ LIGHTS ].ulPin >> 1 ].reg = PORT_PMUX_PMUXE_E;
Pin LIGHT is pin D4 ( Port A.08, TCC0[0] ), but nothing on output.
If I use pin A3 ( Port A.04, also TCC0[0] ), the sketch run fine ( sometimes a visual glitch ).
Quickly test with TCC0[0 to 3 ] on pins D4, D3, D10 and D12 ( rewrite sketch to match ), and nothing run.
I dont understand why PWM run on analog pin, and not on digital pin.