Skip to content

Commit d0f464d

Browse files
committed
Fix bug in GPS_Tbase.get_t_split.
1 parent bdff299 commit d0f464d

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

gps/README.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -811,11 +811,15 @@ These tests allow NMEA parsing to be verified in the absence of GPS hardware:
811811

812812
# 7. Notes on timing
813813

814-
At the default baudrate of 9600 I measured a transmission time of 400ms when a
815-
set of GPSV messages came in. This time could be longer depending on data. So
816-
if an update rate higher than the default 1 second is to be used, either the
817-
baudrate should be increased or satellite information messages should be
818-
disabled.
814+
At the default 1s update rate the GPS hardware emits a PPS pulse followed by a
815+
set of messages. It then remains silent until the next PPS. At the default
816+
baudrate of 9600 the UART continued receiving data for 400ms when a set of GPSV
817+
messages came in. This time could be longer depending on data. So if an update
818+
rate higher than the default 1 second is to be used, either the baudrate should
819+
be increased or satellite information messages should be disabled.
820+
821+
The accuracy of the timing drivers may be degraded if a PPS pulse arrives while
822+
the UART is still receiving. The update rate should be chosen to avoid this.
819823

820824
The PPS signal on the MTK3339 occurs only when a fix has been achieved. The
821825
leading edge occurs on a 1s boundary with high absolute accuracy. It therefore
@@ -854,26 +858,27 @@ Sources of variable error:
854858
* Inaccuracy in the `ticks_us` timer (significant over 1 second).
855859

856860
With correct usage when the PPS interrupt occurs the UART will not be receiving
857-
data (this can affect ISR latency). Consequently, on the Pyboard, variations in
858-
interrupt latency are small. Using an osciloscope a normal latency of 15μs was
859-
measured with the `time` test in `as_GPS_time.py` running. The maximum observed
860-
was 17μs.
861+
data (this can substantially affect ISR latency variability). Consequently, on
862+
the Pyboard, variations in interrupt latency are small. Using an osciloscope a
863+
normal latency of 15μs was measured with the `time` test in `as_GPS_time.py`
864+
running. The maximum observed was 17μs.
861865

862866
The test program `as_GPS_time.py` has a test `usecs` which aims to assess the
863867
sources of variable error. Over a period it repeatedly uses `ticks_us` to
864868
measure the time between PPS pulses. Given that the actual time is effectively
865869
constant the measurement is of error relative to the expected value of 1s. At
866-
the end of the measurement period it calculates some simple statistics on the
867-
results. On targets other than a 168MHz Pyboard this may be run to estimate
870+
the end of the measurement period the test calculates some simple statistics on
871+
the results. On targets other than a 168MHz Pyboard this may be run to estimate
868872
overheads.
869873

870-
Assuming the timing function has a similar latency to the ISR there is likely
871-
to be a 30μs lag coupled with ~+-35μs (SD) jitter largely caused by inaccuracy
872-
of `ticks_us` over a 1 second period. Note that I have halved the jitter time
873-
on the basis that the timing method is called asynchronously to PPS: the
874-
interval will centre on 0.5s. The assumption is that inaccuracy in the
875-
`ticks_us` timer measured in μs is proportional to the duration over which it
876-
is measured.
874+
The timing method `get_t_split` measures the time when it is called, which it
875+
records as quickly as possible. Assuming this has a similar latency to the ISR
876+
there is likely to be a 30μs lag coupled with ~+-35μs (SD) jitter largely
877+
caused by inaccuracy of `ticks_us` over a 1 second period. Note that I have
878+
halved the jitter time on the basis that the timing method is called
879+
asynchronously to PPS: the interval will centre on 0.5s. The assumption is that
880+
inaccuracy in the `ticks_us` timer measured in μs is proportional to the
881+
duration over which it is measured.
877882

878883
[MicroPython]:https://micropython.org/
879884
[frozen module]:https://learn.adafruit.com/micropython-basics-loading-modules/frozen-modules

gps/as_tGPS.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def get_t_split(self):
211211
t = self.secs
212212
acquired = self.acquired
213213
machine.enable_irq(state)
214-
x, secs = divmod(secs, 60)
214+
x, secs = divmod(t, 60)
215215
hrs, mins = divmod(x, 60)
216216
dt = utime.ticks_diff(utime.ticks_us(), acquired) # μs to time now
217217
ds, us = divmod(dt, 1000000)

0 commit comments

Comments
 (0)