LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you make a subVI that only executes once while inside a while loop?

I am having trouble coming up with a way to write a subVI so that when a Boolean control in the main program is switched, it executes some code once, but not again when the main programs while loop executes again.

Basically, the real world problem I have is that I am attempting to control a latching solenoid valve. What this means is that I don't have to send the valve a constant + or - 12 V, just a short pulse of + or - 12 V to switch it. I am having trouble because I can't seem to write a subVI that will execute this behaviour. I can't use a latching Boolean as I need to be able to make local variables of the switch.

Basically I am looking for how to have the behaviour where I hit the button, and the subVI pulses the valve the correct way once, and then doesn't do anything until I hit the Boolean again. This Boolean button is inside a while loop that is executing indefinetly.

I have tried an event structure with value change on the Boolean being the event detected, but this does not work as a subVI, only if it is in the main VI.

Conor
0 Kudos
Message 1 of 6
(4,205 Views)
Conor,

Put the write to valve in a subVI. Put the subVI inside the True case of a case structure. Connect the select terminal to a boolean type shift register. When your boolean button changes (The CHANGE is the important part, not the continuing value of the boolean) to True, set the shift register value to True. Inside the case structure set the boolean value on the shift register back to false after writing to the valve. Be sure to initialize the shift register: False if the valve is not to turn on when the program first runs and True if is does turn on. The False case will just pass the shift register through.

If you are using local variables, there may be better ways of structuring your program. They are not often needed and create opportunities for race conditions.

Post your attempts and someone will probably be able to suggest ways to make it work.

Lynn
0 Kudos
Message 2 of 6
(4,198 Views)
One way is to use a shift register to hold the value of the button.  Read button each loop and compare to last loop value using XOR.  Use a case structure to call the subvi only when XOR output is True.  See attached VI.
- tbob

Inventor of the WORM Global
0 Kudos
Message 3 of 6
(4,195 Views)
Hmm, the problem with that solution is that the valve has two directions to throw it. To open it you hit it with +12 V and close it you hit it with a -12 V pulse. Therefore, having a "false" setting where nothing happens is no good, as false should actually means a -12 V pulse one time.

Also, I was wondering if there is a way to do ALL of the coding for this in a subVI, i.e. the main vi would only be the button (or local variable of the button) feeding into a subVI that handles everything else. This is because any code that was inside the main VI would need to be redone many many times.
0 Kudos
Message 4 of 6
(4,187 Views)
What you have just described is demonstrated in Consumer-Producer Design Pattern. Go to File >> New.. >> VI >> From Template >> Frameworks >> Design Patterns

Rather than using a boolean for the case selector you may want to change to an enum with Open, Close, and Standby values. When those are sent to your subVI it will send +12 V, -12 V, or 0 V to the valve.

Lynn
0 Kudos
Message 5 of 6
(4,184 Views)

Try this.  In the true case structure you send either a +12 V or -12V based on the new stated of the boolean.  In there, you place your subVI that generates this "pulse".



Message Edited by Ravens Fan on 01-08-2008 11:53 AM
0 Kudos
Message 6 of 6
(4,177 Views)