[comp.sys.ibm.pc.misc] reading system timer?

randys@cpqhou.uucp (Randy Spurlock) (03/06/91)

in article <1991Mar3.1124.5635@canrem.uucp>, bradley.grigor@canrem.uucp (bradley grigor) says:
> 
> As part of a system performance analysis exercise, I would like
> to read the *internal counting register* of the PC system timer
> channel 0.  This is the timer channel that creates the system
> clock interrupts 18.2 times per second.
> 
> I want to determine how many internal timer counts (which run at
> the relatively high speed of 1.193180 MHz) have elapsed since the
> last system clock interrupt. I have tried to do it essentially as
> follows:
> 
>          MOV  AL,36h   ;select timer channel 0
>          OUT  43h,AL   ;  for reading LSB first
>          IN   AL,40h   ;read the LSB
>          MOV  BL,AL    ;  and save it
>          IN   AL,40h   ;read the MSB
>          MOV  BH,AL    ;  and save it
>    ;
>    ; Now BX contains the 16-bit counter value.
>    ;
> 
> This works but there is a serious problem: when this code reads
> timer channel 0, it causes the timer channel AND the stream of
> 18.2 interrupts per second to STOP (or so it would appear)!  Of
> course, this wasn't what I had in mind.  But I also didn't expect
> this because I thought this timer channel was gated in hardware
> to run continuously!  I guess I was wrong!
> 
	You need to issue a timer latch command instead of a timer
	load command (use 00h instead of 36h). This will allow the
	timer to continue to run but will also allow you to read 
	the timer count value when you issued the timer latch command.
	I use this to get the internal count value for fine resolution
	timing and delays on a PC.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
          - Randy Spurlock -	      |      Compaq Computer Corporation    
---------------------------------------------------------------------------
These opinions are mine...all mine... | He fired his hyper-jets and...  
just ask anyone who's heard them!     | blasted into the 5th dimension!
--------------------------------------| 
UUCP: ...!uunet!cpqhou!randys         |                     Space Man Spiff
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=