Solved

Microsecond timing routine for DOS

Posted on 1997-08-18
2
364 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

758 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

21 Experts available now in Live!

Get 1:1 Help Now