Solved

Microsecond timing routine for DOS

Posted on 1997-08-18
2
365 Views
Last Modified: 2008-03-10
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
Comment
Question by:paas
2 Comments
 
LVL 4

Accepted Solution

by:
emmons earned 100 total points
ID: 1253333
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
 

Author Comment

by:paas
ID: 1253334
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now