LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

wait time in while loop: wait before all other code in the loop runs

My vi is attached. 

 

In the 'Check for Equilib' case, there is a while loop that takes data from a pressure gauge and compares it against data taken equilibTime seconds previous.  equilibTime is hooked up to a wait(ms) function inside the while loop.  Currently it appears that the code in the loop runs, and then the loop waits so many seconds before the next iteration.  I would like to reverse this process, i.e. in each iteration, the loop will wait so many seconds and then run the rest of the code in the loop.  I want to do this because I don't want there to be any delay between then time the 'check for equilib' code finishes and the start of the 'add shot' case.

 

Can anybody suggest an elegant way of implementing this?

 

Thank you

0 Kudos
Message 1 of 4
(1,611 Views)

As a quick fix why don't you execute it then in a stacked sequence structure inside your while loop in Check for Equilib case. Wait first for so many milliseconds and then execute the code in the next sequence frame. An ellegant or preferred way (we all hate sequences in LV) is to have a simple state machine inside your Check for Equilib case with Wait state first and your code as the case in the state machine. This should solve your delay problem.

By the way, a better way to implement State Machines is to use enumerated type definition with your states wired to the case selector input. This makes it easier to modify the cases and avoid errors with misspelling of strings.

 

0 Kudos
Message 2 of 4
(1,608 Views)
if u want to execute your code sequentially then use stack sequences, But i wont prefered much. Another thing you can do is add a wait case in the state machine if u want delay before executing some specific case the enqueue the delay case first then enqueue the required case.Ya use Enumerated controls to avoid misspelling as told above.
Balaji PK (CLA)
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better

Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
0 Kudos
Message 3 of 4
(1,601 Views)

No.  Use Flat sequences they are far preferable to stacked sequences.  Functionally they are the same.  But a flat sequence is easier to read, doesn't hide code, and you don't have to worry about backwards wiring caused by sequence locals in stacked sequence.

 

Note, you have two oddities in your lower while loop.

1.  Write a value to an indicator's terminal node and to a local variable of the same indicator is pointless.  They do the same thing.

2.  Reading from a local variable of an indicator and writing to its terminal node is just as pointless, as you aren't doing anything.

 

In your middle loop "Add shot" case, you have the local variable of DC estimate righting to a right hand side shift register, but you never use the left hand shift register.  So you are saving that value for future loop iterations, but never use it.

0 Kudos
Message 4 of 4
(1,595 Views)