AMPS-N:
Why didn't used DS1307. You get accurate.problem need to use external crystal oscillator. I think it should work with library. Instead of conversion.
JamesCarruthers:
I need accurate time for my project — specifically milliseconds.
...SNIP....
Sorry, but I can't understand your post - even after having a quick look at the DS3231 datahsheet.
I have no idea what you want to achieve or even how you think you might do it.
What is your project?
What amount of error in timing is acceptable? ( +/- how many microseconds or parts-per-million )
AWOL:
I read it as "I want to be able to timestamp to (roughly) millisecond accuracy"
Yup, exactly.
You are still not expressing your requirement clearly.
It sounds like you are content with an accuracy of +/- 1 msec, but you don't say how long that must be maintained for.
If you want accuracy over a longer period than the Arduino can naturally maintain I would read millis() and the RTC periodically and keep a correction factor variable that represents how much has to be added or subtracted to/from the value for millis() to stay in step with the RTC. In other words if I wanted to record the time of an event I would save it as
eventTime = millis() + correction;
Would it not be easier just to read the RTC when the event occurs and ignore millis() altogether?
In the same way I can get seconds() I'd like to be able to get milliseconds()
Accurate as possible within reason.
I'm using them to drive a strip of LEDs — at the moment I'm using only 60 and slight variances are noticeable. It's surprising how the eye can pick up on tiny millisecond differences. So at the moment I only need 1/60 accuracy.
I'd like a solution that is scalable to a large number of LEDs
JamesCarruthers:
I'm using them to drive a strip of LEDs
If you just want to flash LEDs in a pattern and you are driving all the LEDs from a single Arduino then just use millis().
If they are not staying in sync with each other the way you want that is because you are not using millis() properly - not because of a deficiency in millis().
AMPS-N:
Why didn't used DS1307. You get accurate.problem need to use external crystal oscillator. I think it should work with library. Instead of conversion.
I have your library working — many thanks — saved me some time.
I have set my squarewave to 1024Hz — but am unsure how to test it's actually working. I have it attached to a pin and attachInterrupt running a counter function on RISING. But no luck.
JamesCarruthers:
In the same way I can get seconds() I'd like to be able to get milliseconds()
Accurate as possible within reason.
I'm using them to drive a strip of LEDs — at the moment I'm using only 60 and slight variances are noticeable. It's surprising how the eye can pick up on tiny millisecond differences. So at the moment I only need 1/60 accuracy.
I'd like a solution that is scalable to a large number of LEDs
I'm with Robin on this, if your timing errors are noticeable to the human eye, you're probably way beyond millisecond error. What kind of LED strips are these?