Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

techniques for calibrating software time

I need to generate pulses on one of the lines of my DIO-96, which doesn't have the pulse generating API available to it that some of the analog instruments do. I don't own Labview Realtime so I have to do it myself in C++. The method I've heard to use is to perform some standard mathematical operation in a loop many times and then time it to obtain an approximate value on the time needed to perform that operation-- Then simply use that operation as the basis for a timer by repeatedly invoking it in a loop. I was going to use arctangent in Visual C++, but if I just do something like arctan(1) is there a danger the compiler will cache the result and that that will skew the timing? Would it be better to gener
ate a random number each time and then perform arctangent on that? Or is there a better trick available? The Microsoft C++ libraries have a process timer function called clock and a few others, but these are not even precise enough for time intervals measured in milliseconds,much less microseconds. any tips appreciated.

brendan
0 Kudos
Message 1 of 3
(3,343 Views)
I use VB and use this Windows API to generate the delay in millisecond. I'm sure you can use this API in VC++ too.

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sleep 100 'generates a 100 ms delay

Hope this helps
Rajiv Agarwal
www.rajiva.com
0 Kudos
Message 2 of 3
(3,343 Views)
Sleep(100) is a minimum 100ms delay.
There might be some disk or whatever
else activity and this call maight take
somewhat longer. The same applies to
the tangent() loop. Windows was not designed
to be a realtime system. Any timing is
just approximate.
0 Kudos
Message 3 of 3
(3,343 Views)