Stopwatch using millis() accuracy.

Hi All, I'm reading a lot these days, and i've some questions, but first let me explain my project.

I'll have a Start button that will start the StopWatch, after that when i touch a pad, the arduino needs to write to the serial port the elapse time, after that when someone press the stop button the stopwatch stops.

So the flow is simple i guess, the trick is, i need millisecond precision on the touch, so i read a lot about it, and everyone said that the millis() function is accurate but it loses some seconds a day, for me its not problem, but is possible to "synchronize" the function to not get the "wrong time" during the course of the start of the stopwatch? ( The stopwatch will be started in the max for 1 hour) but we could also "correct" the time at the end of every stop from the stopwatch.

If i was not clear please tell me, i'll elaborate better.

Basicly i need to know if someone touchpad the pad after 01:30.254 (minutes:seconds.milliseconds).

Thanks!

A human won't be able to press a switch or touchpad with millisecond accuracy. Unless you have more precise input (light barrier...), such an accurate display is cheating.

I don't think you can use anything homemade for official sanctioned sporting events.

But for unofficial use over an hour time period, the Arduino should be accurate enough.

And for example, assuming you are timing a race - If there's a 1 percent timing error (it shouldn't really be that bad), that could be significant over a 1 hour period, but if there's a 100 millisecond difference between 1st place and 2nd place, 1% of 100 milliseconds in not so significant.

You'll probably need to use an interrupt to make sure you "snap" the time exactly when you touch the pad. (It takes some time to run a loop and the more things your program is doing, the more delay there will be before you read the touch-pad.)

for me its not problem, but is possible to "synchronize" the function to not get the "wrong time" during the course of the start of the stopwatch?

Probably not a good idea. Over a long period of time it would be OK, but if you "capture" one event, then adjust the time and then capture another event a short time later, you could introduce a greater error. by changing the time in the middle of a measurement.... Let's say you're running 1 minute slow every hour. Then you measure a 5-minute event and there's a 1-minute "correction" in the middle of the 5-minute measurement... That would really mess you up!

And, wat would you synchronize it to? If you've got a more accurate clock/timer, use that timer/clock instead of the Arduino's built-in oscillator with millis(). :wink:

How do you mean "wrong time"?

What does this statement mean?

we could also "correct" the time at the end of every stop from the stopwatch.

What are you correcting it to?

MorganS:
How do you mean "wrong time"?

What does this statement mean?What are you correcting it to?

In everything i read is was said that millis() is not 1ms its like 1024us so the 16mhz crystal will input a difference along the day. And i was said that difference could be "corrected".

DrDiettrich:
A human won't be able to press a switch or touchpad with millisecond accuracy. Unless you have more precise input (light barrier...), such an accurate display is cheating.

I need the precision time in milliseconds from the touch. I mean, i press start, after a X time you touch a pad, i need the time with milliseconds elapsed from the start.

DVDdoug:
I don't think you can use anything homemade for official sanctioned sporting events.

But for unofficial use over an hour time period, the Arduino should be accurate enough.

And for example, assuming you are timing a race - If there's a 1 percent timing error (it shouldn't really be that bad), that could be significant over a 1 hour period, but if there's a 100 millisecond difference between 1st place and 2nd place, 1% of 100 milliseconds in not so significant.

You'll probably need to use an interrupt to make sure you "snap" the time exactly when you touch the pad. (It takes some time to run a loop and the more things your program is doing, the more delay there will be before you read the touch-pad.)
Probably not a good idea. Over a long period of time it would be OK, but if you "capture" one event, then adjust the time and then capture another event a short time later, you could introduce a greater error. by changing the time in the middle of a measurement.... Let's say you're running 1 minute slow every hour. Then you measure a 5-minute event and there's a 1-minute "correction" in the middle of the 5-minute measurement... That would really mess you up!

And, wat would you synchronize it to? If you've got a more accurate clock/timer, use that timer/clock instead of the Arduino's built-in oscillator with millis(). :wink:

It just for study the example, we'll build a prototype for demonstration only, but a simulation from a real competition.

I said about the "correction" to be only after the stop, of at the start, let say, i press start, the arduino code "corrects" the millis() time, and store the new value and use it for the race, for a period like 5 minutes its probably ok right?

No need to touch the internal clock. Remember the start time, in milliseconds, and subtract it from every other millisecond value read during the race, to get the elapsed time.