Hi, I am using the TCC0 timer to generate free-running PWM and hw-triggered one-shot pulses. So I have set clocks, mux'd pins and peripherals (thanks, MartinL!) all working fine.
Now I am looking for a way to drive the output pin high or low after PWM or one-shot operation is done.
For one-shot, I may use the Non-Recoverable Fault registers NRE and NRV to switch to either high or low after the pulse.
TCC0->DRVCTRL.reg |= TCC_DRVCTRL_NRE4 | TCC_DRVCTRL_NRV4; // drives pin high after one shot, see SAMD21 datasheet 31.6.3.1
But how to do it when the TCC0 peripheral is already disabled via TCC_CTRLA_ENABLE ? Or, more generally, how to temporarily disable the timer and set the output pin "manually" to high or low?
I tried something like
if (input==0){
TCC0->DRVCTRL.reg |= TCC_DRVCTRL_NRV4;
TCC0->DRVCTRL.reg |= TCC_DRVCTRL_NRE4;
TCC0->CTRLBSET.reg |= TCC_CTRLBSET_CMD_STOP; while(TCC0->SYNCBUSY.bit.CTRLB);
}
else {
TCC0->DRVCTRL.reg &= ~TCC_DRVCTRL_NRV4;
TCC0->DRVCTRL.reg |= TCC_DRVCTRL_NRE4;
TCC0->CTRLBSET.reg |= TCC_CTRLBSET_CMD_STOP; while(TCC0->SYNCBUSY.bit.CTRLB);
}
to stop the timer toggle the pin high or low, but this "crashes" the SAMD (i.e., it's irresponsive). Removing the syncbusy check does not help.