This example uses a look-up table to do temperature compensation. The look-up table is built from the manufacturers data on temperature drift. As the values are symmetrical around 25°C (parabolic curve), only values for 25°C and higher are used, to reduce data size. There are two tables included in this example, one using 8-bit data, and one with 16-bit data. 8-bit data offers reduced datasize, but it gives lower accuracy. There are also two defined values associated with the table.
The application sets up the ADC to read the internal temperature sensor. The resulting temperature value is used to pick a correction value from the look-up table, which is added to the accumulated error.
The RTC is configured to give an interrupt every second. In the RTC ISR the correction is applied. When the accumulated error is larger that one (or more) 32.768 kHz clock cycle, the RTC period is reduced by one (or more). Any remaining error unaccounted for is kept until the next correction cycle.
This example is based on the Application Note AN2711 - Real-Time Clock Calibration and Compensation on AVR® Microcontrollers, which should be referred to for a more detailed understanding of the concepts.
- AN2711 - Real-Time Clock Calibration and Compensation on AVR® Microcontrollers
- ATtiny817 Device Page
- MPLAB® X IDE 6.25 or later
- ATtiny DFP 3.3.272 or later
- MPLAB® XC8 3.00 or later
- AVR/GNU C Compiler 5.4.0 or later
- ATtiny817 Xplained Pro
- Micro-USB cable (Type-A/Micro-B)
- The crystal on the ATtiny817 Xplained Pro board is by default not connected to the TOSC pins, as they are used for UART communication. To connect the pins, remove resistors R307 and R308 and place them on the footprints of R312 and R313. Refer to ATtiny817 Xplained Pro User's Guide for more information on how to do this.
-
Connect the board to the PC.
-
Download the zip file or clone the example to get the source code.
-
Open the project in MPLAB X IDE.
-
Build the solution and program the ATtiny817.
This example has illustrated a way of doing temperature compensation by using look-up tables.