LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Delay function resolution and rounding

Solved!
Go to solution

A quick question about the Delay () function.  The resolution is apparently 1 ms according to the help file.  What happens if I pass it a value with some fraction of a mlliseconds, say something like,

Delay(0.0128);

For 12.8ms.  Does it rround up and delay 13ms?  Or round down to 12ms?  Undefined?  Something else? 

 

Thanks.

0 Kudos
Message 1 of 5
(3,219 Views)
Solution
Accepted by topic author tstanley

Hey tstanley,

 

I did some research into the function, and it looks like the functionality is for the timer to try and get as close to the 12.8ms, but since the resolution is only 1ms, it could still be +/- 1ms from the value you enter. So in some of our tests, it was waiting for 13.8ms, since that's within the 1ms accuracy of the timer.

 

Since Windows is not a realtime operating system, there are several factors that could keep the timer from delaying for 13.8ms--other processes can run on the machine and pre-empt the timer process, for example. If this level of precision is necessary, you might want to consider using the CVI RT module on a realtime operating system.

Message 2 of 5
(3,182 Views)

Thanks for the response.  The reason I ask is because I need to delay while some settings take effect on a piece of hardware, and I was calculating the time.  Then I realized that the delay time I was calculating wasn't a round number of milliseconds.  If I ask for 12.8 ms the real delay time is 13.8 ms or even 20 ms then it's not a big deal, but 12 ms is could be problematic.  In any case I've added another millisecond to my delays to make sure that it waits enough time.

0 Kudos
Message 3 of 5
(3,163 Views)

Hey TStanley,

 

Now that I know more about why you are asking this question, I can be a little more specific and that may help. When calculating the delay, we actually take the 1ms of inaccuracy into account. If you are specifying 12.8ms, then with 1ms of variance, that actual result could be either 11.8 or 13.8. But we agree with you that it is preferred for the delay to be longer than the specified time, than it is to be shorter than the specified time. So internally, we actually add 1ms to your input (just as you did in your own code). So really the delay function is attempting to delay for 13.8ms, but because there is up to 1ms of inaccuracy, that could be as low as 12.8ms or as high as 14.8ms.

 

This is why I always recommend not relying on it for any specific timing control. The real purpose of the function is to delay at least a specified time (the delay could be even longer than 14.8 if the thread is interrupted for any reason).

 

As for the 12.8, we don't round that number internally. So there is really no limit to the precision of your input, it's just that anything less than 1ms has little practical meaning.

National Instruments
Message 4 of 5
(3,147 Views)

It makes sense what the Delay() function is doing, and for my purpose it suits it well. Thanks for the explaination!

0 Kudos
Message 5 of 5
(3,130 Views)