Link to home
Start Free TrialLog in
Avatar of iasso
iasso

asked on

Sub-millisecond Timing in Windows 95

Using Visual C++ in Windows 95,  I am trying to have an event occur exactly every 1 millisecond.  I would acctually like it to occur every 500 microseconds but I don't think I can get that kind of resultion.  The MMTIMER is supposed to support 1ms time intervals, but by events occur later and it is not very precise(running on a P-200).  Is this a possible task??  Can I get events to precisly occur this quickly??
Avatar of alexo
alexo
Flag of Antarctica image

First of all, please keep in mind that Win95 is NOT a real-time OS.  Not even remotely.  There is no way to guarentee EXACT timing in your app.  Your threads may be preempted by other apps or the system; interrupts may occur; etc...

With that in mind, the best resolusion is obtained using multimedia timers.  Check the timeSetEvent() function.
Avatar of iasso
iasso

ASKER

I know that the multimedia timers give you the best resultion.  My problem is that the resution they give is not good enough.  I'm asking if it is possible.  I know it is not possible using the standard MFC.  Can code be written below the OS level??  Or perhaps if you thunk a 16-bit code appltication you can get better resution than the multimedia timer provide.  I'm not sure how the Win 95 event handling works.  I know when some games load, Alt-tab and other WIN 95 functions do not work.  This is done to increase performance.  Is there a way to give a specific event greater priority??
A specific event, I am not sure of, but processes and threads can be given higher priorities than other processes/threads(or lower) so that they get a bigger slice of the CPU time, so I guess you could probably put this specific task in its own thread, pump its thread priority to the highest, and give its process a slightly raised priority(unless you think its really mission critical, then you could really boost that up too) and get a bit better timing.
ASKER CERTIFIED SOLUTION
Avatar of RONSLOW
RONSLOW

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The August 96 Windows Developers Journal has an article and source code on "A More Accurate Timing Tool"

You can get the source code (not sure about the article) from http://www.wdj.com

The code is assembler.


Look at QueryPerformanceCounter and QueryPerformanceResolution

The docs say ...

>>>>>>>>
High-Resolution Timer

A counter is a general term used in programming to refer to an incrementing variable. Some systems include a high-resolution performance counter that provides high-resolution elapsed times.

If a high-resolution performance counter exists on the system, the QueryPerformanceFrequency function can be used to express the frequency, in counts per second. The value of the count is processor dependent. On some processors, for example, the count might be the cycle rate of the processor clock.

The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter (if one exists on the system). By calling this function at the beginning and end of a section of code, an application essentially uses the counter as a high-resolution timer. For example, suppose that QueryPerformanceFrequency indicates that the frequency of the high-resolution performance counter is 50,000 counts per second. If the application calls QueryPerformanceCounter immediately before and immediately after the section of code to be timed, the counter values might be 1500 counts and 3500 counts, respectively. These values would indicate that .04 seconds (2000 counts) elapsed while the code executed.
>>>>>>>>

But as said before, if you need accurate timing, then it is best to do time-critical code in a VxD where you have some (better) control over your interrupts.

From a VxD you can call certainly call Get_System_Time (but that is only to the millisecond) .. I am not sure what other timers are or are not available in a VxD (I only have one that required millsecond timing, so Get_System_Time is ok).

Also ,check out www.snippets.org and look for uclock.c which does micro-second timings.