LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Darren's Occasional Nugget 01/05/2018

Wait (ms) doesn't accurately wait, so if you're using this for software timing it's not the best.

 

I always use the newer High Resolution Polling Wait function: https://zone.ni.com/reference/en-XX/help/371361R-01/glang/high_resolution_polling_wait/

 

Yea, it's not a VIM and can't be inserted on any wire, but it has standard error functionality, and won't wait if an error is on the wire. It also waits the actual amount of time you requested 🙂

 

I'd rather have the stall function use this wait under the hood, rather than the inferior Wait (ms).

 

Here's how I would wrap this into a VIM, so it works as it should:

Front Panel.pngError Case.pngOther Wire Case.png

 

See attached 🙂

 

 

Craig H. | CLA CTA CLED | Applications Engineer | NI Employee 2012-2023
0 Kudos
Message 21 of 24
(866 Views)

@Craig_ wrote:

I'd rather have the stall function use this wait under the hood, rather than the inferior Wait (ms).


The flipside is the High Resolution Polling Wait function polls a timer. Doing that everywhere will drain your CPU, and defy the purpose of the 'exact' wait as it does.

 

It's definitely not superior, at least not in general. It just has an entirely different purpose than the normal wait (ms), with it's own ups and downs. IMHO.

 

Here's how to drain my 4 CPUs, ironically the waits usually are there to prevent that:

Precision wait.png

Message 22 of 24
(852 Views)

Yes, the polling wait is implemented with a poll, and yes that can thrash the CPU, but it accurately waits!

 

At higher waits it uses the Wait (ms) for a large chunk of the time, and then polls to get an accurate finishing time.

 

In my use cases, I'm using the wait to add intentional delay between operations, and having that be relatively accurate is very useful. I don't use it as a loop timer.

 

If you want to yield the CPU and know that that the Wait (ms) value you specify has varying accuracy depending on operating system, then that function is perfectly applicable.

Craig H. | CLA CTA CLED | Applications Engineer | NI Employee 2012-2023
0 Kudos
Message 23 of 24
(839 Views)

When the High Resolution Polling Wait.vi was proposed, my response was, "Sweet! I'm going to use this everywhere I used to use Wait (ms), since it has error terminals." To which the authors of the VI responded, "NO! You should only use this VI if you actually *need* the high resolution!". At which point they stuck a red exclamation mark on its icon and added the phrase "Use this VI with caution" to its context help.

 

So I'm on the Stall Data Flow.vim train now, and I hope the idea linked above gets more kudos. 

0 Kudos
Message 24 of 24
(812 Views)