From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Time delay while loop before stopping the loop

Solved!
Go to solution

 

Hi All,

 

I modified this code from one of the example in the forum. I forgot which thread. Original file name is "loop speed control.vi"

 

I want to measure pressure and compare with target pressure. Once the pressure reading is higher than the target pressure, I hold the output high for 5 seconds and turn it to low. 

 

When It goes back to low, I want the to exit the loop or when I pressed the stop button. I do not how to do this one. Please help.

 

Thanks

 

 

0 Kudos
Message 1 of 7
(3,281 Views)

Hi Havevun,

 

Try using a case structure with a couple different states. For instance "Measure", "Hold" and "Exit". This way you are only checking for one condition in each state.

0 Kudos
Message 2 of 7
(3,277 Views)

Yeah, you definately want a state machine.  This probably would become very simple when you break down the states properly.


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
0 Kudos
Message 3 of 7
(3,269 Views)

Hi Gregoryj and Crossruiz,

 

Thank you it really helps. The logic is cleaner than my previous. 

 

There is this thing that I need to fix.

 

Motor is used to increase pressure

Valve is to dump the pressure. 

I used delay to hold thre pressure once it reach the target pressure. (TRUE condition). 

 

Pressure readings fluctuate.

The problem that I have here is that once the pressure reading is higher than the target. I do not want the code to return back to "False" (pressure reading is lower than target). 

 

Please advise.

 

 

0 Kudos
Message 4 of 7
(3,241 Views)
Solution
Accepted by havevun

I can't view your VI (I'm using LV 2014). Please see my attachment for an example. See what happens when you make the value of numeric >= 1. Turn on the highlight execution if it does not make sense.

0 Kudos
Message 5 of 7
(3,225 Views)

Thank you, Gregoryj. 

 

It works like a charm

0 Kudos
Message 6 of 7
(3,182 Views)
You're welcome. As a side note, it is best practice to type define the enum, so that if you change it, it will update everywhere. I didn't do that here to limit the file dependencies.
0 Kudos
Message 7 of 7
(3,173 Views)