There are a few modes for the TC.
In 8 bit mode, with normal PWM, there are 3 registers controlling the output, PER sets the period, when the count reaches this value, it resets to zero (assuming the TC is counting up). The CC0 and CC1 registers give two separately controlled outputs. For example if PER is set to 100, if CC0 is set to 50 you will get a 50% duty cycle
In 16 bit mode, with normal PWM, the period cannot be controlled, it always resets at max count, but like the 8 bit case. the CC0 and CC1 registers give two separately controlled outputs. If match PWM is selected, then the CC0 register controls the period, and the CC1 register gives the PWM output.
The code below is for the backlight control if my LCD.
Personally I do not use Harmony.
GCLK->PCHCTRL.reg = GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN(0); /* Connect GenClk0 to TC0 (4MHz CPU clock) */
while ((GCLK->PCHCTRL.reg & GCLK_PCHCTRL_CHEN) == 0); /* Wait for Sync */
TC0->COUNT8.CTRLA.reg = TC_CTRLA_SWRST; /* reset the timer */
while(TC0->COUNT8.SYNCBUSY.reg & TC_SYNCBUSY_SWRST); /* wait for reset to complete */
TC0->COUNT8.CTRLA.reg = TC_CTRLA_PRESCALER_DIV4 | TC_CTRLA_MODE_COUNT8; /* set to 1:4 prescaler and 8 bits */
TC0->COUNT8.WAVE.reg = TC_WAVE_WAVEGEN_NPWM; /* set waveform to normal PWM */
TC0->COUNT8.PER.reg = PWM_PERIOD; /* set the PWM period */
TC0->COUNT8.CC.reg = BRIGHT_TIMER_VALUE; /* set the PWM duty cycle */
PORT->Group[BACKLIGHT_PORT].PINCFG[BACKLIGHT_PIN].reg = PORT_PINCFG_PMUXEN; /* make port output for TC0 */
PORT->Group[BACKLIGHT_PORT].PMUX[BACKLIGHT_PIN/2].reg |= PORT_PMUX_PMUXE(4); /* PB08 = TC0/WO */
TC0->COUNT8.CTRLA.reg |= TC_CTRLA_ENABLE; /* Enable the timer */
while(TC0->COUNT8.SYNCBUSY.reg & TC_SYNCBUSY_ENABLE); /* wait for sync */
post edited by malaugh - 2021/02/05 09:33:06