LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LABVIEW code to switch a 4-port, 2 position valve

I am building a test setup where I need to change gas flow by operating a switch valve.  I've been trying to write some code, the VI runs but doesn't really do what I want.

 

I have an NI 9185 chassis with an NI 9401 Digital I/O module.  I have a Vici 4 port, 2 position valve (manual, p3 for configuration) that I want to be able to switch on and off.  The test is run with the Vici valve in the "A" position and then  after certain conditions have been met I want to switch to the "B" position.

The conditions to be met will either be determined by time or other experimental observations, so the code doesn't need to do that. 

 

See the attached VI, I got stuck.  It does seem that when I start with the valve in "B" position, I can get it to switch to "A."  But I cannot get this program to switch to "B" after starting in the "A" positon like I want.  Any advice would be appreciated! 

0 Kudos
Message 1 of 8
(361 Views)

Please attach your vi code, save it for Lv Version 2020 or older

 

0 Kudos
Message 2 of 8
(340 Views)

It shouldn't be necessary to change anything since "Two Position With Stops" is the default mode, but double-check that your valve is configured this way. You can use the remote control to verify it by following the menu diagram on page 23 of the manual. Once set, it will be permanently saved to the actuator's memory.

 

You mentioned getting stuck when trying to switch from "A" to "B." Based on what you described, this might be a physical wiring or pin assignment issue. I'd suggest adding an indicator to your program to verify if there are any errors when reading the states of pins 4 and 6. You could also use the manual remote to monitor the valve's position. Make sure that you're energizing and de-energizing pins 3 and 1 correctly. It’s possible that pin 3 might still be energized, preventing the switch to "B."

I have experience with the same actuator, though I control it using an Arduino with the Hobbyist Toolkit. I’ve attached my code here in case it’s helpful.

-----------------------------------------------------------------

If you can not measure it, you can not improve it.
- Lord Kelvin
0 Kudos
Message 3 of 8
(320 Views)

Hey thanks for the reply, lets see if this works, having issues uploading my VIs at the moment

0 Kudos
Message 4 of 8
(313 Views)

There are no actions to execute in the case structure when the switch condition is False. That's probably when you need to go from B to A.

On a separate note, there's no need to read and compare the boolean state every time. Also, an event structure takes care of that. Not critical here, but more elegant and efficient for larger programs. Best to build the habit now.

-----------------------------------------------------------------

If you can not measure it, you can not improve it.
- Lord Kelvin
0 Kudos
Message 5 of 8
(304 Views)

@drShredz7684 wrote:

Hey thanks for the reply, lets see if this works, having issues uploading my VIs at the moment


There are plenty of things wrong with this VI.

 

  • When the toogle is unchanged, you have a greedy loop, spinning as fast as the computer allows, constantly "starting" the same task over and over.
  • Your shift register in not initialized so it will remember the state of the previous run.
  • Stopping the task after each write seems silly.
  • What is the significance of the 100ms wait? (This won't determine the time between T and F writes, but runs in parallel)
  • If you stop the VI while the False case is active, you will try to close an invalid task (use default if unwired). You need to wire across all cases.

See if this can give you some ideas.... This will write the new value whenever the toggle changes state.

 

(definitely needs more work, for example you probably would want to write F when stop is pressed or ensure the correct output before the toggle is touched by the user, etc..)

 

altenbach_0-1731431663930.png

 

 

I and not a "hardware guy", so there could be some omissions. I Strongly recommend to look at the shipping examples and the learning resources listed at the top of the forum.

 

0 Kudos
Message 6 of 8
(299 Views)

Thats why I posted it here ha.  I have been going through the CORE 1 courses and excercises they are really helpful but I still have a ways to go to get through all of it.   I was attempting to use some  AI my company developed to help with some of the LABView code writing initially, but I don't think it does this very well. 

Its a lot cleaner, and got rid of some of the silly things like stopping the task each time.  I still can only get it to switch from the "B" to "A" position, and not the other way.

 

I've taken what you put together, and after looking at what cyclotronist posted, it seems like I am not getting the pins to fire in correct sequence to do this.  I'm trying to follow his Vici valve actuator VI since its the same hardware I have.  If i am interpreting this correctly, he is initally writing the initial state of the output channels to initialize them, then reading the specific ones in question (within loop) and then writing the new updated values in the event structure.  

0 Kudos
Message 7 of 8
(240 Views)

You forgot the shift register I used. There is no reason to duplicate all that inner code. You only need to write the line when there is a new value, so the false case should be empty.

 

Also:

  • Comparing the toggle to a true constant with <not equal> is just a NOT.
  • In the false case, you do a "false <not equal> false", equally silly.
  • All you currently do is write a TRUE in the TRUE case and a FALSE in the FALSE case.

 


@drShredz7684 wrote:

it seems like I am not getting the pins to fire in correct sequence to do this.   


You currently have only one pin (i.e. a boolean array with one element), so I am not sure what you mean by "pins in the right sequence"

 


@drShredz7684 wrote:

 some of the LABView code writing initially,   


After core 1, most people know that it is LabVIEW. Note the lettercase.

0 Kudos
Message 8 of 8
(230 Views)