Setup of Timer/Counters

This chapter describes the setup of the two different timer modules used in this application note, the 16-bit Timer/Counter Type B (TCB) and the 16-bit Timer/Counter Type A (TCA).

16-bit Timer/Counter Type A (TCA) Setup

The 16-bit Timer/Counter Type A (TCA) is used for keeping track of the accumulated incremental movement as indicated by the quadrature pulses on A and B.

The 16-bit Timer/Counter Type A (TCA) has one event input and is configured to count both edges of the event signal. It also has a configurable count direction. By setting the generated count signal as the event input and updating the counter direction according to the generated direction signal, the timer/counter can keep track of the incremental encoder pulses requiring CPU only to update the count direction.

Furthermore, the counter period is set up corresponding to the total number of encoder increments to be counted before the counter value is reset to zero. For applications like tracking the position of a control dial or shaft that always resides in a given angular interval, the size of the measurement window given in encoder counts could be less than or equal to 16 bits. In these cases the counter period should be set up so that zero and the period value represent the endpoints of the measurement window, including sufficient buffers to avoid counter underflow or overflow.

In rotary applications where the measurement window is unconstrained or larger than 16 bits, the counter period should be set to the encoder resolution minus one. Subtracting by one must be done to account for the zero position, so that the total number of unique positions equals the encoder resolution. For these applications the position is only tracked within each encoder revolution, thus if position tracking across multiple revolutions is required the accumulated number of revolutions must be counted as well.

The 16-bit Timer/Counter Type A (TCA) is used in Normal mode without any compare channels or waveform outputs.

16-bit Timer/Counter Type B (TCB) Setup

Two instances of 16-bit Timer/Counter Type B (TCB) are used to detect edges on the quadrature input signals A and B. Both are configured identically.

The 16-bit Timer/Counter Type B (TCB) has one event input and the ability to trigger actions on both event edges. The actions are given by the configured TCB mode. In Single-Shot mode, a single count sequence can be initiated upon detecting an edge on the input event. If the TCB waveform output is enabled, it will be held high until the counter reaches the compare value.

The TCB is configured as an edge detector that outputs a signal strobe of configurable length upon detection of both rising and falling edges on the event input. This is accomplished by enabling the following features:
  • Single-shot mode
  • Event input with dual edge detection
  • Asynchronous waveform output

The configuration is utilized by routing the quadrature inputs via the I/O Pin Controller (PORT) module and the Event System (EVSYS) to the event inputs of the two 16-bit Timer/Counter Type B (TCB) instances. The asynchronous waveform outputs are then routed to the Configurable Custom Logic (CCL) via their output pins.