aws / amazon-freertos

DEPRECATED - See README.md
https://aws.amazon.com/freertos/
MIT License
2.54k stars 1.1k forks source link

[General] Nanosecond-level Clock Synchronization #3480

Closed sumanclimote closed 2 years ago

sumanclimote commented 2 years ago

Briefly summarize the issue being raised How can we archive a micro/Nano second level time synchronization between edge computer and AWS server.

Describe the desired outcome How Synchronization time to a nano seconds accuracy between the edge device ? I want to detect an even at different edge devices and get the time difference between them at a nano seconds. How can we handle the RTC clock drift between the edge devices and resynch them to a master clock (AWS/NPT)

System information

Hardware board: STM32L496VGTX based custom board IDE used: VS code Operating System: Linux on VM Code version: 202107.00-58-g5adbe3026 and 202108.00-37-g5da3a389 Project/Demo: custom application

References Just a talk on this topic, but am expecting an AWS solution for this?
https://youtu.be/Opf9CBwP5R8

Code/Steps to reproduce the current status N/A

Additional context N/A

archigup commented 2 years ago

Hi, for time synchronization with the SNTP protocol, we provide the coreSNTP library here: https://github.com/FreeRTOS/coreSNTP

sumanclimote commented 2 years ago

@archigup thanks for sharing the SNTP server, will that be able to synch all edge devices to a nano [or milli] second accuracy considering all the network constrains ?

kstribrnAmzn commented 2 years ago

@sumanclimote coreSNTP (and any Network Time Protocol) will fail to meet your requirement of nanosecond accuracy. While coreSNTP does output a time value with enough precision to answer in nanoseconds (see RFC 4330 pg 7 - which coreSNTP adheres to), ultimately network latencies can and will introduce both some clock jitter and skew which roughly leaves the accuracy valid only to milliseconds. The general consensus seems to be to expect no better than millisecond accuracy from any NTP.

PTP, or the Precision Time Protocol, was created to offer sub-millisecond accuracy. There appear to be a number of implementations - maybe one has been ported to an RTOS.

Now if you need millisecond precision, which sounded like it may work for your post, coreSNTP would be a great place to start; however, the time accuracy is in part determined by the network (latency, reliability, etc) so you may need to do some testing of your own to determine the actual clock accuracy.

sumanclimote commented 2 years ago

thanks for sharing this info.