This may be a super dumb question which is more about clocks rather than the arduino.
For a certain application i need to count seconds aswell as milli seconds.
First i thought i could use a 100hz. Using the clock untouched as milli seconds and then either divide by 10 to obtain the 1 second pulse or just have a counter counting each rising edge of the 100 hz untouched until the count reaches 10 ( then + 1 to seconds count).
Would this be a valid way to do such a task or is using the 100 hz crystal going to give me not true time?
oh, well that kinda owns the situation.
No i haven't looked at a 100hz clock.
How would you obtain milliseconds and seconds from one clock then?
edit, i just realized i am really dumb because i don't want seconds and milliseconds as that follows this "1 second is a 1hz clock then wouldn't milliseconds being second/1000 be 1khz" I want a 1 second clock aswell 1/10th of a second clock Sorry, its getting late :(*
The crystal in real Ardunos are good enough for timekeeping in my experience. Other than that, the classic way of keeping time, is to use a 32.768 khz crystal and feed it through a 15 stage binary counter to get a 1hz signal. As used in millions of digital watches everywhere.......
The other trick is to use the AC power supply to provide a time reference. In the US at least, the "60Hz" of your typical wall outlet is kept VERY accurate over the long term...
My experience with Arduino is that depending on your specific board it may be off to 200ppm. With an oscillator instead of a crystal even more. The question is: do you need high resolution, high precsission or both?
A cheap Chinese knock-off Duemilanove is my least accurate Arduino with a crystal, its OK to within 4 seconds a day (~45 ppm) The one homebrew with a ceramic oscillator I tested gained 15 seconds a day, (~ 170 ppm). My best timekeeping real one (of 4) has gained around 5 seconds in the past month. The real ones crystals are guaranteed better than 100ppm, they are usually much better than that, I always suspected your code Udo....
The other trick is to use the AC power supply to provide a time reference. In the US at least, the "60Hz" of your typical wall outlet is kept VERY accurate over the long term.
Long term being the kicker, they speed and slow the frequency over extended periods to keep a mains synchronous clock accurate to within a few seconds a day, if it gets too fast, they slow it down for a few hours or days and vice versa. In the short term (a few seconds or minutes), it can be off by 0.1 Hz or 1600 ppm.
@Pluggy: I actually bought a DSO, a frequency counter and an efratom time normal (in order to ensure proper overkill ). Conclusion: my code was off by one cycle (=1/16 ppm). The rest was due to the crystal setup. I discussed this with a professional electrical engineer. He explained to me that with the arduino like setup it may be possible to get into the 100ppm range. But this is not at all reliable. The main issues are temperature, voltage and of course aging.
True: the original Arduino did not drift that much at room temperature. However if you need guaranteed timing better than 100ppm, a 100ppm crystal is not at all sufficient. You will need a VXCO, TXCO or something along these lines. It also seems that dedicated time keeping chips (based on 32kHz crystals) offer much better precision than the standard setup and they are comparatively cheap (compared to TXCOs).
There is one more thing I learned by now: crystal oscillators are mechanical devices and thus the frequency may drift in the presence of vibrations as well.
I thought using the 32hz clock and just dividing it down was the normal deal for getting pretty precise time.( getting seconds) but i am looking for milli seconds i wasn't sure.
I agree with Richard Crowley but my questions is what is a good crystal to use to divide down to get Milli seconds without Extreme clock drift?
I will explain the use so that way its easier to understand, although the use of this clock isn't exactly to deal with an arduino.
I have a fan that each rotation outputs a signal ( outputting its square clock pulse). And then i have another clock which is for timing.
The aim is be able to output the Rotations of the fan per second.
I am required to be able to display the number of rotates per second of this fan on 2 segment displays.
from 0.0 to 9.9
So i can gain the 1st digit from the rising edge of the pulse provided from the fan clock. but for the second digit i thought i would use a counter counting 1/10th of a second. ( just going to count milliseconds)