Compensation for Temperature Drift

To be able to control the capacitive load of the crystal, and to reduce the noise induced into the crystal oscillator circuit, the 32.786 kHz crystal should be placed close to the device. This also means that the device and the crystal will be exposed to the same temperature.

The devices in the tinyAVR 1-series and megaAVR 0-series have an internal temperature sensor. From the characteristics section in the corresponding device data sheet, it can be seen that the temperature sensor has relatively poor accuracy. This is true, even when using the supplied calibration values located in the signature row of the device, as these values are found when the silicon is still on the wafer. Cutting and packaging can have an impact on the silicon and therefore change temperature readout. The calibration value can further deviate when the device is soldered onto the PCB.

It is possible to achieve better results with the internal temperature sensor if new gain and offset values are measured in production. This requires calibration steps, preferably done after the device has been soldered onto the PCB. If good performance over a wide temperature range is needed, two or three point calibration should be performed. Two of the test points should be slightly above and below the temperature range where accuracy is needed, and one close to the middle. If the crystal frequency is measured at these three points, it is possible to get a more accurate parabolic temperature curve than what is given in the characteristics in the crystal data sheet.

Note: While having a high accuracy temperature sensor is optimal, using a low accuracy temperature sensor to do temperature compensation is still useful. This is especially true if the operating temperature is far from 25°C, as the compensation values chosen based on an inaccurate temperature reading will be more accurate than values given for 25°C.