Close

Firmware update

A project log for GPS Disciplined xCXO

A DIY GPS disciplined 10 MHz reference clock

nick-sayerNick Sayer 01/13/2016 at 15:450 Comments

If you've got one of these GPSDOs, there's a bug fix in the firmware on github that you probably want to take.

The issue is that if the input capture (of the PPS edge) takes place exactly as the timer overflows (goes from 0xffff to 0), then both of those interrupts happen simultaneously. The input capture interrupt has priority, which means that the overflow is deferred until the input capture ISR finishes.

The purpose of the overflow interrupt is to increment the high bits of the timer value, allowing us to track 32 bits of time instead of the 16 bits supported by the hardware. But if the overflow interrupt doesn't happen when it should, then when you sample the value, it will be 65,536 counts too low.

What this means in practice is that once in a while - every month or so, maybe - your GPSDO will lose its mind - it will shoot way high in frequency to compensate for a phantom period of being way too "slow." That will start a slow, damping sine wave frequency modulation that will last an hour or two. In the meantime, the LED indications will show no lock.

The workaround is to check in the input capture ISR to see if the overflow interrupt flag is set. If it is, and if the captured value is "low," then that means that an overflow interrupt is pending and we should add 65,536 to the count. If the captured value is "high," then that likely means that there's a race condition at play and that the timer overflowed after the capture, but before we just checked it. In that case, we should not add any compensation.

In actual fact, it's quite likely that this happens only when the captured value is exactly zero. If it were 1, then the overflow interrupt would have happened first and deferred the capture interrupt (but the value would have been captured, so the delay is not critical). The timer overflow flag would not be set and life goes on as before. If it were 0xffff, then the input capture interrupt would have happened first. In that case, the workaround code will likely see the overflow flag set, as the timer would have overflowed very shortly after the capture. But the captured value will be seen as "high," and no compensation added, which is correct. The workaround code decides "high" or "low" simply by comparing to 0x8000, which is good enough, as this will only be a factor when the counter is very, very close to zero.

To update the firmware, you need an AVR programmer and a pogo pin programming adapter. Your AVR programmer should be configured to be target powered, and you should power the GPSDO from its own power supply during programming.

Discussions