1.2 Timer/Counter Type E

The TCE provides accurate program execution timing, frequency and waveform generation, and command execution. The TCE consists of a base counter and multiple compare channels. The base counter can be used to count clock cycles or events or let events control how it counts clock cycles. The counting direction and period setting control are used for accurate timing. The compare channels can be used with the base counter for compare match control, frequency generation, and pulse-width waveform modulation. The TCE features the following characteristics:

  • 16-Bit Timer/Counter
  • Four Compare Channels
  • Double-Buffered Timer Period Setting
  • Double-Buffered Compare Channels
  • Waveform Generation:
    • Frequency generation
    • Single-Slope PWM
    • Dual-Slope PWM
  • Count on Event
  • Timer Overflow Interrupts/Events
  • One Compare Match per Compare Channel
  • Increase Waveform Generator Resolution up to 8x (three bits)

Depending on the mode of operation, the counter is cleared, reloaded, incremented, or decremented at each timer/counter clock or event input. In the context of this technical brief, the focus is on the Normal operation mode.

During operation, the counter counts clock ticks in the direction selected by the Direction bit in the Control E (TCEn.CTRLE) register. The clock ticks are given by the peripheral clock, prescaled according to the Clock Select bit field in the Control A (TCEn.CTRLA) register.

The counter value is compared continuously to zero and the Period register value to determine whether the counter has reached TOP (the highest value in the count sequence) or BOTTOM (zero). When reaching TOP while the counting direction is set to up, the counter will wrap to 0 at the next clock tick. When counting down, the counter is reloaded with the Period register value when the BOTTOM is reached.

The counter value in the Counter register can be changed during operation. The write access to the register has higher priority than the count, clear or reload operations and will be immediate. The direction of the counter can also be changed during normal operation by writing to the Direction bit.

An Overflow interrupt and event will be generated when the counter has reached either TOP or BOTTOM, depending on the counting direction.

Figure 1-3. TCE Normal Operation