LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to turn on/off solenoids at specific frequency

I have a problem which I think someone here can help me.  I am trying to turn on and off two solenoids that control the up and down of an air cylinder.  I have done applications before but nothing more than recording data and some controls but nothing to do with timing.

 

I have tried several variations but the timing seems off when I have it in the attached structure (this is rough since I have played with several versions in the last few days).  The user needs to be able to select a frequency from 1-20 Hz.  I also need to have a fairly easy computational scheme since I will have eight of these stations running all independantly (each slave loop will be a station). 

 

Should I use a timed loop?  Should I read a digital waveform for the output in one loop?  I am stuck on what structure to start with.  Right now I have a master and slave loops for each station.  Each loop waits for the occurance to start/stop.  One the loop starts it runs but not in a consistent manner.  It is not necessary to have each station timed exactly with each other.  Just so that each air cylinder goes up and down at its specified frequency.

 

Thanks in advance for the help!  I am using a cDAQ 9188 with a 9478 module to drive the solenoids directly.  I am under the current limits for the module.

0 Kudos
Message 1 of 6
(3,582 Views)

I'm guessing, based on your code, that you have a latching solenoid such that you only need to activate it momentarily.  However, I wonder if you're activating them long enough - you might want to add a small delay between switching the valve on and switching it off again.

 

The best way to control something like this is a PWM (pulse-width modulation) signal, which is a square wave with a varying duty cycle (the ratio of on time to off time).  How accurate do you need the timing to be?  On Windows, you cannot get good timing in software - the best you can hope for is on the order of 10s of milliseconds, with occasional unpredictable interruptions when it installs updates or runs a virus scanner or whatever else.  If you need better timing than that, you need a device that can generate a PWM signal in hardware.

 

Of course, your situation is slightly more complicated, since you want to trigger your valves momentarily on the edges of a square wave, and leave the valves de-energized the rest of the time.  However, I think a good start would be to generate a PWM signal in software, then detect the edges in it and use that to energize the valves.  I posted an example of how to generate a PWM in software with varying duty cycle and frequency here.  If you convert the numeric values in that example to booleans, you can use "Boolean Crossing PtByPt" (found in Signal Processing -> Point by Point -> Other Function PtByPt) to detect the transitions.  When a transition from true to false occurs, or vice versa, turn on the appropriate valve momentarily.

 

EDIT: added the link.  Also, if your hardware supports digital waveforms, it's definitely possible to get accurate timing that way, you'll just need to generate the entire waveform in advance.

0 Kudos
Message 2 of 6
(3,569 Views)

The solenoids are not latching but as long as they get activated at the proper time, the time that they are on doesn't matter.  i.e, for 1 hz the air cylinder can push up for .5 seconds and pull down for .5 seconds and that would be fine.  It doesn't have to have the same time at force as when operating at higher frequencies, would be nice though.  Any ideas on what hardware I can use if the generate waveform doesn't give the appropriate timing?  Is there a NI card that can do this?

0 Kudos
Message 3 of 6
(3,548 Views)

Okay so I tried the waveform which works fine by itself when its running in a single loop.  But there is some latency and inconsistent behaivor on the timing on when the output gets written to the channel.  I think I need to use a hardware timed loop.  My cDAQ-9188 has a internal timer.  How do I make use of it?

 

0 Kudos
Message 4 of 6
(3,531 Views)

attached what I have tried so far that does not run

0 Kudos
Message 5 of 6
(3,527 Views)

Can you be more specific than "does not run"?  Are you getting an error?  Why did you insert the Sample Clock and Configure Output Buffer functions, which are not helping you at all here (and are possibly generating an error, preventing your code from running properly)?

 

I don't know enough about the CompactDAQ series to tell you what your system can do, nor what module is right for your needs.  According to the spec sheet the 9478 does not support hardware timing, so I would guess that you cannot use it for PWM generation.  Most of the devices that can do PWM generation cannot handle enough voltage or current to drive a valve.

 

I don't think I properly understand your system.  In the code you first posted, you actuate the valve momentarily, which led me to believe that there's a latching mechanism in your valve.  Are you sure this is not the case?  If not, I can't imagine you're getting much travel distance out of a very short pulse of air from the valve.  What happens if both valves are turned on at the same time?  How accurate does the timing need to be?  When you write "there is some latency and inconsistent behaivor on the timing" can you be more specific?  How much latency?  What value are you using for the loop timing?

0 Kudos
Message 6 of 6
(3,511 Views)