SAMD21 WO[] and CC[] register mapping

I’ve been messing with using the Trinket M0 with SAMD21 chip for PWM (thanks, MartinL!) and have discovered an interaction between the SAMD21 data sheet, and “received wisdom” on the 'net, is likely to lead newcomers like me astray. I’m posting this in the hope it may help others to avoid wasting time.

The port mapping table in the data sheet[1] says that on pins PA08 and PA09, function F uses WO registers 2 and 3 respectively.

A few places on the web say that when setting the duty cycle of the timer you use CC[n] where n is determined by n = x % 4, and x is from WO.

That applies to TCC0, which has 4 WO registers, but TCC1 has only two and the proper CC[n] value for TCC1 is x % 2 – e.g., where function F of PA08 says TCC1/WO[2], you need to use CC[0], and where function F of PA09 says TCC1/WO[3], you need to use CC[2].

A post from another part of the forum[2] tells you about the number of WO registers (thanks, Martin!), but doesn’t link that to use of CC[n]. I wanted to make this post to document the added wrinkle with the TCC1 WO and CC registers.




@n8ur Hi John,

The TCC timer outputs is probably one of the most poorly explained sections of the SAMD21 datasheet.

TCC0 has four channels 0 to 3, output on WO[0] to WO[3] respectively and repeated on outputs WO[4] to WO[7], so channel 0 for example is repeated on output WO[4], channel 1 on WO[5] and so on.

In normal operation, the repeated outputs simply allow a given timer channel the opportunity to be output on more pins. However, when the timer’s dead-time operation is enabled, the channel’s output and repeated output become a non-inverted and inverted signal pair that can be used to drive high and low side transistors (with dead-time offset), for instance to control a DC motor with a H-bridge.

TCC1 has 2 channels, 0 and 1 output on WO[0] and WO[1], repeated on WO[2] and WO[3].

TCC2 also has 2 channels, whose outputs WO[0] and WO[1] are not repeated.

Hi Martin – yes, your other message that I cited was what finally showed me what was going on. The main reason I made this post is because of the “n % 4” advice that seems to have made its way into Google, which only works for TCC0. And the Trinket M0 has so few pins available that you might well need to use those TCC1/WO[2] and TCC1/WO[3] pins.

And again, thanks for the huge amount of help you’ve given me and others.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.