22.3.3.4.2 Frequency (FRQ) Waveform Generation

For frequency generation, the period time (T) is controlled by the TCAn.CMP0 register instead of the Period (TCAn.PER) register. The corresponding waveform generator output is toggled on each compare match between the TCAn.CNT and TCAn.CMPn registers.

Figure 22-9. Frequency Waveform Generation

The following equation defines the waveform frequency (fFRQ):

f FRQ = f CLK_PER 2 N ( CMP0 + 1 )

where N represents the prescaler divider used (see the CLKSEL bit field in the TCAn.CTRLA register), and fCLK_PER is the peripheral clock frequency.

The maximum frequency of the waveform generated is half of the peripheral clock frequency (fCLK_PER/2) when TCAn.CMP0 is written to 0x0000 and no prescaling is used (N = 1, CLKSEL = 0x0 in TCAn.CTRLA).

Use the TCAn.CMP1 and TCAn.CMP2 registers to get additional waveform outputs WOn. The waveforms WOn can either be identical or offset to WO0. The offset can be influenced by TCAn.CMPn, TCAn.CNT and the count direction. The offset in seconds tOffset can be calculated using the equations in the table below. The equations are only valid when CMPn < CMP0.

Table 22-2. Offset Equation Overview
Equation Count Direction CMPn vs. CNT State Offset
t O f f s e t = ( C M P 0 C M P n C M P 0 + 1 ) ( T 2 ) UP CMPn ≥ CNT WOn leading WO0
DOWN CMP0 ≤ CNT WOn trailing WO0
CMP0 > CNT and CMPn >CNT WOn trailing WO0
t O f f s e t = ( C M P n + 1 C M P 0 + 1 ) ( T 2 ) UP CMPn < CNT WOn trailing WO0
DOWN CMPn ≤ CNT WOn leading WO0

The figure below shows the leading and trailing offset for WOn, where both equations can be used. The correct equation is determined by count direction, and the state of CMPn vs. CNT when the timer is enabled or CMPn is changed.

Figure 22-10. Offset When Counting Up

The figure below shows how changing CMPn during run-time can invert the waveform.

Figure 22-11. Inverting Waveform Output