I want to enable PWM on 7 out of 8 I/O pins on PORTC using TC2 on an ATXMEGA64A1U rev H, and I simply can't get it working.
The lower byte is alive (pin 0-2), but the high byte (pin 4-7) is dead.
When looking at the IO registers in the debugger, I noticed that despite setting LPER and HPER, only LPER were written. The same goes for LCNT and HCNT.
It seems like the TC is still operating as TC0 despite being set in split mode.
After changing this to a single write to TCC0_PER, I were able to set both LPER and HPER, but with no change to the end result (still no PWM on pin 4-7).
The code is quite short:
void TimerPwmInit(void)
{
// Split TCC0 in two 8-bit timers.
TCC2_CTRLE = 0b00000010;
// Enable compare output and override port output register for the corresponding OCn output pin.
TCC2_CTRLB = 0b11110111;
// Reset counter
TCC2_HCNT = 0;
TCC2_LCNT = 0;
// Set period.
TCC0_PER = 0x7F7F;
//TCC2_HPER = 127;
//TCC2_LPER = 200;
// Set compare value
TCC2_HCMPD = 32;
TCC2_HCMPC = 32;
TCC2_HCMPB = 32;
TCC2_HCMPA = 32;
TCC2_LCMPD = 32;
TCC2_LCMPC = 32;
TCC2_LCMPB = 32;
TCC2_LCMPA = 32;
// Enable clock to timer.
TCC2_CTRLA = 0b00000110;
}