LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Repeated sequence in a case structure

Solved!
Go to solution

Hi everyone!

 

I have a problem about repeating a task in a case structure. I want to control two LED indicators in a sequence until I change the case.

 

 

Here is a clearer explanation of what I am trying to do:

 

LED#1 ->on (wait 100ms) 

LED#2 ->off (wait 100ms)

LED#1 ->off (wait 100ms)

LED#2 ->on (wait 100ms)

....

 

How can I do this? In the vi I uploaded, there is a main while loop and a case structure in it. If the case is false both LEDs are off. If the case is true then LEDs should be as above. 

 

Thanks for helping!

0 Kudos
Message 1 of 24
(5,065 Views)

It might help to better understand what your end goal is. Is this the end of the program, Blinking LEDs? Is this a homework assignment?

 

Your VI won't work because you're not understanding dataflow. The LED values don't trigger the True or False values until the data gets passed through the wires to the indicator terminals.

LabVIEW programming is based entirely on dataflow and parallelism. This is incredibly powerful and has lead to its success over the years (coupled with the graphical programming), but is usually one of the first things that new developers stumble over. The Highlight Execution feature is a great way to watch how your application utilizes dataflow.

 

 

After you understand what's wrong with your VI, you may want to make it work better. In LabVIEW, you rarely need to use a sequence structure and you shouldn't because it leads to duplicating code and non-scaleability. The way around this is to use a For loop that loops 4 times where each loop assigns different boolean values according to your instructions above.

 

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 24
(5,050 Views)

This sounds like an incredibly easy state machine to put together.  Have you looked into that architecture?

0 Kudos
Message 3 of 24
(5,034 Views)

Honestly, I think state machine is too complicated for this specific application if all he needs is the LEDs to flash in that order once. If he plans to grow the code, then yeah, state machine.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 4 of 24
(5,021 Views)

My actual VI's screenshot is attached. This is a lab project and I am controlling a set of valves and pressure regulators via Arduino and Labview. The LEDs stand for the valves in this case. I just wanted to simplfy it for you so that you guys could play with the VI and guide me.

 

There are 4 cases for the valves. 

 

Case 1 = manual on/off

Case 2 = auto control (if a condition is satisfied the valves are on/off just for once)

Case 3 = This is the one I asked. The valves should be on/off for a period of time, until I move to case 4.

Case 4 = all valves are off

 

Now do you have any suggestions? 

0 Kudos
Message 5 of 24
(5,009 Views)

I did it after some thinking 🙂 It is really easy Smiley Very Happy

Message 6 of 24
(4,961 Views)

@akifyalcinkaya wrote:

I did it after some thinking 🙂 It is really easy Smiley Very Happy


Thinking is always good.  Sometimes it helps to write down what you want to do in a way that your best friend, who does not know LabVIEW, will understand the problem -- for more complicated tasks, such a step can help clarify and organize your thinking.

 

Bob Schor

Message 7 of 24
(4,931 Views)

@akifyalcinkaya wrote:

I did it after some thinking 🙂 It is really easy Smiley Very Happy


I would recommend to do some more thinking (yes, it's easy!)

 

  • Don't maximize the diagram to the screen. That's very annoying on large monitors.
  • Have you looked at the CPU usage when the button is OFF while the VI is running? It uses 100% (!!) of one CPU core, spinning the loop as fast as the computer allows while the VI is not doing anything useful. THis make all other programs running on your computer starve for resources. On a laptop, this will also drain your battery.The wait belongs outside the case structure!
  • You could make the output tunnels going to the indicators to "use default if unwired" now you don't need the FALSE diagram constant
  • For simple code like that you don't need a case structure. No hidden code when looking at the diagram!

Here's a possible alternative implementation.

 

Message 8 of 24
(4,916 Views)

Thank you for the recommendation but my actual code is a bit more complicated and I need a case structure there. You can see the screenshot in the attachment.

screen.png

0 Kudos
Message 9 of 24
(4,902 Views)

Ok, that's even worse because now you have a race condition.

 

Your "initial mass" global variable is read and written in parallel, but the immediate outcome differs depending on what occurs first.

Why is this a global variable at all? Are ther other VIs that also access it? For local use, you would just use a feedback node to store the reference value.

 

Please attach your actual VI, looking at a code picture never gives the complete information.

 

Why is there so much duplicate code??? You could calculate 255/80 once before the loop and multiply the controls with the result. Why do you think you need to do that three times per iteration?

You could even use a arrays of controls/indicators.

Your code is also broken because some output tunnels are not fully defined.

Your shift register serves no purpose because you never use its output.

0 Kudos
Message 10 of 24
(4,890 Views)