2 Overview
The TCF consists of a base counter and control logic, which can be set in different waveform generation modes like frequency generation, NCO Pulse Frequency, NCO Fixed Duty Cycle and 8-bit Pulse-Width Modulation (PWM). Similar to other timer/counter modules, it can generate interrupts or events based on specific conditions like timer overflows or compare matches.
The timer/counter can be clocked from the multiple clock sources, including Peripheral Clock (CLK_PER), internal oscillators, and Event System (EVSYS).
The Clock Select (CLKSEL) bit field in the Control B (TCFn.CTRLB) register selects one of the clock sources used as an input for the prescaler. The selected clock source can be divided by a maximum of 128 using the 7-bit prescaler.
Using TCF in Frequency Generation Mode
In Frequency Waveform Generation mode, the CMP register controls the period time (T). The corresponding Waveform Generator output is toggled for each compare match between the CNT and CMP registers. The functionality is similar to what TCA and TCB timers/counters have, but the TCF has a 24-bit wide count register, instead of 16-bit width.
Using TCF in 8-bit PWM Mode
The TCF can be configured to run in 8-bit PWM mode where the register pairs in the lowest 16-bit Compare register (CMP0 and CMP1) are used as individual compare registers. The 8-bit PWM functionality is a helpful addition to the TCF. The TCF 8-bit PWM output is single-slope only.
Using TCF in NCO Pulse-Frequency Mode
The NCO mode uses the overflow of an accumulator to create an output signal.
The accumulator overflow is controlled by an adjustable increment value rather than a single clock pulse or postscaler increment, offering an advantage over a simple timer-driven counter because the division resolution does not vary with the limited prescaler/postscaler divider value. The NCO is most useful for applications that require frequency accuracy and high resolution at a fixed duty cycle.
The NCO operates by repeatedly adding a fixed value to an accumulator. Additions occur at the input clock rate. The accumulator will overflow with a carry periodically, the raw NCO output. This reduces the input clock by the added value ratio to the maximum accumulator value.
The NCO output can be modified by stretching the pulse or toggling a flip-flop. Then, the modified NCO output is distributed to other peripherals and optionally output to an I/O pin. The accumulator overflow can also generate an interrupt. The NCO period changes in discrete steps to create an average frequency. This output depends on the ability of the receiving circuit to average the NCO output to reduce uncertainty.
The waveform frequency (fFRQ) is defined by Equation 1:
Equation 1. FRQ Frequency
In this mode, the output becomes active on the clock rising edge immediately following the overflow event, and goes inactive from 1 to 128 clock periods later, determined by the WGPULSE bit field in TCFn.CTRLB, giving a waveform output at the frequency.
The Compare-Match 0 (CMP0) event is generated at every start of the waveform pulse, while the Compare-Match 1 (CMP1) event is generated when the pulse ends. The interrupt flags are set at the same time as the pulse events.
Using TCF in the NCO Fixed Duty-Cycle Frequency Waveform Generation
In NCO Fixed Duty Cycle Frequency Waveform Generation mode, the TCF operates like in NCO PWM mode, but the output is toggled every time the accumulator overflows.
Given that the increment value remains constant, this provides a 50% duty cycle at half the frequency for the Pulse-Frequency mode.
The CMP0 and CMP1 events are generated at alternating overflows.
The interrupt flags are set at the same time as the pulse events, as shown in Equation 2.