Solved

Microsecond timing routine for DOS

Posted on 1997-08-18
2
374 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

729 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