33.6.1 Principle of Operation
The following definitions are used throughout the documentation:
Name | Description |
---|---|
TOP | The counter reaches TOP when it becomes equal to the highest value in the count sequence. The TOP value can be the same as Period (PER) or the Compare Channel 0 (CC0) register value depending on the waveform generator mode in 33.6.2.6.1 Waveform Output Operations. |
ZERO | The counter is ZERO when it contains all zeroes |
MAX | The counter reaches MAX when it contains all ones |
UPDATE | The timer/counter signals an update when it reaches ZERO or TOP, depending on the direction settings. |
Timer | Increment / decrement / clear / reload steps are performed on each prescaled clock cycle. |
Counter | Increment / decrement / clear / reload steps are performed on each detected event. |
CC |
For compare operations, the CC are referred to as “compare channels” For capture operations, the CC are referred to as “capture channels.” |
Each TC instance has up to two compare/capture channels (CC0 and CC1).
The counter in the TC can either count events from the Event System, or clock ticks of the GCLK_TCx clock, which may be divided by the prescaler.
The counter value is passed to the CCx where it can be either compared to user-defined values or captured.
For optimized timing the CCx and CCBUFx registers share a common resource. When writing into CCBUFx, lock the access to the corresponding CCx register (SYNCBUSY.CCX = 1) till the CCBUFx register value is not loaded into the CCx register (BUFVx = 1). Each buffer register has a buffer valid (BUFV) flag that indicates when the buffer contains a new value.
The Counter register (COUNT) and the Compare and Capture registers with buffers (CCx and CCBUFx) can be configured as 8, 16, or 32-bit registers, with according MAX values. Mode settings (CTRLA.MODE) determine the maximum range of the Counter register.
In 8-bit mode, a Period Value (PER) register and its Period Buffer Value (PERBUF) register are also available. The counter range and the operating frequency determine the maximum time resolution achievable with the TC peripheral.
The TC can be set to count up or down. Under normal operation, the counter value is continuously compared to the TOP or ZERO value to determine whether the counter has reached that value. On a comparison match the TC can request DMA transactions, or generate interrupts or events for the Event System.
In compare operation, the counter value is continuously compared to the values in the CCx registers. In case of a match the TC can request DMA transactions, or generate interrupts or events for the Event System. In waveform generator mode, these comparisons are used to set the waveform period or pulse width.
Capture operation can be enabled to perform input signal period and pulse width measurements, or to capture selectable edges from an IO pin or internal event from Event System.