This example code demonstrates how to do compensation for static drift. The drift is not measured, as it is static. Temperature is therefore not considered here. As this example uses a known value for the drift, the direction of the drift is also known. The RTC is configured to generate an interrupt every second. In the ISR, a variable keeps track of the cumulative error. If the error is larger than one 32.768 kHz clock cycle, the RTC period is reduced to compensate for this.
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 now illustrated a way of compensating for static drift.