LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple boolean switch question

I'm quite new at using structures (while loops, etc) in LabVIEW, so here's a very oversimplified question (hypothetical, but I think will help me understand what I'm doing). I have 2 on/off boolean switches, each one controls 2 identical LEDs which display if switch is on or off. One set of 2 LEDs (one from one switch, one from the other) should update every 1s, the other set of 2 updated every 5s. How do I accomplish this most efficiently?
 
I attached a picture of my first try, this lets me time the udpates individually but of course it's wrong since I then learned each while loop only takes the input when you first click run, and doesn't keep checking the input after that point. Thanks!
 
 
0 Kudos
Message 1 of 12
(3,626 Views)
ps, I have an internship in Germany this summer so that's why you'll notice my German LV version, and my question has nothing to do with the other Dan that also just posted asking a question about something to do with boolean and led's 🙂
0 Kudos
Message 2 of 12
(3,621 Views)
In this case.

Put the controls in the upper loop and create a local from each control and put them in read mode in the bottom loop.
Regards,
André (CLA, CLED)
0 Kudos
Message 3 of 12
(3,620 Views)
That makes sense, I'll try it now and let you know if I got it to work, thanks!
0 Kudos
Message 4 of 12
(3,610 Views)
The problem in your diagram is that the state of the switch is read out side the loops. So this will pass in whatever the initial condition when you run the VI to the loops and keep writing the same value on each iteration.
 
In a simpler way, what you can do is to put the two switche terminals inside one of the loops and the other loop can be using their local variable.
To create a local variable right click on the terminal, select Create->Local Variable. Change the variable to read from write. To do this right click and select 'Change to Read'.
 
Hope it helps...
0 Kudos
Message 5 of 12
(3,605 Views)
You only need a single loop and you don't need any local variables.
 
Place all controls inside the loop and spin the loop every 1000ms.
 
Update one set of controls at every iteration and the other set of controls every 5 iterations using a case structure.
 
 
 
 
 


Message Edited by altenbach on 06-09-2008 01:25 AM
0 Kudos
Message 6 of 12
(3,597 Views)
Hi Dan,

you can put all controls/indicators in one loop to avoid locals (which you should do anyway!). To update the second set of indicators only every 5secs you can put them in a case structure where the TRUE case is only executed every 5th iteration...

Remember: In LabView the wire is the variable and most often (some may say: never!) you don't need any locals.

@altenbach: seems we have the same thoughts on this matterSmiley Very Happy


Message Edited by GerdW on 06-09-2008 10:27 AM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 12
(3,596 Views)
Good responses, I tried with locals and got it to work (attached) but if avoiding them is better then that's good to know, thanks for the picture example.
 
Why is it better to not use local variables, what are the disadvantages?
0 Kudos
Message 8 of 12
(3,587 Views)
Hi Dan,

using locals may lead to "race conditions" (problems due to timing of read and write operations). They also create data copies which may be a problem when handling big data structures.

For your attached picture: you don't need to write to locals in the right (producer) loop, the locals in the (consumer) loops are always tied to the control! You may want to read the manual for consumer-producer-pattern too!?
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 12
(3,575 Views)

Using local or global variables can cause "race conditions" (http://zone.ni.com/reference/en-XX/help/371361D-01/lvhowto/race_conditions/) which can be very difficult to debug. It is also difficult to control timing when using too many local variables, which is half the part of creating a VI in LabVIEW. I personlly never use local variable unless I have some very strict condtions to control the timing. It's best practice to limit or eliminate the use of local variables in your programs. It may be a bit more difficult to write, but is more effective in the long run.

 
0 Kudos
Message 10 of 12
(3,572 Views)