TeamSunride / MRAS

Multi Rocket Avionics System
https://mras.sunride.space/
GNU General Public License v3.0
6 stars 0 forks source link

Get reliable timestamp in milliseconds from 1/1/1970 with Teensy RTC #5

Closed TomD53 closed 2 years ago

TomD53 commented 2 years ago

https://forum.pjrc.com/threads/68062-Teensy-4-1-RTC-get-milliseconds-correctly

The above forum thread describes a method of getting a timestamp in milliseconds. Please write a function for this and place it in the lib folder. Then write a unit test for the function and place it in the test folder.

The docs for unit testing in PIO are here, if you need help please message me on discord https://docs.platformio.org/en/stable/plus/unit-testing.html

TomD53 commented 2 years ago

More helpful resources:

https://forum.pjrc.com/threads/61665-RTC-Registers-and-Millisecond-Precision-from-Teensy-4-0

Page 1242 of IMXRT1060 manual https://www.pjrc.com/teensy/IMXRT1060RM_rev2.pdf

Ash2772 commented 2 years ago

Added rtc function in commit 1bb59a4dd402891d981d63303eafd27b0c87d70b

TomD53 commented 2 years ago

I've added some more tests in 5199a3e, 855f560 and d4da455.

The test now compares RTC time to compiler time to verify that the sync worked properly.

TomD53 commented 2 years ago

I don't believe it was actually using the Teensy RTC to sync the time; I left it running for an hour or two and there was some drift. Should be fixed in 7749812.

Based on this example code

The default interval for re-syncing the time is 5 minutes but can be changed by calling the setSyncInterval(interval) method to set the number of seconds between re-sync attempts.