[comp.sys.ibm.pc.programmer] timing a software function via timer chip

JRD@cc.usu.edu (Joe Doupnik) (05/05/90)

	If one takes a careful look at the IBM PC specs Timer channels 0, 1,
and 2 are nearly identical, but channels 0 and 1 are preallocated to memory
refresh and time of day. So, channel 2 is the only one free for ordinary
programming use. Since they are the same kind, driven from the same clock
one needs to simply choose a nice divisor for the chip to count in units
of up to 1/18.2 seconds.
	The chip can be started just before your test function is executed
and then then stopped at the end. The differences in counts before and
after gives the elapsed time in tics; arithmetic yields the time in seconds.
	If you would like to see an example of this in action take a look
at file MSXIBM.ASM in MS Kermit where I calibrate the duration of a
software timing loop to be 1/1000 second by using channel 2 above to measure
the real time of the loop. That file is available via anonymous ftp from
watsun.cc.columbia.edu  in directory kermit/a.
	Joe D.

tjr@cbnewsc.att.com (thomas.j.roberts) (06/05/90)

From article <23656@cc.usu.edu>, by JRD@cc.usu.edu (Joe Doupnik):
> 
> 	If one takes a careful look at the IBM PC specs Timer channels 0, 1,
> and 2 are nearly identical, but channels 0 and 1 are preallocated to memory
> refresh and time of day. So, channel 2 is the only one free for ordinary
> programming use....

Channel 2 is used to generate a pulse-train for the speaker.
You can safely use it as described, and not bomb any program or driver
on the PC; you should make sure that the routines being timed DO NOT
generate any sound or cause ^G to be typed - those would cause your
timing values to be wrong.

Tom Roberts
att!ihlpl!tjrob