Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!usc!sdd.hp.com!spool.mu.edu!uunet!mcsun!corton!chorus!opera.chorus.fr!mir From: mir@opera.chorus.fr (Adam Mirowski) Newsgroups: comp.os.msdos.programmer Subject: Re: Accurate timing request Message-ID: <8162@chorus.fr> Date: 8 Mar 91 15:41:03 GMT References: <1991Mar6.145414.8747@uwovax.uwo.ca> <1991Mar7.025205.9213@qualcomm.com> Sender: mir@chorus.fr Reply-To: mir@opera.chorus.fr (Adam Mirowski) Organization: Chorus systemes, Saint Quentin en Yvelines, France Lines: 28 In article <1991Mar7.025205.9213@qualcomm.com>, rdippold@maui.qualcomm.com (Ron Dippold) writes: %% In article <1991Mar6.145414.8747@uwovax.uwo.ca> bangarth@uwovax.uwo.ca writes: %% >Researchers here are looking for some facility to measure time with 1 ms. %% >or less accuracy on an AT or 386 machine. We currently with our software %% >(in Turbo Pascal) can't get any better than about 3 ms. accuracy. I have heard %% %% I would suggest that you speed up the clock ticks. Currently they occur %% 18.2 times a second, but you can speed it up so that they occur 1000 times %% a second or more, as the timer is programmable. Your interrupt routine will %% need to scale whatever timer value you use down to the expected value and %% pass that on to the old timer. For example, if you speed up the timer 128 %% times, you will need to call the old interrupt vector every 128 actual ticks. %% You can get some great accuracy this way, just keep in mind that the faster %% you interrupt the processor, the more machine power it gobbles up. On every PC you have a 838ns resolution timer, counting on 16 bits. When it reaches 0, the standard clock interrupt is called. When you want a time-stamp, just read both system time and that counter. That will provide you a very precise value. There is some effort to do in order to get the lowest overhead and a coherent value, though. Don't reprogram the timer (so as to get more interrupts), because you don't need them. You would need to reprogram the timer if you wanted to periodically poll some I/O port without sitting in a loop, or to get a more "round" signal for a scheduler, etc. -- Adam Mirowski, mir@chorus.fr (FRANCE), tel. +33 (1) 30-64-82-00 or 74 Chorus systemes, 6, av.Gustave Eiffel, 78182 Saint-Quentin-en-Yvelines CEDEX