Showing results for 
Search instead for 
Did you mean: 

Sequencing Within Data Range Help

Hello Labviewers!!


Well, I've found myself stuck again.  We've assembled a system comprised of an air compressor, a CO2 Adsorber (carbon dioxide remover), and a storage tank to hold the CO2-free air.  My job now is to develop code which will automate the process of opening a series of solenoid valves (by firing relays) thus allowing for the creation and storage of CO2-free air.  I think I've got the logic straight in my head but I'm having a hard time figuring out how to code this in LabVIEW.  The system should operate like this:


A pressure gauge is continuously monitoring the pressure on the storage tank.  I would like the storage tank pressure to stay between 30-50 psi.  If the pressure reaches 30 psi I need to open a solenoid, wait for 1 minute, and open anther solenoid and wait.  At this point the system should be adding pressure to the storage tank.  When the pressure in the storage tank reaches 50 psi I would like to close the solenoids and wait for the pressure to drop down to 30 psi before doing anything more.  


My problem is that while I can write code which will open the first solenoid, wait for 1 minute, and open the second solenoid, I don't know how to program "wait until the pressure reaches 50 before moving on."  If I try and put the whole thing in a while loop I encounter the problem of having the 1 minute wait occurring more than once (I only need do this 1 minute wait once per cycle).


Any ideas or suggestions will be appreciated.




0 Kudos
Message 1 of 14

I so not know if you can have both operation running at the same time or not. I will assume it is possible.


I would create 2 loops within the application. One to fill the air pressure 50 and one to release the air. That way they will not hold the proces up. Next, I would have the timing loop faster than 1 minute, in your particuliar case every 10 second. This should give a finer degree of control to turning the pressure on or off. If you don't, you can be off by about a minute versus 10 seconds.

0 Kudos
Message 2 of 14

Thanks for the reply.  I suppose I should clarify that I won't be direclty controlling the air pressures in the application, just reacting to the pressures.


I think I need to use a series of shift registers and case structures but just don't have that much experience with them.  Here's another look at the logic I'm trying to code for:



if (pressureReading <30)&&(isAdsorberRunning==false){







if(pressureReading >50)&&(isAdsorverRunning==true){





Once again any help is greatly appreciated.







0 Kudos
Message 3 of 14

Hi Mike,


What you are looking for is a State Machine. This is a very common LabVIEW design pattern.


There are tons of resources available on State Machines including many videos - which may be the fastest way to learn them. Do a google search on "labview state machine video". Of course also search the National site for more info.


> I think I need to use a series of shift registers and case structures


You are on the right track with this statement. A State Machine usually uses a shift register to keep track of the state and a series of case structures that contain the different state actions. You determine which state to go to next in each state (case).



For your application you would have an Initial State that checks your conditions (pressure reading, isAdsorberRunning). From there you decide which state to execute (or remain in the current state if no action needs to take place). 


Check out the resources and give it a try. If you have trouble -  ask questions. Posting your problem code often gets quicker and better answers.




Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
question. Give "Kudos" to replies that help.
Message 4 of 14

Hi mike,


Also rather than using the "wait" 1 minute function use the" elapsed time with a reset" express VI (or code your own once you see how it works).  This will enable you to remain in the state and monitor pressures while the elapsed time is still running.  When elapsed time has occured move onto next state etc. By doing it this way you avoid using the wait function which inhibits the monitoring capability of the state machine (moore Vs mealy maybey??)



LabVIEW 2012
Message 5 of 14

Thanks for the replys.  I'll look into State Machines this morning and I'll keep in mind that I should use the "elapsed time with a reset" expressVI.  I'll let you know how it goes after I have some code.


Thanks again,


0 Kudos
Message 6 of 14

Hi Craig,


I've been fooling around with the Elapsed Time Express VI but so far I haven't been able to make it work properly.  Do I need to somehow tell my code to wait until the "Elapsed Time (s)" has reached 60 or until the "Time has Elapsed" Boolean be set to true?  How does one go about doing this?  Also, when you say to use a reset should I be using the "Auto Reset" feature?


Thanks again for the help,


0 Kudos
Message 7 of 14

Hi Mike


Lets concentrate on this state first for example lets call it S2.


You should use the "elapsed time" OP and check if it is greater than your limit say 60 Secs.  This gives You one boolean/logic condition.  B1

You also check the pressure and if that is greater than your limit this gives you another logic condition.                                                  B2


 Now you can determine which state to goto next using these Booleans and some logic gates (AND OR etc) as follows.

No matter what, "the outer loop iterates" and Next state always occurs.... Even if it is the same state as we are already in.


B1     B2      Next State

F       F        S2       <---Lets say it stays in this state as we havent gone over a minute or the pressure

F       T        S2       <---Stays in S2 Still As B2 hasnt gone over a minute still etc etc

T       F        S3       <--- Goto diff state

T       T        S1       <--- Returns to default state (Where we set a flag / boolean to reset the elapsed time before going back to S2 for example.


So you decide when your program exits the current state (S2 in our little demo)


 RESETTING the timer

The state that goes into S2 Should set a Flag / WIRE / Boolean to reset the elapsed time vi.  You carry information between states using shift registers 🙂


Sorry I can't be more help but I am at home now and havent got LV on this comp :s.




Message Edited by craigc on 26--01-2010 07:54 PM
LabVIEW 2012
Message 8 of 14

Ultimately, you have to look at the pressure in the tank periodically.  (poll it by reading it).  When it goes below 30 for the first time, operate the state "start filling".  When the pressure reaches 50 ... operate the state "stop filling". 


The reading of the tank is an event (you could actually do that in a timed loop....or use the timeout default to set the polling time)...the states are actually cases called by using a queue out of the event.  You can put whatever code you want to in the case structures to handle the under and over pressure events.


So you have two event loop doing the polling...and a state loop doing the case functions called for by the event loops...


Or, you could just put the pressure reading in the event loop, and call a state for figuring out what needs to be done.  That state would then list the state names for all the stuff that needs to be done.


probably clear as mud.


Hope that helps...



Message 9 of 14

Thanks again for the help everybody.  I have developed some code which is working fairly well but I would like to take the more sophisticated approach Craig has mentioned and try to work in the Elapsed time with reset express VI.  In the meantime, have a look at the code I've developed and let me know what you think.


Craig, given the structure that I've set up here, do you have any ideas as to how I would add the Elapsed Time VI?


Thanks again,

0 Kudos
Message 10 of 14