Calibration with High Frequency Input

The idea is to use TCD to count a fast reference frequency within a set period given by the RTC running from a crystal oscillator. The number of TCD overflows, and the final capture value can be compared to an expected value. Refer to Get Source Code from Atmel | START for a link to the projects.

The method consists of the following steps:

  1. 1.Apply an external reference frequency to the EXTCLK pin of the device.
  2. 2.Configure TCD to use this as its clock source.
  3. 3.Configure the RTC to use the XOSC32K clock.
  4. 4.Configure the Event System to transmit the overflow signal from the RTC to get a capture value from the TCD.

TCD will start counting from zero after the first capture, therefore the first captured value should be discarded. Count the number of TCD overflows within the RTC period. When the RTC period is done, store the second capture value and use this and the number of TCD overflows as the measured value. The difference between the ideal expected value and the measured value indicates the frequency error of the crystal.

In the example, the RTC period that is measured is set to correspond to one second, provided that the crystal is exact. The external reference used in this example has a frequency of 20 MHz. If the crystal is running at exactly 32.768 kHz, and the period is set to one second, TCD should reach 20,000,000 counts. As TCD is only 12 bits wide it cannot reach this count value. It will overflow 4882 times, and the final capture value should be 3328.

Now, let's say that the final capture value does not reach this ideal value, but instead it reaches 2296, while the number of overflows is still 4882. TCD has counted 3328-2296=1032 cycles less than it should. The crystal is running faster than it should, causing the RTC period to be shorter than expected. In seconds the time difference is 1032/20,000,000=51.6µs/s.