LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with repeating while loop


Escatrax wrote:

Can't I use 3 shift registers: one for adding 1l/sec, one for adding 0,5l/sec and one for decrementing with 1l/sec?


A pair of shift registers is just storage. You need two:

  1. A DBL shift register to keep track of the fill level: LEVEL
  2. A boolean to remember if you are filling or draining the tank: STATE (There are only two real states! For more complicated state machines, you would use a typedef as in Tin's example)

The tank increment is either 1, 0.5, or -1, and the actual value must be calculated from LEVEL and STATE.

 

Here's a minimal solution, see if you understand it.

 

Message 11 of 14
(809 Views)

Hallo altenbach,

 

Well I understand some things, but I haven't started working with arrays so I have to study it before I understand it completely.

 But there's one thing I can't figure out namely you've put a local variable of the stop button outside the while loop en connected it to the loop condition. Why?

 

thanks alot for helping me out!! 

0 Kudos
Message 12 of 14
(805 Views)

Since the stop button should not immediately stop the loop, but initiate draning of the tank, we need switch action instead of latch action (right-click...mechanical action). This means that the stop button should stay TRUE until the program stops (or until the stop is canceled by the operator). Once the loop stops, the program should reset the button to FALSE so the code does not stop right away next time we run the program.

 

There are many other ways to solve this. You can also force the button to FALSE right before the loop when the program starts. This may require a sequence frame (since local variables don't do dataflow) or you could use a value property with the error output wired to the while loop. Doing it before the loop has the advantage that it also works if you would stop the program with the abort button.

Message 13 of 14
(802 Views)
ahn ok I understand, thanks alot!!
0 Kudos
Message 14 of 14
(794 Views)