LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Wait until next multiple

What is the difference between  using a wait until next multiple  in a time critical loop and in a while loop
0 Kudos
Message 1 of 8
(3,296 Views)
Hello jmq
 
The Wait Until Next ms Multiple function works in one way no matter which loop you set it into. It will make sure that every loop will be executed in a multiple of the milliseconds that you define. That will say that if you define the milliseconds input to be 100 ms, and the code in the loop will be executed within 100 ms then every iteration in the loop will only take 100 ms. But if the code in the loop exceeds the 100 ms it will take 200 ms for the iteration to execute and before the loop jumps into the next iteration. And of course if the code exceeds 200 ms the loop will take 300 ms. 
 
Regarding using a time critical loop, it could be a while loop used in a vi where the priority of the execution of the vi is set to be time critical. So when you talk about having a time critical loop it is the case where you use one loop in a time critical vi including some code that should be deterministic. Wanting to use a time critical vi to execute the code within a deterministic time period you should also use a Real Time OS.
 
Hope this will help you out.
 
Mohadjer
NI-DK
0 Kudos
Message 2 of 8
(3,285 Views)

Dos the wait-time start when the loop becomes active

 

Doesn’t the code in the while loop execute when the  wait until next ms multiple function executes

 

 

Is it necessarily  to initialize the wait timer for every while loop or only for time critical loops like on page 4-6 of the real-time course manual

0 Kudos
Message 3 of 8
(3,279 Views)
The wait until next ms multiple uses the OS ms timer and checks if it got to a multiple of the number you wired (let's say if you wired 100, the function will wait until the timer value will be something divisible by 100 [1,000, 1,100, 1,200, 1,300 and so on]), so the wait for the first iteration will probably be less the number you wired, because the timer is almost certainly between multiples.
 
The code in the loop executes at the same time as the wait function, but the function itself will only return once it detects the ms multiple. This means that if you have, for example, in a sequence structure, the code in following frames will have to wait until the function completes.
 
You should place wait functions in all loops which take time because loops without wait functions tend to take over the CPU. A loop with a wait function (even with 0) will let the CPU do other things.

___________________
Try to take over the world!
0 Kudos
Message 4 of 8
(3,276 Views)
tst:  Are you a female (Lucy)?  I once made a similar mistake with Mr. Lynn, and I wouldn't want to do it again.
- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 8
(3,258 Views)

The fact that I chose Lucy as my current avatar should not disclose my gender any more than Sam, Max, Escher or Guybrush Threepwood (some former avatars).

That fact is currently being kept undisclosed to help keep Ben, Altenbach and CC on their toes, so they avoid making assumptions (plus, it's more fun that way).


___________________
Try to take over the world!
0 Kudos
Message 6 of 8
(3,247 Views)

If the code in de loop executes at the same time as the wait function I don"t understand this example form the NI-site

Who can clarify me this?

 

 

Using Wait Until Next ms Multiple to Time a Loop in Time Critical Priority


You must use this VI carefully in the time critical priority of LabVIEW Real-Time. Remember that if any VI sleeps in a time critical thread, then the entire thread sleeps. For this reason, you should control when the Wait Until Next ms Multiple executes, rather than placing the VI in parallel with other code. To understand why, let's look at an example control loop. In this example, we will read an analog input and then write an analog output. The desired timing of the system is shown in Figure 1. The vertical arrows represent 100 millisecond multiples.


Figure 1: Desired timing of control system

Our first attempt to solve this problem is a simple loop with Wait Until Next ms Multiple (see Figure 2).

Figure 2: First attempt at timed loop


In this first attempt, we do not dictate when in the sequence the Wait Until Next ms Multiple executes. The behavior of this loop will differ depending on when the Wait Until Next ms Multiple gets executed. If the Wait Until Next ms Multiple executes first, then the analog input will be followed immediately by the analog output. This behavior is usually desired, but is not guaranteed in the example above.

If the Wait Until Next ms Multiple executes immediately after the analog input, then the analog output will not be able to execute until the Wait Until Next ms Multiple is finished. Again, this is because when any portion of a time critical priority VI sleeps, the entire thread sleeps. The resulting timing would be as shown below, in Figure 3. This behavior is usually not desired.


Figure 3: Wait statement executes after AI


Figure 4: Controlling the sequencing of events

0 Kudos
Message 7 of 8
(3,237 Views)

I think what you may not understand is the dataflow concept which is at the base of LabVIEW.

In one sentence, it can be declared as (in my words)

A piece of code will only execute when all of its input are available.

This means that if you have pieces of code which aren't connected to each other by wire you have no control regarding when they will execute and the code in the rest of the loop could (and almost certainly would) be executed at the same the wait VI is executed.
So, if you put a wait VI in a loop with other code without forcing the timing, you can't know when the wait VI will execute.
The wait VI does something simple - it waits until the ms multiple and then it finishes, so the point in the code you saw in the example is to use a sequence structure to get the VI to wait at the right time.

It sounds like you should worry about LV basics and not about real time coding, which is a more advanced subject and requires that you have LV RT and a real time target.

Also, next time just include a link to the page you want us to see. The images weren't copied and it's very hard to understand this way.

To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here and here are a couple you can start with. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).


___________________
Try to take over the world!
0 Kudos
Message 8 of 8
(3,223 Views)