[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

Microsecond timing routine for DOS

Please help me to find an algoritm to provide software delays accurate to plus or minus 10 microseconsds and able to generate delays fo the order of  1.2 to 2.5 milliseconds.
0
paas
Asked:
paas
1 Solution
 
emmonsCommented:
The problem is going to be that the clock on the machine generates ticks on the order of 1 per millisecond (check out the system value CLOCKS_PER_SEC). This means that millisecond timing is easy. Microsecond, not so much.
For a millisecond level timer a quick way might be to put in a
loop to check the timer upon occasion until the correct time has passed. .

#include <time.h>
/* give begintime and endtime the type */
/* returned by clock(): clock_t on my system */
clock_t begintime, endtime;
float totaltime; /* in seconds */
endtime = begintime = clock();
for( totaltime = 0;  
      (endtime - begintime) < 100    /* 100 ms */;
      endtime = clock()
      );

If you really need microsecond timing, there is a company that sells a library that does it. Check out
http://www.ryledesign.com/winhrt.html
0
 
paasAuthor Commented:
Dear Emmons,
I really do need microsecond timing to get accurate delays of 1.2 and 2.5 milliseconds.  I am presently using a softrware delay loop written in assembler and trying to calibrate it automatically by calling it  multiple times (say 1.2 mS * 5000 = 6 seconds) and adjusting its loop counter until I get the right answer.

BTW there is a website called 'snippets' which has such software but I have not been able to assemble their timer.  Also Borland offer a millisecond timer (delay (unsigned milliseconds)] as a part of their runtime library.
Pls excuse the return advice flow!!!

Many thanks,

Andy
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now