Skip to content

Commit e28603b

Browse files
committed
Prior to branch
1 parent ab243d0 commit e28603b

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

gps/as_GPS.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def speed_string(self, unit=KPH):
649649

650650
def time(self, local=True):
651651
t = self.local_time if local else self.utc
652-
return '{:02d}:{:02d}:{:2.3f}'.format(*t)
652+
return '{:02d}:{:02d}:{:06.3f}'.format(*t)
653653

654654
def date_string(self, formatting=MDY):
655655
day, month, year = self.date

gps/as_GPS_time.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
import as_GPS
1111
import as_tGPS
1212

13+
print('Available tests:')
14+
print('calibrate(minutes=5) Set and calibrate the RTC.')
15+
print('drift(minutes=5) Repeatedly print the difference between RTC and GPS time.')
16+
1317
# Setup for tests. Red LED toggles on fix, blue on PPS interrupt.
1418
async def setup():
1519
red = pyb.LED(1)
@@ -20,13 +24,20 @@ async def setup():
2024
pps_pin = pyb.Pin('X3', pyb.Pin.IN)
2125
return as_tGPS.GPS_Timer(gps, pps_pin, blue)
2226

23-
async def drift_test(gps_tim, minutes):
24-
for _ in range(minutes):
25-
for _ in range(6):
26-
dt = await gps_tim.delta()
27-
print(gps_tim.get_t_split(), end='')
28-
print('Delta {}'.format(dt))
29-
await asyncio.sleep(10)
27+
running = True
28+
29+
async def killer(minutes):
30+
global running
31+
await asyncio.sleep(minutes * 60)
32+
running = False
33+
34+
async def drift_test(gps_tim):
35+
dstart = await gps_tim.delta()
36+
while running:
37+
dt = await gps_tim.delta()
38+
print('{} Delta {}μs'.format(gps_tim.gps.time(), dt))
39+
await asyncio.sleep(10)
40+
return dt - dstart
3041

3142
# Calibrate and set the Pyboard RTC
3243
async def do_cal(minutes):
@@ -39,9 +50,19 @@ def calibrate(minutes=5):
3950

4051
# Every 10s print the difference between GPS time and RTC time
4152
async def do_drift(minutes):
53+
print('Setting up GPS.')
4254
gps_tim = await setup()
43-
await drift_test(gps_tim, minutes)
55+
print('Waiting for time data.')
56+
await gps_tim.ready()
57+
print('Setting RTC.')
58+
await gps_tim.set_rtc()
59+
print('Measuring drift.')
60+
change = await drift_test(gps_tim)
61+
print('Rate of change {}μs/hr'.format(int(60 * change/minutes)))
4462

4563
def drift(minutes=5):
64+
global running
65+
running = True
4666
loop = asyncio.get_event_loop()
67+
loop.create_task(killer(minutes))
4768
loop.run_until_complete(do_drift(minutes))

0 commit comments

Comments
 (0)