Compensation for Crystal and Load Capacitance Deviation

In the above example, the crystal was found to be 51.6 µs/s too fast. If we count two extra cycles in the RTC per second, the RTC will become 2*(1/32768)=60 µs/s slower. The error is now reduced to being 60-51.6=8.6 µs/s too slow. A software variable can be used to keep track of the accumulated error in each second. When the accumulated error overflows one period of the 32.768 kHz crystal clock, the RTC period is reduced by one cycle for one second.

In the crystal compensation example found in Atmel | START, the precision of the compensation variable is 0.1 µs/s. Increasing the number of decimals counted as the error is possible. In the temperature compensation example, the precision of the compensation is increased to 0.01 µs/s. Refer to Get Source Code from Atmel | START for links to the projects.