2.3 Algorithm for Determining the Oscillator Calibration Value

A timer/counter can be used to compare the frequencies of the calibration clock (C-clock) and the internal RC oscillator. The 16-bit Timer/Counter C0 (TCC0) is recommended since it is present on most XMEGA devices with tunable RC oscillators. The idea is to capture the frequency of the C-clock using the XMEGA Event System and compare the frequency to predefined limits. The exact frequency of the C-clock is assumed to be known by the application, and by adjusting the RC32KCAL calibration value the frequency of the internal RC oscillator can be tuned according to the C-clock.

A suggested algorithm for determining the most suitable oscillator calibration value is described in the flowchart in Figure 2-1

Figure 2-1. Flowchart of algorithm determining relationship between the C-clock and the internal oscillator frequency