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: 

Programming Total Flow

Solved!
Go to solution

Hello all,

 

   This is my first time programming in LabVIEW and I am slowly grasping the concepts, but have found myself stuck on a (more than likely) very simple task. I have two flowmeters hooked up in series that I am recieving flow rates from, I then take the average of the two for better accuracy with our readings, and display that value on the front panel.

 

    Here's where I start having issues. The flow through the meters is not continuous, we will turn the flow off and on multiple times throughout our tests. As of right now that is fine and I only see my average flow when the meter is on and 0.0 when there is no flow, since it is recording constantly. Albeit, now I need to display the total volume that passed through the flowmeter during it's operation.

 

    So for example, we turn on the flow (draw) at 3.0 GPM for 0:02:30 then the output would read 7.5 gallons and would reset that total to 0.0 before the next draw began. So in principle we would only see the total for each set of draws. Although, it would be useful to also keep a running total of the overall volume drawn during the entire test.

 

     I know that in order to create a running total I can use a while loop and a shift register. This, I think,  will give me the total gpm over a span of x cycles, which I could then divide by the number of cycles, and output the average flow rate in 1 minute (say flow1). Following that I could have the program reset and repeat that loop until another minute has passed and add that number (flow2) to a running total for my overall volume? I do not know how to start/ stop the while loop based on when I am drawing, unless I somehow record the 0.0 flow and when the while loop sees this it stops? I am sure there is a different (better) way of doing all this that is constantly running and recording?

 

     Any advice would be appreciated, thank you for your time.

0 Kudos
Message 1 of 15
(3,912 Views)
Solution
Accepted by topic author M_Blaylock33

I would use the 0 GPM as your marker that the draw is complete.  Yes, keep a shift register for the amount of flow.  Also keep a shift register for the number of samples taken.  You will also need to know your sample rate.  It is just a simple multiplication from there.  A simple state machine should be able to easily handle this.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 15
(3,901 Views)

Now i dont know how you're reading your values, if it's through some daq (which'll make this easy) or some serial communication (which'll make it slightly harder).

You're right about the running total, you only need to add a Status/running flag and some constant reading of the values. 

 

You can e.g. have a flowmeter reading loop that only updates Current Flow and Total volume. If, e.g. you read this once a second you simply add GPM/60 to the total creating a simple integration. (If using a daq you can setup 1kHz sample rate and use it as a timer while getting better values.)

 

The only thing needed then is to zero the total as a new test starts. One way of doing that is to use a Functional Global/Action engine(/Global variable) or simply react to the Status flag. 

You can e.g. set the flag to Start and the flowmeter loop can react to that by zeroing the total volume and change status to Running. When you're done you set status to Stopped which makes the flowmeter loop ignore updating the total (leaving the last total on screen until next test).

 

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
Message 3 of 15
(3,898 Views)
Something else to be careful about is the definition of 0. Remember that floating point is an approximation. So 0.0000000001 may be very small, but it is not zero -- though it may look like it in an indicator or on a graph. Can you get a signal from the valve indicating when it has closed and flow has stopped?

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 4 of 15
(3,883 Views)

"A simple state machine should be able to easily handle this."

 

He beat me to it. Defo the way forward.

Message 5 of 15
(3,844 Views)

Hello everyone,

 

   I apologize for my lack of punctality in replying to this thread. I was working on another project, and then out of town for a while. All previous comments were helpful, I agree that using a state machine is the way to go. I started back on trying to incorporate this today, and I am running into issues with how I have it set up. I have posted a picture of my code (be easy, this is my first time with LabView).

 

    When I run the program a couple things happen: 1) The rest of my program stops running as soon as I open the solenoid and start the draw (start the while loop). 2) The iterations continue even after I close the solenoid. So my program stops working as soon as I go into this while loop, and the loop will not stop when it should.

 

    In the picture you will see that I am taking the draw flow and converting it into an interger to account for the floating point (I thought), and then changing that to a boolean value of True or False if it is zero or some amount of flow. That then controls my state machine parameters. I am taking the average flow rate over 1 minute (as long as the cycle time is 4 seconds) and adding that into my loop with a shift register to create the running total. The total draw flow for that minute will give me my volume drawn. Although, it would be nice to be able to do this where it's not dependent upon my cycle time (since I might want to change that later). Just after taking the screen shot I added in a Wait timer in the while loop with a control of 60000 ms or 1 min.

 

     I imagine my biggest problem is in how I am starting and stopping the loop, and as before any help would be greatly appreciated. I will try to respond much faster this time around.

0 Kudos
Message 6 of 15
(3,744 Views)

You've got dataflow problems.

 

First, that still isn't a state machine.  With a state machine, there is an enum that is passed into a shift register.  That enum connects to the case structure.  That way the previous loop iteration determines what case executes in the next iteration.  You aren't doing that here.

 

Second.  Your loop is either going to run one time, or neither.  Most of the time newbies make a mistake and wire a boolean into a loop and connect it to the conditional terminal.  You didn't do that directly, because your boolean drives a case structure which then determines the run/stop condition of the loop.    You've effectively done the same thing.  If the boolean coming into the loop is true, the true case sends a True boolean to the loop conditional terminal and the loop runs forever.  It can never stop without aboriting because that value at the loop tunnel will remain true until your outermost loop of the VI (not shown in your image) is able to iterat again.  If you have a false coming in, the false case executes, it passes a false boolena to the "Continue if True" terminal, then the loop is done after only one iteration.

Message 7 of 15
(3,731 Views)

1) Your thought process for data flow is flawed.  That loop will run forever if that I32 is not equal to 0.  Since that boolean is the only thing that can stop the loop and it is set outside of the loop.

2) This does not look like a good state machine.  In fact, I'm not even seeing the point of that while loop.  You should have a state for checking the amount of time and accumulating your sum one sample at a time.  You should not have any (long) loops inside of your state machine.

3) The Dynamic Data Type is very dangerous to have in any real application.  You might want to change to using the actual DAQmx API.  Then we will actually know what the data is.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 15
(3,729 Views)

Round 2: Thank you both for the advice, I have modified my program to account for a few of the things you mentioned. I see what you are saying about needing to feed the enum into the shift register, that way the loop will see a "True" or "False" with each iteration. I was using the case function in the second while loop because that was how I had seen it done in examples. Now I see that I can simply attach a shift register to my outer loop and no longer need to run two loops in parallel. So, things I modified:

 

1) Removed the inner-most while loop and created the shift register on the outer (main) loop.

2) Instead of converting to an interger to destroy the floating point I am converting to a Boolean of "False" as long as the value is greater than 0.2.

3) I converted the data to scalar instead of the dynamic data type.

 

Result: My program will run and record the average flow rate when the draw is on and stop recording when the draw is shut off. (Yay!) Issue now is in my timing. The readout is multiplying my total gallons each minute by 10, because of the shift register. So, instead of getting say 1 gallon in a minute, it is reading 10 gallons. Is there any way I can add a timer or something else in my case to keep the total to what it should be?

 

Thank you for all your help with this, it is a great learning tool before I start working on my larger more complex program; that I am sure I will have to start another thread for when the time comes.

0 Kudos
Message 9 of 15
(3,674 Views)

The shift register isn't multiplying numbers by 10.  Something else is.

 

You have some scary looking feedback nodes in there.  It really isn't clear what you are doing with them.

 

But if you need to know how much time has elapsed, then add it to the loop, store the time the flow starts in a shfit register and compare it to the current time.  Divide your total flow by the time that has elapsed.

Message 10 of 15
(3,661 Views)