LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

stopping a loop without waiting for its next iteration

Solved!
Go to solution

@winterfresh11 wrote:

So is this what the final solution should look like, it seems to work?


No, it does not work! A timeout event with a -1 hardwired to the timeout, will never timeout and will stall the loop in the first iteration forever or until stop is pressed.

Why don't you wire an indicator to the iteration terminal to see for yourself?

 

Before attaching a VI, you should also place reasonable default values into all controls (Do you know how to do that?). Currently we get a division by zero unless we change the values.

Message 11 of 20
(1,517 Views)

It appears that you cannot run any other code in the while loop though because the loop is just waiting for the event structure to do something. For example, I wired in a simple counter and it counted when the event structure was disabled but no when the structure was enabled 

0 Kudos
Message 12 of 20
(1,515 Views)

@winterfresh11 wrote:

It appears that you cannot run any other code in the while loop though because the loop is just waiting for the event structure to do something. For example, I wired in a simple counter and it counted when the event structure was disabled but no when the structure was enabled 


Yes, you are learning about the simple principles of dataflow: All code in the while loop (and the current cases) will run, but the loop cannot go to the next iteration until every part of the loop code has completed, of course. If you want to truly run things in parallel, use two independent while loops. All the tools are right there!

 

Can you explan your timeout calculation? It seems to always retun the same value. What should happen if the inputs are changed while it is still waiting? (e.g. complete the current wait, break the wait and update to the new value, etc.)

0 Kudos
Message 13 of 20
(1,507 Views)

I don't have a calculation for the event structure timeout, I just weired in 1 and it appears to wrork now. The other calculation in the code is just to determine how long each iteration should take based upone the final power one would want to get to and how fast they want to get there. 

0 Kudos
Message 14 of 20
(1,497 Views)

@winterfresh11 wrote:

I don't have a calculation for the event structure timeout, I just weired in 1 and it appears to wrork now. The other calculation in the code is just to determine how long each iteration should take based upone the final power one would want to get to and how fast they want to get there. 


No that will defeat the entire purpose because the loop is still stalling at the wait and you even have now a race condition because the event structure times out in 1ms and the stop button will most likely not be read until the next iteration.

0 Kudos
Message 15 of 20
(1,490 Views)

So what kind of timeout  calculation would be ideal for this? I guess I'm still a bit confused

0 Kudos
Message 16 of 20
(1,485 Views)

@winterfresh11 wrote:

I don't have a calculation for the event structure timeout, I just weired in 1 and it appears to wrork now. The other calculation in the code is just to determine how long each iteration should take based upone the final power one would want to get to and how fast they want to get there. 


If you don't want the values to change while the loop is executing, the timeout calculation needs to be before the while loop. No need to constantly recalculate it.

 

What are the units of "final"? How is it defined? Why are the controls DBL? Shouldn't they be integers? (Multiply by 1000 before the division and use Q&R for the division to keep it all blue.)

 

You still haven't told us the typical values for the controls.

 

 

0 Kudos
Message 17 of 20
(1,483 Views)
Solution
Accepted by topic author winterfresh11

@winterfresh11 wrote:

So what kind of timeout  calculation would be ideal for this? I guess I'm still a bit confused


Try something like this, for example.

 

 

0 Kudos
Message 18 of 20
(1,478 Views)

The units of "final" would be in Watts, the typical value for final could be anything from 1 to 100. The controls don't need to be DBL so i changed them. The value of "ramp time" could be anything really, but typically in the 300 seconds to 1800 seconds range.

0 Kudos
Message 19 of 20
(1,470 Views)

Indeed what you want is break comment in text base programing but labview do not have break to break the loop or while suddenly but there are some trick that you can use them for do it i attach you a vi with two method for do this test them and tell me if it is what you want 

0 Kudos
Message 20 of 20
(1,447 Views)