atmelsamd21

Pause SAMD21 TCC counter


The Atmel SAMD21 TCC peripheral provides a STOP command, which pauses the counter. The counter can be resumed with a RETRIGGER command.

When STOP is issued, the TCC enters a fault state, in which the outputs are either tristated, or driven to states specified in a config register. Presumably this mechanism is designed to support a fixed failsafe output state.

In my case I want the output pins to freeze in the state they're in at the time of the STOP command. The only way I can see to to do this is to update the configured fault output state register every time the outputs are updated - requiring interrupt processing which kind of defeats the purpose of much of the TCC's output waveform extension architecture, as well as being a processing load I'd prefer to avoid. There are other complications too, such as accounting for the dead time mechanism, and hardware/software races.

So I've been looking at ways to achieve this that don't involve the STOP command - but I can't see any other way of stopping the counter. There's no way to gate the peripheral clock input, and disabling it in GCLK is ruled out as it also runs TCC1. (And who knows what other effects this would have.) Negating the ENABLE bit, besides being overkill, unsurprisingly also tristates the outputs. Modifying the configuration in various other ways usually requires writing to enable-protected registers, thus requiring disabling the peripheral first.

(One idea I haven't investigated that yet is to drive the counter from the event system, and control the event generation/gating instead.)

So: is there any way of pausing the peripheral in its current state, while maintaining the state of the output pins?


Solution

  • All that I can think of to try is the async 'COUNT' event, which sounds like it is a gate for the clock to the counter.

    (page numbers from the 03/2016 manual)

    31.6.4.3. Events, p.712; Count during active state of an asynchronous event (increment or decrement, depending on counter direction). In this case, the counter will be incremented or decremented on each cycle of the prescaled clock, as long as the event is active.

    31.8.9. Event Control, p.734; EVCTRL register, Bits 2:0 – EVACT0[2:0]: Timer/Counter Event Input 0 Action 0x5 COUNT (async) Count on active state of asynchronous event

    The downside is that software events have to be synchronous.