New improved version

Post date: 13-Feb-2018 18:44:42

This version increases the accuracy to better than 1s/month.

The basic version optimizes the performance of an existing quartz frequency, based on the Offset register of the PCF8523 Real Time Clock (RTC). This version makes what any user is supposed to do: at least a monthly adjustment of the watch, to less than 1s error. After following the RTC in its original version, for several months, it proven to have -3.5s/month. Since the minimum step of quartz correction is 0.5s/day, this means, the other option is +4s/month. This is not an improvement! It would then be nice if the RTC could adjust automatically from -3.5 s to +0.5 s after each month. This would mean roughly +6 s/year, which is close to the best achieved performance of a quartz watch: Citizen CTQ57-0953 Chronomaster (http://wornandwound.com/guide-to-high-accuracy-quartz-haq-watches/) which stands at +/-5s/year.

The difficulty is to keep in the RTC registers the last month of the adjustment, supposing that the RTC was accurately set at the beginning of a month. From all available registers, we chosen 0x0D which keeps the day of the week for a possible alarm: unlikely you would like to be awaken on a Saturday or a Sunday!

So, the software reads in, the first 3 bits of the register. After the initial setup, this is set to the month of setup, e.g. 5 = (101) for May.

the month when the RTC was set. So, if the RTC is turned on during the same month, nothing happens. A month later, in fact when the month increased by one unit, e.g. June, the RTC will add 4s to the time it keeps, by calling:

DateTime realtime (now + TimeSpan(0, 0, 0, corr)); // Add 4 seconds for each passed month

rtc.adjust(DateTime(realtime));

Then the new month is written in byte 0x0D as e.g. 10000111. Bit 7 is set to 1, to disable this alarm.

Of course, if the RTC is turned on after several months, the appropriate correction will be made, even if passing over the New Year!

Now that we learned to work with the RTC registers, why not check the RTC cell battery status. The excellent engineers who designed PCF8523, allows this test easily, by reading bit 4 of register PCF8523_CONTROL_3. If this is 1, then the battery is low. Consequently, our software will paint in red the background of the battery icon visible on the TFT display and write on the Serial monitor (if connected) the "RTC battery LOW!" message.

We did not activate the alarm registers, since the main board Adafruit Feather 32u4 Basic Proto is powered only occasionally from a LiPo battery. However if the board would be continuously powered, the software allows for an alarm at given HH:MM:SS for a selected duration (s). This information was shown on the display in the initial version also. An external LED is turned on and a small red square appears on the display when the alarm is active. A relay (e.g. https://www.adafruit.com/product/2895 or cheaper equivalents) can be connected in parallel with the LED, for more effects.

Feel free to download the new version of the software, below.