I am using TCC0 on a D21 for PWM to an H-bridge. I use the Pattern register to override the PWM signals to force an output high or low. The TCC conveniently provides buffer registers for the PWM count (CC[n]) and pattern (PATT) registers (CCB[n] and PATTB) so that changes will kick in together at the end of each PWM cycle.
My problem is that the PATTB register is not copied to the PATT registers at update. CCB[n] is copied to CC[n]. The Status register has a flag to indicate that the buffer register has been written and should be copied, and in the debugger I can see this flag gets sets when writing CCB but not when writing PATTB. I have worked around this by setting PATT directly, but this is not synchronized with the change in CC[n] and could cause a serious glitch.
This seems like a bug in the chip, but there is no errata for it. I am using a SAMD21E16B, die rev. E. Has anyone ever successfully used PATTB? On this die revision? I am not using ASF, but have looked at the ASF code and it doesn't do anything differently. To use this in ASF, you would ensure that double buffering is enabled in the TCC driver and call tcc_set_pattern().
// Disable hardware updates from buffer registers while we set them TCC0->CTRLBSET.reg = TCC_CTRLBSET_LUPD; TCC0->CCB.reg = uOnTime; // Set PWM time TCC0->PATTB.reg = usPattB; TCC0->PATT.reg = usPattB; // UNDONE: write to PATTB doesn't seem to work // Enable hardware updates from buffer registers TCC0->CTRLBCLR.reg = TCC_CTRLBCLR_LUPD;
I have tried doing things in different order, removing the update lock, waiting on SYNCBUSY, but nothing changed.