LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Alternating signals

Hello all

 

 

I'm currently trying to figure out how to alternate signals again. In my previous question I got some nice answers, but after some reconsideration the one I picked to be good enough, isn't anymore.

This is the original design (thanks to Yddet):

valve alternation oud.jpg

The alternation works fine here, but the issue lies in what I want to achieve.

 

Basically I want to open and close valves, alternating when some alarm is on (hence the case structure). 

With this design I didnt take in account the time for a valve to open or close, and I don't want the two valves to be open at the same time. So what will happen here is that while one valve is closing the other one will already be opening.

 

I tried to use a timed loop sequence (inside the case structure) to solve this, which seems to work pretty fine. The only problem is that I can't stop the VI and it seems that even when the alarm shuts down (so case goes to false) the loop continues. 

My current design: (I had a stop button connected to the stop condition, but it somehow seemed to skip it.)

valve alternation.jpg

 

Booleans 1 and 2 indicate that the valve is opening, 4 and 5 indicate that the corresponding valve is opened, 3 indicates that the alarm is on.

 

I'd also like to control the time that the valves are open, while the opening and closing time should be a constant (but which has to be set aswell).

For example: Start with opening valve 1, which takes 10s, then keep it open for 10s, close it again (again 10s) after that start opening valve 2, which would take 10s again, keep open 10s, close 10s.

This all should be automated, starting from when the alarm goes on.

 

However it should be possible to interrupt when the alarm goes off (back to false) or when the stop button is pressed.

 

(The manual operation of the valves is already fixed.)

 

It is important that the valves are never open at the same time and that they can stay open for a 'long' time.

0 Kudos
Message 1 of 15
(4,232 Views)

Hi XebeXUC,

 

whenever you have certain states in your algorithm (like valve1ON, valve2OFF, …) you should immediatly think of a state machine!

Convert your big block diagram fiull of local variables (and totally missing THINK DATAFLOW!) into a proper state machine…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 15
(4,215 Views)

The reason your VI won't stop is that your inner most timed while loop has nothing wired to its stop terminal.

 

It will run forever.

0 Kudos
Message 3 of 15
(4,210 Views)

I had it connected to a stop button, but pressing the stop button still didn't stop the loop...

0 Kudos
Message 4 of 15
(4,207 Views)

Could you help get me started on this? I'm not really familiar with state machines.

@GerdW

0 Kudos
Message 5 of 15
(4,205 Views)

@XebeXUC wrote:

I had it connected to a stop button, but pressing the stop button still didn't stop the loop...


It would have.  Something else must have been wrong with the code.

0 Kudos
Message 6 of 15
(4,194 Views)

Hi XebeXUC,

 

to get you started on state machines: here or here

 

Are you sure your inner loop didn't react on your stop button? Do you have any proof of "bad behaviour"?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 15
(4,191 Views)

Be descriptive with your boolean names.  As a forum user from whom you are seeking help, when I see Boolean1 Boolean2, I don't know what that means and what is its purpose.  But if I see "Valve 1 Open" and "Valve 2 Closed", there is no doubt.  You will get more useful information if you provide useful information.

 

When you get to the point where you are programming the delay between opening and closing, do not use a Wait function.  Instead, create a separate state in your state machine called "Opening Valve" (or something equally as descriptive) and use an Elapsed Time VI.  If the 10secs has elapsed, go to the next state.  Otherwise, tell the state machine to iterate but stay in the same state so that the timer continues to be checked.  In other words, don't put long running loops in your states.  Instead of using a loop structure, create the effect of a loop by calling the same state.  This will allow your UI to remain responsive and your stop buttons will work properly.

aputman
0 Kudos
Message 8 of 15
(4,184 Views)

So basically I would start with saying 'start open valve 1', which takes 10 seconds, then I'd output that signal, add 1 to the state machine to open the next state which would be 'valve 1 open', which would take another 10 seconds, add again to close, and repeat for valve 2? 

and then I have to somehow reset it so that i'd start over with 'start open valve 1'?

0 Kudos
Message 9 of 15
(4,171 Views)

But you don't "add 1".  Create a typedef enum that contains a list of all your states.  When you finish a state, you use a constant of the enum to tell what the next state is that you feed into the shift register.  You can make decisions as to whether you go to Step A or Step C or whatever.  When you get to the end and you want to start over, you just put in an enum constant that is set to go back to Step 1.

0 Kudos
Message 10 of 15
(4,157 Views)