Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've got a multimedia timer based on a Code project article and the code here and it seems to work pretty great.

The problem I'm having is that over time it seems to drift slightly and I would like to figure out a way to get things back on track.

I tried stopping the timer, sleeping for an adjustment period, and then starting the timer ... but that seemed to create more problems than it solved ... especially since the "start time" was set when the form loaded and that seems to be substantially different from 1 timer tick after the timer starts ... so I don't seem to be able to use the start time based on when I start the timer (probably due to the amount of code to get things registered etc).

Any thoughts on how I can account for drift ... I'm trying to keep my application fairly stable to an accuracy of 100ths of a second ... and in general it's keeping to that ... it's just the drift that's the problem.

Thanks in advance for any thoughts or suggestions.
Posted
Updated 15-Sep-11 10:56am
v2
Comments
Sergey Alexandrovich Kryukov 16-Sep-11 17:25pm    
It highly depends on the problem you're trying to solve.
--SA
BHort 19-Sep-11 10:05am    
I'm trying to implement a time correction algorithm to ensure my application timer stays closer to the original intended time. Basically to remove or at least adjust for the drift as it happens.
BHort 5-Oct-11 18:21pm    
In doing further development I've discovered that the multimedia timer is pretty accurate. It stays within a few microseconds of accurate without needing any help. When it does drift slightly ... if it's going too fast, I quickly stop and start it again ... and that seems to pull it back on track and/or keep it from straying too far. I do this whenever the timer is > 3 microseconds off. If it's going too slowly I haven't found a great solution other than to add in a "fake" extra tick (equal to 1/100th of a second for my application). I only do this when the error is > 8 microseconds because the impact is bigger but the result is that the timer is staying very true over an extended period with these correction measures.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900