LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Time not stopping with while loop

Hello,

 

I've attached my VI.  I am having trouble with while loops.

 

I want to turn on LEDs. The first LED should turn on after 3s.  The second LED should turn on after 5s.  The third LED will turn on later. 

 

The LEDs turn on based on the following conditions:

Case 0: numeric control > 10 then led_1 off, led_2 off, led_3 off

Case 1: numeric control <= 10 then led_1 on, led_2 on, led_3 on

Case 2: numeric control <=5 then led_3 on

 

Because of the way I'm delaying time, I have the following problems

Case 1 --> case 2: led_3 doesn't come on right away

Case 2 --> case 1: led_3 doesn't turn off right away

 

Putting probes in certain areas leads me to believe that these problems are due to the way the time delay is being generated.

 

Thanks in advance.

 

EDIT: Looking at it more...it seems to be that when the stop condition is true, the loop runs one more iteration. Is there a way to keep it from running that "one more iteration."

0 Kudos
Message 1 of 4
(2,426 Views)

Your stop button is read as soon as the loop starts.  So if you need to stop the loop, it will iterate again before it has a chance to stop.  You will need set a sequence that guarantees the stop button is read and acted on after your delays.

 

If you want LED 3 to be turned on or off right away, then put it in the corresponding case structures in parallel to the other code.

 

Here is a cleaner version of your code.

0 Kudos
Message 2 of 4
(2,401 Views)

@EightBit wrote:

 

I want to turn on LEDs. The first LED should turn on after 3s.  The second LED should turn on after 5s.  The third LED will turn on later. 

 

The LEDs turn on based on the following conditions:

Case 0: numeric control > 10 then led_1 off, led_2 off, led_3 off

Case 1: numeric control <= 10 then led_1 on, led_2 on, led_3 on

Case 2: numeric control <=5 then led_3 on


You need to be more clear with the specifications. First you tell us that the LEDs should depend on timing, then they should also depend on the value of a control. Since these two directives can conflict with each other, it is not clear what you actually expect to happen. (e.g. what do you expect if the control is >10 and 5 seconds have elapsed.) Also "later" is too imprecise to be of any use.

 

Why are you using all these value property nodes? All you need is a small state machine.

 

 

0 Kudos
Message 3 of 4
(2,386 Views)

One of the problems is that your VI is not able to "breathe" because it is sometimes trapped inside inner loops that consume all CPU and step on each others toes. All you need is an single outer loop and a few shift registers.

 

May of your specifications are still not clear, for example what should happen to LED 1&2 in case #3? Should they remain in the state they are in, or should they turn off, for example.

 

Here is a simple rewrite that spins the outer loop at a regular rate, has no inner loop, and does not need any local variables or value property nodes. See if it makes sense. Also note that your code can be simplified dramatically by using arrays. Since the stop button is read with each of the regular interations, we don't need to worry about sequencing.

 

Most likely you need to do a few simple modofications, because your specs are not clear.

0 Kudos
Message 4 of 4
(2,373 Views)