25 February 2019

GPS Week Number Roll Over, 2019 edition

I discovered this detail of GPS raw signal in 2010, when my Garmin Geko 201 showed a wrong date. The guys behind GPS (not Garmin) implemented the transmission of a 10-bit weeks counter value that rolled over in 1999, so that some devices began showing a date that was 1024 weeks behind.

It will happen again at the end April 6th, 2019 (UTC).

(Somehow) The week counter has been upgraded to 13-bit, 157 years (but week #0 is still back in 1980-01-06). Probably most devices using GPS location data built in the last 19 years have a software way to handle the rollover, so you will not be affected. Probably. Hopefully. I know too many lazy developers to be 100% sure all my devices will not be affected.

Unless the device is tested with a fake GPS signal ahead in time, all we can do is to wait for the first full weekend of April 2019.

What's worse, the device might have an embedded lookup table "GPS week vs real week" that is 19.5 years long and would roll over any time in the future. And, in most cases, all these devices are unlikely to get a firmware update.

See you in week #0 :)

15 February 2019

Weird behavior of ZS-042 RTC modules (DS3231)

First of all: all these ZS-042 RTC modules were paid about 1 USD each and come from not-certified sources. 

One night I decided to measure the 32K output of some DS3231 ZS-042 RTC modules. I wanted to see what difference would make if I retouched the aging register. This experiment lead to few unexpected discoveries.

1) Maxim DS3231 datasheet mentions 32K output and 32.768 kHz interchangeably. Alright, it is a digital device, so 32K equals 32768 if K=1024 as used for bytes. But we are talking of Hz, not bytes, so I think should be K=1000. Proof? Search for "768" in the datasheet.

2) There are two quite different devices that share 6 characters of the part name - DS3231 - and are distinguished by their suffix: M or SN. The former "M" is 5 ppm with MEMS resonator, while the latter "SN" is 2 ppm with TCXO. In simple terms, "SN" is better than "M". But you can't choose when buying ZS-042 modules and you will receive either model

"M", "SN", "M":notice the deeper blue PCB of "SN"
3) All my ZS-042 modules with DS3231M output a frequency close to 32.700 kHz, while those with DS3231SN are close to 32.768 kHz. The "M" would be loosing 180 seconds/day, 1.5 h/month, but none of them does! Actually I have one DS3231M in my longest running Nixie clock and it is within 5 ppm specification.

Measuring "32K" output of DS3231M.
So, let's forget DS3231SN that are most likely second-hand/pulls but legit. How can a DS3231M that outputs 32700 Hz be so accurate as I observed? If it is genuine, Maxim has a way to calibrate the chip once, before it is sold. If it is a fake, then it is microcontroller with proper firmware and calibration to count the correct number of interrupts. I could sacrifice one and decap it, but then I lack the microscope to examine the silicon die.

Conclusion. Buy the DS3231SN if you need an interrupt rate of 32768 Hz. Otherwise for hobbyist use, they are both worth it.

02 February 2019

Timebase for homemade clocks, 1 pps

I am currently into a minimalist approach to building (Nixie) clocks that does not include a user interface. The are several reasons, like simpler and less buggy firmware, straightforward user interaction, less hardware, fewer holes to drill in the case. Since these are one-offs "products" without commercial intents, I can afford it.

I am after a simple way to get an accurate 1 pps or integer fractions of it so that the microprocessor can count the elapsed time.

The most elegant way would be to clock the AVR microprocessor with a purposely chosen XTAL, feed that timebase into a divider and use it as timekeeping interrupts. I've got plenty of 11059200 Hz crystals, but they don't divide well into suitable interrupt counts.

Another way is to take advantage of the AC line at 50 (60) Hz, but that means a special power supply (AC-AC) and additional circuitry to get DC voltage for the logic and the booster in case of Nixies. No, I don't want to use the direct-AC method!

How about a watch crystal at 32768 kHz and a 4060 divider? That would work, indeed.

But when you take into account both the additional wiring and the cost of each of these solutions, it turns out that modern RTC chips (at 1 USD shipped, already on breakout boards) are equally cheap, maybe even less complex to wire, output a 1 pps signal and offer greater upgrade possibilities if you ever want to, like battery/supercap backup, date, power loss warning. And their SOIC package is probably not too difficult to hand-solder either.

By the way, how to set the time on a interface-less clock? Well, it always starts at an agreed time, and you simply have to plug it in at that time. We are surrounded by clocks and "my" device doesn't aim at being the time reference standard.