LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Terminating two while loops simultaneously

Hello,

 

I have a VI that controls a spray nozzle, which outputs staggered sprays cyclically. Essentially, there are two pulses: One controls the cycle (high time/low time), and the other controls the frequency of the spray within one cycle's high time. A transistor was used to connect these two pulses, so that the pulse will only trigger during the cycle's high time.

 

I'm having difficulty synchronizing the two while loops in my VI. The upper loop controls the pulses, while the lower loop is a counter for the number of sprays and cycles. When I hit STOP, the upper loop stops, but the lower loop executes another iteration before stopping. What changes should I make so that both loops will terminate simultaneously when the STOP condition is met? Thank you in advance for your assistance!

 

Thanks,

Michael

Download All
0 Kudos
Message 1 of 6
(2,590 Views)

@michaelfriedmn wrote:

Hello,

 

I have a VI that controls a spray nozzle, which outputs staggered sprays cyclically. Essentially, there are two pulses: One controls the cycle (high time/low time), and the other controls the frequency of the spray within one cycle's high time. A transistor was used to connect these two pulses, so that the pulse will only trigger during the cycle's high time.

 

I'm having difficulty synchronizing the two while loops in my VI. The upper loop controls the pulses, while the lower loop is a counter for the number of sprays and cycles. When I hit STOP, the upper loop stops, but the lower loop executes another iteration before stopping. What changes should I make so that both loops will terminate simultaneously when the STOP condition is met? Thank you in advance for your assistance!

 

Thanks,

Michael


I'm only looking at the png right now as this computer doesn't have labVIEW; however, if you can branch the boolean output stemming directly from the STOP control, they should stop at the same time. It looks like there is two different booleans or it goes through a subVI which could allow the second to go for one more iteration?

0 Kudos
Message 2 of 6
(2,586 Views)

Hi Michael,

 

the lower loop executes another iteration before stopping.

You need to start to THINK DATAFLOW!

 

There is a (kind of) race condition in your code!

You read the notifier, it's still FALSE. Then your lower loop will do it's task and will wait for a certain amount of time. While this wait executes your upper loop is setting the notifier to TRUE. BUT: that notifier is read only after the next iteration of the lower loop start - after the wait is done! Now you read the TRUE state, but again you need to wait (as you programmed it)!

 

What changes should I make so that both loops will terminate simultaneously when the STOP condition is met?

Generic answer: read the notifier more often!

Specific answer: read ithe notifier in the inner FOR loop of the lower loop. Stop that FOR loop when the notifier is TRUE. Don't wait when the notifier is TRUE!

Also: use WaitForNotifier instead of NotifierStatus. Use it's timeout instead of additional wait functions!

And cleanup your block diagram!

 

(For this simple VI I would even use an indicator in the upper loop and its local in the lower loop. But then notifiers allow you to modularize your code into several subVIs…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 6
(2,585 Views)

Hi GerdW,

 

Thank you for your reply! I'm using the Wait functions to time the iteration counter, so I can't replace them. If a STOP condition is added to the FOR loop, won't the WHILE loop run an additional time (i.e. counting the cycle) before stopping?

0 Kudos
Message 4 of 6
(2,560 Views)

Notifiers are tricky, until you get the idea that you are supposed to not use Get Status, but Wait on Notification.  I just answered another question about stopping parallel loops and included a snippet where I stopped 4 with a single Stop button (and could have stopped more) using the Tag Channel Wire, which performs a function similar (but easier to understand, IMHO) to the Notifier.  As they say in Pittsburgh, "Check it Ahht" here.

 

Bob Schor

0 Kudos
Message 5 of 6
(2,533 Views)

Your design is completely wrong. You are trapping the lower loop for long time in the inner FOR loop, during which time the notifier is not even read and stopping is thus not possible.

 

All your code is slow, and it is probably possible to do everything in a simple one-loop state machine. Don't over-complicate things!!

0 Kudos
Message 6 of 6
(2,532 Views)