Go Down

Topic: SAMD21 TCC2 deadtime (Read 317 times) previous topic - next topic

daveblear

Hi, I'm new to ARM, and I'm porting some waveform generation code for an ATMEGA328 over to the Arduino Feather M0. From what I can gather from the datasheet and some forum posts, the deadtime feature is only available using TCC0, as it's the only TCC with W[4..7] available. Is this the case?

The hardware guy wants to use PA16/17 (i.e. TCC2/W[0..1] - same pins as TCC0/W[6..7]), so the builtin deadtime can't be used, though it's very easy just to set CC0/CC1 to incorporate the deadtime when the duty cycle is set, which is what I'll do. Is there anything wrong with this approach?

Also, do the arduino libraries for the Zero/Feather-M0 reserve any timers for anything? (similar to how one of the timers in the Uno is used for the millis() function)

Thanks very much for any insight and answers to my random questions :)

Cheers,
Dave

MartinL

#1
Jun 03, 2018, 07:09 pm Last Edit: Jun 03, 2018, 07:21 pm by MartinL
Hi Dave,

Quote
From what I can gather from the datasheet and some forum posts, the deadtime feature is only available using TCC0, as it's the only TCC with W[4..7] available. Is this the case?
Yes, the deadtime feature is only available on timer TCC0, but it's available on both the non-inverting low side TCC0/W[0-3] and the inverting high side TCC0/W[4-7] outputs. Deadtime insertion is controlled by the TCC0 Waveform Extension Control (WEXCTRL) register.

Quote
The hardware guy wants to use PA16/17 (i.e. TCC2/W[0..1] - same pins as TCC0/W[6..7]), so the builtin deadtime can't be used, though it's very easy just to set CC0/CC1 to incorporate the deadtime when the duty cycle is set, which is what I'll do. Is there anything wrong with this approach?
If you require independent low side and high side deadtime insertion then you'll need to choose one TCC0 output from the low side TCC0/W[0..3] and the other from the high side TCC0/W[4..7].

If you're using the TCC0's other output channels as well then it's best to match the timer's non-inverting and its corresponding inverting channel, for example either TCC0/W[0] with TCC0/W[4], TCC0/W[1] with TCC0/W[5], TCC0/W[2] with TCC0/W[6] or TCC0/W[3] with TCC0/W[7].

It's also possible to switch the channel outputs to a limited extent, by using the TCC0 output matrix (OTMX), also found in the WEXCTRL register. For instance, setting the OTMX to 0x2 sets all the TCC0 outputs to channel 0 (CC0), allowing you to mix 'n' match any pair of low TCC0/W[0..3] and high side TCC0/W[4..7] outputs, but this comes with the disadvantage that other TCC0 channel outputs (CC1..CC3) will be become unavailable.

Quote
Also, do the arduino libraries for the Zero/Feather-M0 reserve any timers for anything? (similar to how one of the timers in the Uno is used for the millis() function)
By default, none of the timers are reserved. Timers TCC0..TCC2 and TC3..TC5 are free to use as you wish. The Arduino timing functions such as millis(), micros() and delay() are generated using the ARM microcontroller's systick (system ticker) timer.

However certain Arduino functions such as analogWrite() do make use of various timers, depending on what pin is being used.

daveblear

Thanks very much for the informed response.

Dead time is symmetric, so it looks like using TCC2/W[0..1] will be absolutely fine for outputs D11/D13. According to https://forum.arduino.cc/index.php?topic=346731.msg2391593#msg2391593, analogWrite() only uses TCC2 for D11/D13, so no problems there either. Great!

Cheers,
Dave

Go Up