Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

I'm working on a school project where I need to synchronize the clock on two Arduinos to almost perfect timing. I liked the idea of using Bluetooth but it has certain drifts/delays in timing. I was thinking of using a direct connection between the two boards when initiating and then disconnecting when in sync. Will the Arduinos keep "perfect" timing for a long period of time? Will this do the trick or are there better solutions?

I'm not restricted to using an Arduino. I need a latency of less than 20 milliseconds.

share|improve this question

2 Answers 2

"NTP can usually maintain time to within tens of milliseconds over the public Internet, and can achieve 1 millisecond accuracy in local area networks under ideal conditions"

For example: Arduino UdpNtpClient - though this isn't a full NTP client and doesn't maintain accurate time continuously (unlike a normal NTP client)

Network latency isn't a problem, jitter may be. NTP requires the systems be able to communicate at regular intervals and requires time to settle on accurate values.

share|improve this answer

To answer the question of accuracy while disconnected a typical crystal may have an accuracy of say 50ppm which equates to around 4.3 seconds of error over a day or about 180ms per hour so it could exceed your 20ms limit in under 10 minutes. A lot of the error depends on temperature and the age of the crystal so you probably could calibrate it to get much better results, but if you're talking about extended amounts of time and your temperature will vary quite a bit it may not be practical.

Now that GPS modules are so cheap that's worth looking into as an accurate time source assuming your application has a relatively clear view of the sky or you can run an antenna. Technically the GPS system is accurate to somewhere around 20ns, but most receivers I've seen with an external PPS (pulse per second) output claim an accuracy of 1ms or less.

For that to work normally you'll want a UART port to read the NMEA output from GPS that includes the UTC date and time and connect the PPS output to an interrupt line. You'll need to check the datasheet for the specific GPS module but most seem to pulse the PPS line and the NMEA sentence that follows includes the time that pulse related to, so a method I've used is when the interrupt occurs is to set the time to previous time received plus one second (because the last NMEA data is now one second old) and use that to calibrate the free-running timer.

share|improve this answer
    
As a cheaper alternative to a GPS shield/module - consider a RTC (example sparkfun.com/products/99 ) like the DS1307. Reasonably accurate you can sync once a day or more often, keeps time even when the MPU power fails, easy to program and read, and really small so it shouldn't get in the way. –  Ron J. Jun 26 '13 at 13:11
    
@RonJ. fairly reasonable idea although most watch crystals are still only about 20ppm so it would only be 2.5 more accurate than the above figures, so you'd still only be looking at about 30 minutes or so before it could drift outside 20ms. They tend to be more stable in wristwatches because the human body regulates the temperature while worn and when not most people don't leave them in extreme cold / heat. –  PeterJ Jun 26 '13 at 13:24
    
@PeterJ. To be more precise, my goal is to start playing an mp3 file from different location at precisely an specific time using an app. GPS is too expensive. Reconnecting the boards with a direct wire every time the clock is out of sync seems too tiresome. I'm thinking of going back to a direct Bluetooth connection between boards, in order to keep in sync. Is there hope? –  JJC Jun 26 '13 at 13:43
    
@JJC, if Bluetooth is in range it might be a good solution. I've never done enough with BT to know what latency is like but along the lines RedGrittyBrick suggested maybe you can make an NTP like protocol that does a few 'pings' and measure latency to compensate, but jitter could be a problem but I would think would be OK between two BT devices. –  PeterJ Jun 26 '13 at 13:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.