Introduction

Authors: Eivind Berntsen, Per Andreas Gulbrandsen, Microchip Technology Inc.

Embedded timekeeping applications often use a 32.768 kHz external crystal oscillator as the clock source, due to the higher accuracy of these, compared to internal oscillators. The accuracy is, however, adversely affected by several factors. This document looks at PCB design, aging and drift over temperature. In addition, crystal manufacturing tolerance will be briefly explained.

For highly accurate timekeeping, the accuracy of the oscillator can be improved. This is done by measuring the error of the oscillator and compensating for it. Frequency measurement can be done using an external reference and internal peripherals of tinyAVR 1-series and megaAVR 0-series, or it can be done using an external component. Both approaches are outlined in this document.

When the error is known, software based compensation can be implemented to reduce the error. A few examples are shown, with some useful techniques for efficient implementation of software based compensation.