Anchorage, AK
Offline
Sr. Member
Karma: 10
Posts: 492
|
 |
« Reply #18 on: April 05, 2012, 06:36:51 pm » |
I would definitely not use NTP as a replacement for an onboard clock, if what you need is a clock.
With an RTC, you always have a running date/time. It has a coin-cell backup battery to make sure it keeps ticking even when the power's off, or your code locks up, or whatever.
Without the RTC, your code will need to keep track of time somehow. Usually, this is by setting an interrupt timer to fire once a (e.g.) second and increment a seconds-since-epoch counter, or do date math on the fly to increment minutes, hours, days, months, years. The accuracy of this method depends on how reliable that interrupt timer is (which is in turn dependent on the crystal driving the timer -- already covered adequately here), and of course how quickly you can respond to that interrupt and update your time variables.
This is inherently sloppy as compared to a dedicated RTC chip. But, it's plenty good enough for a lot of projects. If your project is reliant on time enough that you're considering either an RTC or NTP, you should probably go with the RTC. If you're already using the Ethernet shield for some other aspect of your project, maybe adding NTP isn't such a big deal, but it's a huge waste if your primary point of network connectivity is to get the time from your network. And less accurate, due to the software clock implementation described above.
Plus, what do you do before NTP is available? Does it matter if the time is not known for some period? What if NTP is down, or the network is misconfigured? NTP doesn't seem too difficult, but it's not exactly trivial. Far easier to query an RTC.
Now, if precision time is essential to your project, maybe it's worth having both the RTC to keep the time consistent, and NTP to keep it accurate.
|