hardt@linc.cis.upenn.edu (Dan Hardt) (11/18/89)
A friend needs to read the time for a real-time application. We tried using some Microsoft C functions for reading the clock. The functions returned the time down to the hundredth of a second -- but they don't seem to notice any change in the time less than 5/100 of a second or so. If we have a loop which continually checks the time, its values are ,eg, 0,0,0,0,5,5,5,5,5,11,11,11,etc Why is this? Any way to get a more fine-grained access to the time?
fredex@cg-atla.UUCP (Fred Smith) (11/20/89)
In article <17118@netnews.upenn.edu> hardt@linc.cis.upenn.edu (Dan Hardt) writes: > If we have a loop which >continually checks the time, its values are ,eg, > 0,0,0,0,5,5,5,5,5,11,11,11,etc >Why is this? Any way to get a more fine-grained access to the time? This is because on standard PC (and clone) hardware the clock ticks 18.2 times per second, which is close to 55 milliseconds per tick. There are techniques that can be used to reprogram the hardware so that the clock will tick more often. There was a program came over the new within the last month or so which illustrated how to do this. Fred
cs4g6ag@maccs.dcss.mcmaster.ca (Stephen M. Dunn) (11/21/89)
In article <17118@netnews.upenn.edu> hardt@linc.cis.upenn.edu (Dan Hardt) writes:
$A friend needs to read the time for a real-time application.
$We tried using some Microsoft C functions for reading the
$clock. The functions returned the time down to the hundredth
$of a second -- but they don't seem to notice any change in the
$time less than 5/100 of a second or so. If we have a loop which
$continually checks the time, its values are ,eg,
$ 0,0,0,0,5,5,5,5,5,11,11,11,etc
$Why is this? Any way to get a more fine-grained access to the time?
This is because the clock ticks in the PC run at approximately 18.2 Hz,
or roughly .055 seconds apart. If you're using the system clock, accessed
through a DOS call (which is how every compiler I've seen does it), that's
the best resolution you can get.
In order to get a more fine-grained clock, there are a couple of ways to
do it:
1. Find one of the timers that isn't used for anything and program it to
run at whatever speed you want (you'd have to check the IBM tech ref
for this info, unless someone else can fill you in)
2. Speed up the 18.2 Hz clock to some multiple of that speed, insert your
own code into the clock tick (BEFORE DOS's own code, of course!) which
a) updates your counter once per fast tick
b) calls the normal DOS clock routine once every n clock ticks, where
n is your speedup factor.
Hope this helps!
--
Stephen M. Dunn cs4g6ag@maccs.dcss.mcmaster.ca
<std_disclaimer.h> = "\nI'm only an undergraduate!!!\n";
****************************************************************************
They say the best in life is free // but if you don't pay then you don't eat
dar@nucleus.UUCP (Dario Alcocer) (11/21/89)
In article <17118@netnews.upenn.edu>, hardt@linc.cis.upenn.edu (Dan Hardt) writes: > A friend needs to read the time for a real-time application. > We tried using some Microsoft C functions for reading the > clock. The functions returned the time down to the hundredth > of a second -- but they don't seem to notice any change in the > time less than 5/100 of a second or so. If we have a loop which > continually checks the time, its values are ,eg, > 0,0,0,0,5,5,5,5,5,11,11,11,etc > Why is this? Any way to get a more fine-grained access to the time? If i'm not mistaken, it seems that the functions you are using are getting the BIOS clock ticks since midnight (this value is used in INT 21h, 2Ch: DOS Get System Time). The BIOS clock tick count is available at 0040:006C. Since the BIOS clock tick count is incremented by INT 8, which is called approximately 18 times per second, the granularity of the clock tick count is ~1/18 sec, which is roughly equal to 5/100 sec. To have smaller granularity would require you to reprogram the timer chip, and I have seen it done before, although I have no code that does this. Maybe someone else has done it, and could share this with you. Hasta... dario. +==================================================================+ | + | | Dario Alcocer (San Diego, CA) | Internet......dar@nucleus.mi.org | | via Nucleus | phone...............619-450-1667 | | + | +==================================================================+