Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BIOS Timer and Counter puzzle

0 views
Skip to first unread message

Jami Bradley

unread,
Apr 27, 1995, 3:00:00 AM4/27/95
to
I've been working on a small utility to time functions for me in windows.
Coming from a real-time programming world, I wanted high-resolution, accurate
timing. I thought I would just grab the current timer (18 mSec resolution),
and combine it with the counter value to get timing down to about 0.8 uSec.
Unfortunately, windows (as usual) is giving me a really bizarre effect. I
wrote a small DLL to get both values, then I called it 30000 times and recorded
the values. What I noticed is that the tick (at 0040:006C) was changing in the
middle of the count. Now I assume there is some latency, but this was
drifting!!! It would change when the counter was at 1000, and the next tick
the counter would be at 2000, etc. until the tick was changing when the counter
was at 64000! Then the crazy tick wouldn't update for almost 110 mSec, and
would start this cycle over. Fortunately, the correction at the end does make
the system tick, *on average*, occur every 55 mSec. But the real values show
that is running about 54 mSec most of the time, with an occasional 109 mSec!

In the MS-DOS world, I took the same function and checked it, and it worked
beautifully. The only time the tick changed was when the counter wrapped. In
DOS, I can do this without any problem.

Obviously, with the tick out of sync with the counter like this, timing is worthless! Can any windows wizard out there explain why this would happen? I would love to fix this, and get good timing.

Much thanks for any help with this bizarre problem!

Jami Bradley
Intelligent Energy Corporation
Bra...@Colorado.edu

Mike Uchima

unread,
Apr 27, 1995, 3:00:00 AM4/27/95
to
In article <BRADLEY.95...@csf.colorado.edu>, bra...@csf.colorado.edu (Jami Bradley) writes:
|> [discussion of timer problems snipped]

|>
|> Obviously, with the tick out of sync with the counter like this, timing is
|> worthless! Can any windows wizard out there explain why this would
|> happen? I would love to fix this, and get good timing.
|>
|> Much thanks for any help with this bizarre problem!

I think the problem is that Windows is "virtualizing" the timer chip. So
you're not reading the "real" timer chip registers -- rather, you're
reading a software emulation of the timer chip. I seem to recall running
into a related problem a couple of years ago, in that Windows is actually
emulating the older timer chip (I forget the part #) that was in the original
IBM PC, not the (more capable) timer chip used in everything since the
PC AT. So some of the hardware functions available on the timer chip are
actually being hidden as well.

I think there's a setting in one of the .INI files that lets you turn
timer chip virtualization off. This may have other undesirable effects,
however; I've never tried it myself.

There are also some higher resolution timing facilities available as part
of the Multimedia API functions. I seem to recall that in order to use them,
you need to create a DLL with a callback function, which Windows then
invokes at your specified timer interval. Check the SDK documentation for
details...

-- Mike Uchima
-- uch...@fnal.fnal.gov

0 new messages