Open rgov opened 9 months ago
I have a CircuitPython branch up here that simply tracks the monotonic timestamp (relative to the MCU clock) for each pulse: https://github.com/rgov/circuitpython/tree/rzg/pps
CircuitPython does not really let us load external modules. There are native compiled .mpy
modules but they're not enabled for the RP2040 port. You also cannot access any functions from the Pico SDK that aren't exposed.
We have two time sources that need to be integrated, the GPS PPS (#3) and RTC SQW (#1).
CircuitPython does not support interrupts except with
countio
. MicroPython does, with caveats. Either way, Python is not spectacular at timing-sensitive tasks.The proposal is to have a C extension that handles interrupts on
GP10
andGP26
and records some kind of monotonic timestamp: see CircuitPythontime.monotonic_ns
, implemented withport_get_raw_ticks
, using the Pico SDKtime_us_64
(though the 32-bit variant is preferable).The delta between subsequent pulses gives us the number of ticks per 1 second (which will likely shift with temperature); we can take a rolling average. When we want to capture an accurate sub-second timestamp, we should use the current monotonic timestamp divided by the ticks per second.
Upon a GPS PPS, we should program the RTC. This will cause a 500ms offset between the GPS PPS and RTC SQW:
Two SQW pulses without an intervening GPS pulse indicates a loss of the GPS signal. In this case we can use the SQW-SQW time deltas rather than GPS-GPS time deltas.
The GPS-SQW time delta can also be measured to try to calibrate the offset.
The MCAP Timestamp data type is a
uint64
of the number of nanoseconds since some epoch.