From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Representation of while loop in if statement in block diagram

Hello, maybe my question isn't smart but I am a beginner:
how can I use while loop in if statement? I mean how to build block diagram based on pseudocode:



if q<100

{

    while (q<110)

     q=q+1      //1 iteration per second

}

I've tried to do it with event structure but it has only event when boolean is changing value (problem - in my case I want it to be done only when changing value from 0 to 1 (q<100), not otherwise), case structure (problem - after 1 iteration case (q<100) isn't fullfilled)



My real case is pumping system which turn on the pump every time the flow is lower than 100 l/s and stop pumping when flow is 110 l/s

Thank you in advance.

0 Kudos
Message 1 of 10
(4,575 Views)

If you are a beginner, have you viewed any of the LabVIEW Tutorials?  Taken any classes in LabVIEW (i.e. at school)?

 

You should have learned about the Case Statement, which mimic an If statement (if driven by a Boolean comparison, e.g. q < 100) or a Switch Statement (if driven by a integer numeric).  What goes inside the Case structure is what you do in a Case (such as the "True" case of "q < 100").  One thing to remember about a While loop is that the loop always runs at least once, since the test to stop (or to continue) is applied after everything inside the Loop has run.  You also have to remember the rules of Data Flow (and if you don't know what Data Flow means, go back to the first Video Tutorials).

 

Often, things that vary within a Loop are carried in Shift Registers -- the concept of a "Variable" (like "q") in text languages is, in LabVIEW, frequently carried in "wires".

 

Bob Schor

0 Kudos
Message 2 of 10
(4,534 Views)

Hi,

  As a beginner be familiar with basic concepts in labview which is vastly available. For your query, here is a simple block diagram which runs when q<100 and stops when q>110. This is the basic concept. If you can give further information clearly, it will be useful !!

 

Hope it helps 😉

Best Regards,
Dhans 😉
Kudos are welcome 😉
Aspirant Labview Programmer (Labview 14) 😉
0 Kudos
Message 3 of 10
(4,520 Views)

The case statement is directly analogous to a "select case" that you see in just about every text language.  It's basicaly an "if-then" on steroids.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 10
(4,509 Views)

@wisniewski.energy wrote:

 

My real case is pumping system which turn on the pump every time the flow is lower than 100 l/s and stop pumping when flow is 110 l/s


I would suggest you try to solve the real case, instead of a problem that seems to have very little to do with it. 😄

All you need is a state machine that reads the flow at regular intervals and turns the pump on depending on the measured flow and the current state of the pump.

0 Kudos
Message 5 of 10
(4,504 Views)

@wisniewski.energy wrote:

Hello, maybe my question isn't smart but I am a beginner:
how can I use while loop in if statement? I mean how to build block diagram based on pseudocode:

 

if q<100

{

    while (q<110)

     q=q+1      //1 iteration per second

}


Your answer is in your question. If you want a while function in an If statement, place a while loop in a Case structure. 🙂 From your description, though, this wouldn't get you closer to your goal. As Altenbach mentions, a State machine is probably the answer. (It's basically a case structure of States inside a while loop that sends/selects which state to do next, check Examples and New from Template)

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 10
(4,489 Views)

Hi

 

Below i placed example code that is representing functionality described by your C code.

You can play with it and modify as you wish.

example.png

 

Please also read these documents to better understand how this example is working:

http://www.ni.com/white-paper/7588/en/

http://www.ni.com/getting-started/labview-basics/execution-structures#Case Structures

http://www.ni.com/getting-started/labview-basics/shift-registers

 

Please write a feedback if my answer was helpful.

 

Regards

 

Message 7 of 10
(4,463 Views)

@sprzysta wrote:

 

Below i placed example code that is representing functionality described by your C code.

 


This does not solve the real problem and is also not equivalent to the text code because q does not change here. It is generally a very bad idea to trap code inside inner loops for long periods of time, making it unresponsive to user intereaction.

 

The OP needs to (1) solve the real case. If external hardware is not available, a (2) simulation subsystem needs to be implemented that adjust the reading according to the states of the system.

0 Kudos
Message 8 of 10
(4,439 Views)

Here's a very primitive simulation system. maybe it can give you some ideas.

 

(For easy demonstration, it runs faster, so please adjust the timing if needed. In the real system, just replace the orange shift register and associated code with a reading from the flow gauge)

 

 

Download All
0 Kudos
Message 9 of 10
(4,435 Views)

Hello, 

Yes i need this type of stuff in my coding. I just implement till now the interfacing between the arduino and labview. I want to implement now this code into my arduino and control my arduino through one button which should be in Labview. Can you help me with VI.

 

Thanks 

 

 

0 Kudos
Message 10 of 10
(3,326 Views)