[time-nuts] Fwd: The amazing $5 timestamper with 6ns resolution (next stop: 184ps)

Jeremy Elson jelson at gmail.com
Tue Feb 16 02:50:03 UTC 2021


I spent this past weekend building a little gadget I'm proud of and wanted
to share.

I use STM32-based microcontrollers for a variety of personal projects, and
realized that I could use one to acquire reasonably high-precision
timestamps. The STM32G431
<https://www.st.com/en/microcontrollers-microprocessors/stm32g4x1.html>,
which costs about $5
<https://www.digikey.com/en/products/detail/stmicroelectronics/STM32G431C6T6/10326704>,
can
run up to 170Mhz and has counters that run at the same speed. It has an
input capture mode that can record counter values at the moment a GPIO
signal goes high. So this weekend I put together all the pieces needed to
do high precision timestamping:

* A Rubidium oscillator I bought on Ebay some time ago (an LPRO-101) with a
diode clamper circuit to shift its voltage up, so it can drive the clock of
the STM32. This serves as the frequency standard for the timestamper. I
configured the STM32's internal PLL to multiply the Rb XO's 10Mhz x17 to
give a 170MHz system clock.
* Software on the STM32 that waits for input capture interrupts, reads the
captured counter value and writes the values over a serial port, where it's
logged on a PC
* A basic Python script that reads the data and does some statistical
analysis and draws graph
* A GPS receiver as a test signal generator -- the STM32 timestamps the PPS
signal coming from the GPS.

The results of an 18-hour run are in the attached graph. The blue points
are the phase error between the Rubidium oscillator and the GPS PPS over
time after some outliers were rejected. The orange line is the linear
regression line, which has a slope (and thus implied frequency error
between Rb and GPS) of about 2e-10. My guess is that my Rubidium oscillator
needs some calibration since I think the performance of these things is
supposed to be closer to 1e-11. I suspect the larger discontinuities (and
the short term frequency error) are the GPS receiver gaining and losing
lock as birds come and go. My GPS receiver does not have a very good sky
view and is single-constellations, so is usually about 30 meters incorrect
about its location. It's actually the GPS inside of Nick Sayer's GPSDO
<https://www.tindie.com/products/nsayer/gps-disciplined-ocxo/>, though in
this case I am just using the PPS output directly from the GPS and not
Nick's conditioned and disciplined 10mhz output.

I've also attached a second graph of a shorter run (tau=3000s) which gives
you a better view of the short-term jitter.

I'm pretty pleased with the results, and all done with a single $5 chip.
RIght now it's just a mess of wires on a breadboard, but I'll probably make
a PCB out of it. With the cost of PCB fabrication and connectors, I suspect
the BOM would still be under $15 even in small quantities, which is
remarkable considering that such a device would have cost tens of thousands
of dollars a few decades ago.

The higher-end, $10 version of this chip -- the STM32G474 -- has a special
high resolution timer that can run at 32x the system clock rate, for an
incredible 184ps resolution. I might try to get that running on some future
weekend; I didn't use it this past weekend because the '431 happened to be
what I had in the house already when I had the idea. Honestly, though,
anything higher resolution will be tougher to test unless I have a more
stable time standard to test against; maybe I should get a second Rb XO.

The firmware
<https://github.com/jelson/rulos/blob/master/src/app/timestamper/timestamper.c>
and graph generator
<https://github.com/jelson/rulos/blob/master/src/app/timestamper/eval.py>
are both available on github. If there's interest, I will probably turn
this into a PCB and make that available too.

Cheers,
-Jeremy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gpsdo-pps-vs-rubidium-feb14.time.plot.png
Type: image/png
Size: 57231 bytes
Desc: not available
URL: <http://febo.com/pipermail/time-nuts_lists.febo.com/attachments/20210215/ed471786/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gpsdo-pps-vs-rubidium-feb15.time.plot.png
Type: image/png
Size: 77327 bytes
Desc: not available
URL: <http://febo.com/pipermail/time-nuts_lists.febo.com/attachments/20210215/ed471786/attachment-0001.png>


More information about the Time-nuts_lists.febo.com mailing list