CPU Independant Timer (286+)

If you've even tried timing stuff on the PC it can become very fustrating. The timer tied to IRQ#0 is great if you know how to adjust it but Windoze and such will not allow you to do this. And using this timer for say delays in your program when you need like a 1ms delay is too much overhead. Using non-destructive reads from some IO ports can give you a long enough delay but if your code moves to a faster CPU the delay may no longer be long enough. Well as I was scrolling thru some old PC tech info I've found the perfect anwser. It seems that there is a timer connected to port 61h at bit 4. This bit toggles every 15.085 u sec (micro sec).
Here's an example of how to delay exactly 1 sec on any system.
   in al,61h      ;input
   and al,10h     ;mask bit 4
   mov ah,al
   mov cx,0ffffh  ;1 sec delay
   in al,61h
   and al,10h
   cmp al,ah
   jz cnt1        ;no change then loop back
   mov ah,al
   dec cx
   jnz cnt1
This will cause a delay of exactly 1 sec on any system. It's completly CPU independant. This timer is available only on 286 systems and up. There is no IRQ for this timer but it's great for using delays when programming timely critical devices (like the DMA, sound cards, etc.).


Copyright © 1995-2005 Nexus Systems Privacy
SourceForge.net Logo