Measuring time accurately

• 04-25-2012
sigur47
Measuring time accurately
I am working on a project and i am trying to work this out.I have an event that occurs every 16.12356 milliseconds.The problem i have is that i need to use that time to count up to 1 second . so it takes 16.12356 * 62.0210425 to reach a second.The problem is how to measure the .0210425 because i can only measure my timw in whole numbers
• 04-25-2012
Salem
Well which OS/Compiler are you using?
• 04-26-2012
brewbuck
If the timer granularity does not divide evenly into one second, then you can't use such a timer to precisely count one second. That's just a mathematical fact.

However, if you are counting seconds over time (i.e. you want to trigger some event every second), it is possible to avoid accumulation of error. Although each specific timeout will not occur exactly on the second, it won't "drift" over time, so long as you are careful about it.
• 04-26-2012
oogabooga
Quote:

Originally Posted by brewbuck
If the timer granularity does not divide evenly into one second, then you can't use such a timer to precisely count one second. That's just a mathematical fact.

However, if you are counting seconds over time (i.e. you want to trigger some event every second), it is possible to avoid accumulation of error. Although each specific timeout will not occur exactly on the second, it won't "drift" over time, so long as you are careful about it.

That's a good point. So you'd be off, on average, by about half the granularity.