LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

most efficient "wait"?

I have a task that needs to happen once a second.  I can think of two (easy) ways to do this:  (1) place the task inside a While loop with a 1 second timer, or (2) place the task in the Timeout of an event structure, and set the timeout value to 1 second.

 

Is there a reason to choose one over the other?  There's a lot of other stuff going on in the program...

 

Thanks,

-GN

 

 

0 Kudos
Message 1 of 7
(2,292 Views)

If there is "a lot of other stuff..." I would caution against using the event timeout.  the timeout event happens at TMO mSec after the LAST event so, it is completely unpredictable in time if other events occur at all.

 

A separate timed loop would allow the greatest flexability (and spawn its own dedicated execution system to run in)


"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 7
(2,285 Views)

When you say "the timeout event happens at TMO mSec after the LAST event", do you mean after the last event in just this structure?  Or across all the event structures in my program (each of which is in its own while loop).

 

I was planning to have the timeout event be the only event in that structure...

0 Kudos
Message 3 of 7
(2,277 Views)

Note that there is a distinct difference between the Wait ms and Wait Until Next ms Multiple functions.

 

If your task requires less than one second to execute, you probably want to use the Wait Until Next ms Multiple function.

 

For an explanation between the two, see this Knowledgebase entry.

 

 


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

0 Kudos
Message 4 of 7
(2,275 Views)

How deterministic is you timing requirement?  

 

The timeout on the event structure may not timeout according to your schedule if the structure is busy taking care of another event. 

 

Unless you are careful with data dependencies when using the Wait VIs, you may get inconsistent delays depending on how long any processes sharing the loop require to complete.  

 

The timing resolution of these loops is limited to the resolution of the operating system. In the case of Windows it's about 1 ms. Consider the Timed Loop. It has many features to help the process stay on time. For example, the loop keeps track of its performance during each iteration from which you can adjust the period on the fly. If you need a timing resolution better than the operating system, you can use external hardware to pace the loop. Multiple loops can be synchronized with a single timing source.

 

 

 

 

0 Kudos
Message 5 of 7
(2,267 Views)

 


@gnunesjr wrote:

When you say "the timeout event happens at TMO mSec after the LAST event", do you mean after the last event in just this structure?  Or across all the event structures in my program (each of which is in its own while loop).

 

I was planning to have the timeout event be the only event in that structure...


~~~Shudder~~~

 

Yes, it is possible to have multiple event structures running in the same vi however, this approach can become a nightmare to debug and maintain.  its pretty easy for this to become abstract art and what happens if there is a need to share data between the event structures?  USE EXTREME CAUTION if taking this approach!  (<<read as: Don't do that)

 

Event structures only respond to the events they are configured to handle and only the events they handle effect the timeout timer for the structure.  So, in theory a event structure with only a timeout case would operate like a loop with a delay that starts after the rest of the code completes.  in contrast a timed loop executes every (x)mSec like a loop with a wait for next ms multiple inside (but with more functionality available)

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 7
(2,256 Views)

Use a seperate loop for the timed task (either with a "wait next ms multiple or directly with a timed loop).

 

Clearly, the event timeout is a very bad idea. Imagine you trigger an event every 990ms. The timeout case will never execute! Ever!

 

(You can get slightly better behavior if you dynamically adjust the timeout if events occur. See also my comment to a related idea)

0 Kudos
Message 7 of 7
(2,241 Views)