YOu can assume that you will never get code that works with delays this short to ever work
reliably on any operating system other than a real-time operating system. The chances you
will ever get user-level code like this to work on WIndows, Unix, Linux, Mac OS X, or
Solaris is so vanishingly small as to not even be worthy of discussion.
I was trying to use a system, laughably called "Real-time Unix", some years ago. It had a
10ms timer. The only problem with this was that it was two orders of magnitude slower
than our application required.
The key here is "reliably". If your app fails if the delay is longer than 2ms, give up.
You have an unsolvable problem in general-purpose operating systems. If you can
occasionally stand a delay, the multimedia timers will work sort-of-pretty-reliably.
Note that if you need resolution to 1ms, you have to have a system capable of giving you
events at no less than 1/2ms, and preferrably at 1/4ms. Your error rate will be one or
two intervals, so a 1ms timer will not really give you maximum reliability for a 2ms
interval because you might get 2ms, or you might get 3ms. The phenomenon, well known to
people who deal with physical systems, is called "gating error" and was understood back in
the 1940s, at least (I have not researched it earlier than that, because that was the
first time digital circuits could actually be used in measurement equipment). So the
induced error is one or two ticks depending on gating error on front and back sampling, so
to get reliably 2ms, you should have a system that can resolve events to 500us. Not going
to happen on Windows as it is currently set up.
Please explain why you need such tiny intervals.
joe
Post by EdLARGE_INTEGER startc;
LARGE_INTEGER endc;
LONGLONG diff;
QueryPerformanceCounter(&startc);
QueryPerformanceCounter(&endc);
diff = endc.QuadPart - startc.QuadPart;
if (diff < 5000)
goto loop;
I know that this will not be the case on all PC's and OS's.
How can I calibrate it to allways give the same time delay (about 2ms)?
Thanks
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm