Hobbyist Toolkit

Showing results for 
Search instead for 
Did you mean: 

Individual Timing of Two Valves?

Go to solution

Hello! I'm new to LabVIEW and have gone through some tutorials and have used some examples to get started on making a VI for what I need. I am controlling two solenoid valves that both have their own open/closed times, which are user specified. I am using an Arduino and already have a circuit set up with a MOSFET that is capable of safely powering/controlling the valves. I wrote an Arduino sketch that does what I need, but the experimental setup requires control through LabVIEW.


Basically, I need to have each valve initially open for a set amount of time (ex: valve0 for 500 ms, valve1 for 700 ms), then immediately after the specified time each valve needs to start cycling at its own rate (ex: valve0 open for 150 ms then closed for 250 ms, valve1 with different timing).


So far, I've successfully been able to control a single valve in the way I want to using LINX (image attached). I can tell the valve to start open for a time, then begin cycling at my specified rate. My struggle now is figuring out how to properly extend this control to two outputs, ensuring that the uneven timing between valves doesn't mess things up.


Any help would be greatly appreciated!

0 Kudos
Message 1 of 8

I would look into using a State Machine architecture and since you are a beginner I would look into the JKI State Machine.  This can be installed through VIPM.  There any many examples and training available on this type of architecture to get you started.


Basically I would define a loop rate, your timeout in the JKI State Machine, and every loop look at the current time compared to the last change time of each valve.  If the delta time is greater then your cycle time for that value then transition to a case to trigger the value and store the current time to be used for determining the next cycle.  In this way you could extend it to as may valves as you want with as many different durations that you want.

David Wilt
The New Standard LLC
Message 2 of 8

Following the previous state machine suggestion, you may want to try the DVR timer to cleanly handle the two timers :  https://www.vipm.io/package/ni_lib_simple_dvr_timer_api/


How tights does you valve timing need to be? Can it drift a little?




PS: State machine: you can use a basic state machine also as found in the LV examples. "State Machine.lvproj"  under C:\Program Files (x86)\National Instruments\LabVIEW 20XX\examples\Design Patterns\State Machine

Message 3 of 8

Thank you both for the responses and feedback! I will spend some time with this now and report back with any questions or issues.


L: The timing can vary by +/- 10% roughly and still be fine.



0 Kudos
Message 4 of 8
Accepted by topic author PThreePO

I wouldn't use state machine for 2 valves (2 digital output signals) which are independent after start action. See attachment.


Message 5 of 8

Thanks for all the help everyone! Splitting the LINX resource and duplicating what I had ended up working, though I understand that the timing may not be exact and it can't be easily scaled. Also learned a bit in the process 🙂 

0 Kudos
Message 6 of 8

For very tight timing you could also use 2 counters set with the specific period time and variable duty cycle. All with daqmx and a simple  USB DAQ.

If staying with LINX, there should be something doable with the PWM example, the only issue is that even though the duty cycle is settable, the base frequency isn't. I cannot recall if there was a post about that somewhere. That could be solved easily with LIFA, precursor of LINX, but I don't remember with LINX.


0 Kudos
Message 7 of 8

About accuracy ...

1. Let's look on equipment:

- typical simple and small valve has open/close time more than 1 ms. 

- LINX DO rate is 300-500 times per sec (Blink example on Arduino Leonardo)

- LabVIEW application on normal PC gets 1 ms easy. 

So equipment has resolution few ms. IT means suggestion to use counters in NI device is overkill for sure. I don't know PWM parameters in Arduino but anyone can estimate.


2. PThreePO asked about 10% time accuracy. Let's calculate:

- 10% out of 1000 ms is 100 ms

- 10% out of 100 ms is 10 ms.

100 ms and 10 ms accuracies are big difference. So it is better to define accuracy in absolute value, like 2 or 5 ms for this equipment


3. If I would like to get better accuracy I would use "Get Date/Time In Seconds Function" per each valve in loop with event structure. In 1 ms Timeout event application will compare time. If time passed that application switches valve and calculates next switch timestamp. Such application is also simple but it would take a little more time and visibility will be worse.

0 Kudos
Message 8 of 8