I am trying to use TC7 in match PWM mode with output WO[1].
If i start the timer with CC0 and CC1 setup for an initial period and duty the output works.
But if I try to change the period on the fly ( CC0 ) it appears to stall the timer. At least the output ceases to toggle.
setup code
// *******TC7 setup for match PWM waveform generation. Used for feed step motor drive
REG_TC7_INTFLAG = 0x000000ff; // reset any interrupts pending
REG_TC7_CTRLA = 0x000000; // disable TC7 to make config changes
while(REG_TC7_STATUS & TC_STATUS_SYNCBUSY);
REG_TC7_CTRLBSET = TC_CTRLBSET_DIR; // count up
while(REG_TC7_STATUS & TC_STATUS_SYNCBUSY);
REG_TC7_CTRLA = TC_CTRLA_MODE_COUNT16 | TC_CTRLA_WAVEGEN_MPWM; // 16 bit mode - match frequency generator
while(REG_TC7_STATUS & TC_STATUS_SYNCBUSY);
REG_TC7_INTENSET = TC_INTENSET_MC0; // no interrupt routine. used as a flag for setting CC0 register immediately after match
while(REG_TC7_STATUS & TC_STATUS_SYNCBUSY);
REG_TC7_CTRLC = TC_CTRLC_CPTEN1;
while(REG_TC7_STATUS & TC_STATUS_SYNCBUSY); //?
REG_TC7_CTRLA |= TC_CTRLA_ENABLE;
while(REG_TC7_STATUS & TC_STATUS_SYNCBUSY);
In a fast loop I try to write CC0 immediately after a match so the new CC0 value will still be above the current count.
if(REG_TC7_INTFLAG & TC_INTFLAG_MC0) // check for MC0 match
{
REG_TC7_INTFLAG = TC_INTFLAG_MC0; // writing should clear..
if(TC7CC0HasNewValueFlag) // must write new CC0 value immediately after rollover of MC1
{
TC7CC0HasNewValueFlag = 0;
REG_TC7_COUNT16_CC0 = FeedMotorRealTimeCCVal;
while(REG_TC7_STATUS & TC_STATUS_SYNCBUSY);
}
}
All I want to do is change the output frequency via setting CC0.
Thanks