10. Know More about the Realtime Clock
Witty Pi 4 uses PCF85063A realtime clock for time keeping. The realtime clock has been calibrated
in factory, and can reach ±2ppm accuracy. The workflow to calibrate the realtime clock can be found
in chapter 8.2.3.3 in PCF85064A’s datasheet.
10.1 CR2032 Battery and Time Keeping
Every package of Witty Pi 4 includes a CR2032 battery. You can put this battery into the battery
holder on Witty Pi 4, so the realtime clock can still keep the correct time after you disconnect power
supply from Witty Pi 4.
This CR2032 battery only powers the realtime clock chip (PCF85063), which only draws ~0.22µA
current. Also, the realtime clock does not draw any current from the battery when external power
supply is connected. As a result, you basically don’t need to replace this battery because it can last
for years.
If your Witty Pi 4 always have power supply connected, you can even omit this battery. The realtime
clock will not lose the correct time when Raspberry Pi is off, because the realtime clock is still
powered by the connected power supply. The CR2032 battery is helpful when you need to move the
device to another site, or your device experiences power failure.
10.2 Alarms and Alarm Output
Witty Pi needs two alarms (one for scheduled startup and one for scheduled shutdown), but
PCF85063A has only one. That’s why we implemented two alarms in the firmware instead. This also
brings an advantage that both alarms now can be accurate to seconds.
The ALM/ALARM in unpopulated header P3 is connected to the alarm output of realtime clock. This
pin will stay in 3.3V level and will be pulled to 0V when an alarm occurs. This signal is for integration
purpose, so other systems can know whether Witty Pi 4 has triggered an alarm.
Because the realtime clock itself only has one alarm, Witty Pi 4’s firmware always copies the nearly
overdue alarm data to the realtime clock, so both alarms can trigger the ALM/ALARM signal.
10.3 Temperature Compensation
In order to get even better accuracy, Witty Pi 4’s firmware also makes temperature compensation for
the crystal it uses. The temperature compensation bases on the fact that the actual frequency of the
crystal changes according to the temperature. The frequency-temperature curve has been measured
and the data are used for such compensation.