millisecond precision from Teensy 3* RTC

Status
Not open for further replies.

manitou

Senior Member+
From this discussion, https://community.nxp.com/thread/378715, I learned you can get 1/32768 second precision from the teeny 3* RTC. Here is a simple demo of combining RTC_TPR with RTC_TSR to get RTC millis
https://github.com/manitou48/teensy3/blob/master/RTCms.ino

The actual accuracy of the RTC time and frequency is another matter. ;)

Some anecdotal frequency accuracy data (ppm) for various MCUs:
https://github.com/manitou48/crystals/blob/master/crystals.txt

I don't yet know the specs/part for the T3.5/3.6 crystals.

Teensy Time library
 
Thanks, this is great. Any idea how to _set_ the RTC with ms accuracy?

The teensy time library link above has various methods of setting time. Using serial/usb link to host computer, you can get sub-second accuracy, especially if you measure what the serial delay is. Using GPS with pps is probably the best. BUT keeping an accurate time requires adjusting the RTC crystal frequency, maybe with an NTP-like protocol. Crystal frequency can change with voltage, capacitance, age, and temperature. here is info on freq vs temperature,
https://forum.pjrc.com/threads/24628-Interesting-Temperature-Data
The teensy RTC has compensation logic to adjust the frequency.
Buying a temperature-compensated RTC and coin-cell battery might be another solution.
 
Maybe I'm missing something, but the Time library deals only with second-level accuracy, as does Teensy3Clock.set(). With an accurate external clock (NTP, say) it would be great to resync the RTC with fractional seconds. I don't see how to set the RTC without losing fractional second time.

Even with significant drift over time, having sub-second resolution from the RTC is useful for things like sweep-second hands on graphical clocks.

I've built a C++ library on top of Time (https://github.com/blackketter/Clock) that does its best to calculate subsecond time using millis() and the RTC, but it would be preferable take advantage of the rtc hardware directly.

The teensy time library link above has various methods of setting time. Using serial/usb link to host computer, you can get sub-second accuracy, especially if you measure what the serial delay is. Using GPS with pps is probably the best. BUT keeping an accurate time requires adjusting the RTC crystal frequency, maybe with an NTP-like protocol. Crystal frequency can change with voltage, capacitance, age, and temperature. here is info on freq vs temperature,
https://forum.pjrc.com/threads/24628-Interesting-Temperature-Data
The teensy RTC has compensation logic to adjust the frequency.
Buying a temperature-compensated RTC and coin-cell battery might be another solution.
 
I haven't tried it, but you would need your own set_time() function that sets both RTC_TSR and RTC_TPR. If host sends you time "on the second", then at 9600 baud it would take 10 or so milliseconds for character data to arrive, so you'd need to adjust TPR. If it turns out you can't set TPR, then you could wait 990ms before setting time to sec+1. there may be other ways ...
 
Sorry to bring up this old thread, but i have a little confusion on the original sketch and the resulting output on the Serial Monitor. Can you explain a little bit more about exactly how this works?
 
Status
Not open for further replies.
Back
Top