LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timing discrepancies in LabVIEW 6.0

The construct in question uses the wait .vi in a while loop.
Loop execution stops when the specified total running time elapses.

What my .vi should do:

Read data from instruments in lab setup and store results (append
lines to file) every x milliseconds

Results of external time monitoring; what my .vi actually does:
1. Achieves virtually perfect timing when x=1000 😉
2. Shows huge timing discrepancies which increase with decreasing x
when x<1000

Example discrepancy (stopwatch) when x=250:

1 hour total running time more than doubles to 2 hours 3 minutes (!)

Any suggestions as to cause and plausible remedy?

Thanks in advance.


Best regards,
Andrew
0 Kudos
Message 1 of 4
(2,808 Views)
Without having the VI to look at, All I can offer is some general comments on timing. First, LabVIEW just uses the system clock and is only as accurate as that. A PC's clock is cheap and notoriously unreliable. Second, none of the common operating systems are deterministic. You can't rely on anything happening exactly when you want it to. Third, the what the wait function does is execute whatever is inside your loop, waits, then executes again. If whatever you have in the loop takes 500 msec and you have a 250 msec wait, the total loop time is no less than 750 msec. It could be much greater if your system is doing a lot of things in the background. With all that said, if at the beginning of your loop you use the Get Date/Time in Seconds function and use it i
nside the while loop to calculate elapsed time, your while loop should run pretty close to the running time you've selected.
0 Kudos
Message 2 of 4
(2,807 Views)
As Dennis indicated, the system clock is not very reliable.

It seems to me that you have some issues with your delay. You may be assuming things about the delay, as indicated again by Dennis. Instead of using the "wait milliseconds", use the "wait until next ms multiple". This is a better way to achieve what you are looking for.

If you need timing accuracy down to the millisecond, I would suggest considering LabVIEW Real Time.
Message 3 of 4
(2,807 Views)
....
> Example discrepancy (stopwatch) when x=250:
>
> 1 hour total running time more than doubles to 2 hours 3 minutes (!)
>
> Any suggestions as to cause and plausible remedy?
>

If you are using just the wait milliseconds, then this node guarantees
that it will wait at least the time wired to it. The non-determinism
will add up and up. There is another node, the wait ms multiple, that
does some internal math to wait until the next multiple of the delta.
In your case, it will determine the time and wait until the next
multiple of 250, which will often be less than 250ms.

As the other response pointed out, the wait can either run in parallel
with other things on the diagram, or it can be running in sequence and
adding to the 250ms delay.

By the w
ay, the wait ms is usually sufficient to make up for lost time,
but if not, another approach is to add a shift register to your loop,
measure the total time the loop has been running, divide by i, and
determine how much time to sleep. This way when the loop gets one
iteration behind, the delays go to zero trying to get back on schedule.

Greg McKaskle
0 Kudos
Message 4 of 4
(2,807 Views)