[comp.os.msdos.programmer] Fixed clock speed on pc? CLK_TCK == 18.2 is TRUE??

marwk@levels.sait.edu.au (12/21/90)

In time.h in TURBO C 2.0 CLK_TCK is defined to be 18.2.

Should I alter this depending on the speed of the processor, RAM speed
etc., or is there a specific clock on the PC/AT/386,..., that always
ticks away at the same speed, namely 18.2 times/second?

Thank you in advance.

Ray

apm233m@vaxc.cc.monash.edu.au (12/21/90)

In article <15779.2770e40e@levels.sait.edu.au>, marwk@levels.sait.edu.au writes:
> In time.h in TURBO C 2.0 CLK_TCK is defined to be 18.2.
> 
> Should I alter this depending on the speed of the processor, RAM speed
> etc., or is there a specific clock on the PC/AT/386,..., that always
> ticks away at the same speed, namely 18.2 times/second?

I don't know why CLK_TCK is defined in time.h, but the nominal 18.2 "ticks" per
second should be the same on all machines running MS-DOS.

MS-DOS (and PC-DOS etc) have a time-of-day clock. The PC BIOS is interrupt-
driven by a programmable hardware timer running at 18.2 interrupts per
second. This rate is independent of the processor type (8088/80286/80386/etc).
MS-DOS gets the time-of-day from a count of the number of ticks since midnight
which is maintained by BIOS. (I think that it is possible to change this
behaviour of MS-DOS, e.g. by way of an installable driver, but this would
not remove the requirement that the BIOS maintains a correct count - other
programs besides MS-DOS itself can use the BIOS tick count.)

It is possible to perform tricks with the hardware timer to make it run faster,
but you must make sure that the counter which is maintained by bios is
correct whenever it is read. The easiest way of doing this is to make sure that
the BIOS timer interrupt routines are called at the correct rate of 18.2 ticks
per second.

As mentionded above, in addition to the use which MS-DOS makes of the clock
ticks, some programs will use the timer for timing purposes and these programs
will break if the tick rate is changed.

Turbo-C provides the biostime() function for setting and reading the BIOS
tick count.

----------------------------------------------
Bill Metzenthen
Mathematics Department
Monash University
Melbourne, Australia

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (12/21/90)

In article <82583.2771ee24@vaxc.cc.monash.edu.au> apm233m@vaxc.cc.monash.edu.au writes:
>
>I don't know why CLK_TCK is defined in time.h, but the nominal 18.2 "ticks" per
>second should be the same on all machines running MS-DOS.

As an aside:  someone in the Fidonet Pascal who was writing programs to use
at timing races commented on this.  He found the tick rate is very stable
on most machines, but varies from the IBM standard rate by as much as a few
percent (I think) on some clones.  If you need high accuracy, it's necessary
to calibrate it against a reliable external clock.

Duncan Murdoch

lwb@pensoft.UUCP (Lance Bledsoe) (12/22/90)

In article <15779.2770e40e@levels.sait.edu.au> marwk@levels.sait.edu.au writes:
>In time.h in TURBO C 2.0 CLK_TCK is defined to be 18.2.
>Should I alter this depending on the speed of the processor, RAM speed
>etc., or is there a specific clock on the PC/AT/386,..., that always
>ticks away at the same speed, namely 18.2 times/second?

Thats correct!  The clock inturrupt on ANY PC/AT/XT/CloneT is envoked exactly
every 18.2 times a second.  

And now for the $10,000 bonus question... ;-)


-- 
Lance Bledsoe                       Off:    (512) 343-1111                 
Pencom Software, Inc.               Fax     (512) 343-9650                 
8716 Loop 360 N. Suite 300          UUCP:   cs.utexas.edu!pensoft!lwb      
Austin, Texas  78759                UUNET:  uunet!uudell!pensoft!lwb       

r3jjs@VAX1.CC.UAKRON.EDU (Jeremy J Starcher) (12/22/90)

In article <2972@pensoft.UUCP> lwb@pensoft.UUCP (Lance Bledsoe) writes:
>In article <15779.2770e40e@levels.sait.edu.au> marwk@levels.sait.edu.au writes:
  [ Question Deleted]


>Thats correct!  The clock inturrupt on ANY PC/AT/XT/CloneT is envoked exactly
>every 18.2 times a second.  
>

Watch out!  The normal clockspeed is about 18.2 times a second.

Some programs (GWBASIC) change the clockspeed (thus the clock interrupt)
to four times that speed.  GWBASIC sets up a new handler (INT 8h I think)
to call the old one once every four ticks.  Although this won't matter
to most programs, in a few weird situations it could be nastly.

I know, a minor quip since most people will never care about it.  However
being a low-level programmer makes me very carefull to document any possible
side effects of a feature or function.

PS--- I don't know if that modified clockspeed is a constant state
or weather that only comes in when music is playing...

-- 
--------------------------+---------------------------------------------------
Jeremy J Starcher         !  No programmer programs in LOGO after reaching
r3jjs@vax1.cc.uakron.edu  !  age 14...
r3jjs@akronvm.bitnet      !

gwaigh@micor.OCUnix.On.Ca (Geoffrey Waigh) (12/30/90)

The clock tick frequency is left at 4 times normal (at least in BASICA) after
BASIC exits, even if no music was invoked.  A friend of mine found this out
when programming a hi-res clock routine by reprogramming the chip and then all
of a sudden things changed gears if people used BASIC.

gwaigh@micor.ocunix.on.ca | People wanting disclaimers here don't deserve
                          | to see that which is obvious.