LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to send a pulse to a relay

Solved!
Go to solution

Hi

 

I am using LabVIEW 8.6 to control a solenoid via a C series relay module. I wish to turn on the relay for a set period of time and then switch it off. This function is controlled by a feedback loop. I have attached a simple vi showing my code. The problem with this code is that it pauses the whole program (there is additional code running inside thr while loop) for 300ms whilst the relay is enabled. This is undesireable.

 

Is there a better way of turning the relay on for a set period of time and then turning it off? Any help would be greatly appreciated.

 

Thanks

 

John

 

 

0 Kudos
Message 1 of 9
(5,244 Views)

John,

 

It looks like you are using a cDAQ chassis.  If that is correct then the easiest way to generate a pulse is to use one of the two built-in counters in the cDAQ-9171.  LV ships with several examples that use DAQmx counters to generate pulses.  The manual for the 9172 http://www.ni.com/pdf/manuals/371747f.pdf has a section dedicated to using the counters.  You will need to install your relay ouput module in either slot 5 or 6.  See here for info on making the internal counters visible in DAQmx terminal controls/constants.  http://digital.ni.com/public.nsf/allkb/DF48BC8CFFA1F6CB86256F5D007EA11A

 

 

Message 2 of 9
(5,235 Views)

Hi

 

Many thanks for your help. I have been able to output a pulse to the relay as you have instructed. However, I wish to be able to turn the pulsed output on and off (or restart the pulse).  Ideally, I would like the additional code running inside the while loop to enable or disable the pulsed output based on signals from other sensors.  Which is the best way to code this?

 

Many thanks! I have attached an example of my code (LabVIEW 8.6)

 

John 

0 Kudos
Message 3 of 9
(5,182 Views)
Hi John,
There are a few ways to do what you would like. Many of the examples that will be pertinent to your application can be found in your LabVIEW example finder under the Browse tab, then go to Hardware Input and Output>>DAQmx>>Generating Digital Pulses. Deciding which example to use will depend on how you will be signaling to your counter to send the next pulse.

There are two main options: A hardware trigger or a software solution. There are advantages and disadvantages to both.

HW trigger:
You mentioned that you want to have your code send the next pulse from your counter based on a incoming signal from another sensor. This is a classic case of using triggering. The idea is that you would route the signal from your other sensor to a module on your cDAQ chassis. Then your code would look at this signal and receive a trigger whenever the signal changes digital state (digital low to digital high) or crosses a certain threshold (like a voltage value, say 1V). Then your pulse would automatically be output. To do this time of thing you could look at the "Gen Dig Pulse -- Retriggerable.vi" example in the example finder.

SW solution:
If, for various reason, you are not able to do the HW trigger solution, you could look at a simple SW solution. In this case, you could read in the value from your other sensor in a while loop. Then when you receive the data you're looking for, you could then send a boolean true to a case structure, and inside the case structure could be the "Gen Digital Pulse.vi" example in the example finder. I've made a very simple example attached below that shows something like this.

All of the above discussion is a bit simplified of course and I would definitely recommend looking at your DAQmx Help (from your Windows Start Menu: All Programs>>National Instruments>>NI-DAQ) for more information on triggering and the other things I mentioned.

Best of luck!
Brian Spears
NI Certified LabVIEW Developer
NI Certified Professional Instructor
Message 4 of 9
(5,161 Views)

eichlerjw wrote:

Is there a better way of turning the relay on for a set period of time and then turning it off? Any help would be greatly appreciated.



The better way is to use a shift register rather than a wait.  When you first turn on the pulse, store the current millisecond timer value in a shift register.  Subtract the shift register from the current timer value each time through the loop; if it's less than 300ms, turn on your output.  The image below shows a very simplified approach to this (it assumes that the mechanical action for your "data" boolean is latch when released so that a true value is only read once).  You could clean it up so that it only writes to the DAQ board twice (once on, once off), and wire in other conditions in addition to the timer that determine whether the output should be on or off.

If you're using this as a subVI, you'll need to initialize the shift register inside the while loop, using the "Select" and a "First Call?" functions.
Message Edited by nathand on 02-24-2009 02:59 PM
Message 5 of 9
(5,154 Views)

nathand,

 

thanks for the reply. Your code is useful, but I need the pulse to continue 'pulsing' when the boolean input is true. I have attached a vi which suits my application. However, the code only produces a single pulse when it is turned on.  I require that the code continues producing a pulse until the boolean input is set to false. Do you have any ideas about how to do this?

 

Many thanks

 

John

Message Edited by eichlerjw on 02-26-2009 04:10 AM
0 Kudos
Message 6 of 9
(5,115 Views)
Solution
Accepted by topic author eichlerjw

Try these two.  How long do you need the "Off" portion of your pulse to be?  In the first, simpler one, the off state is only one loop cycle.  In the second you can adjust the off and on times.  I'm sure neither of these is exactly what you need but I hope they're a good starting point.  VIs are saved in LabVIEW 8.6.

Message Edited by nathand on 02-26-2009 10:18 AM
Message 7 of 9
(5,097 Views)

Nathand, that's spot on (pulse_continuous_2.vi). It took me a while to get my head around how your code works but i have sorted it now. I have swapped the shift registers for feedback nodes so I can use this as a sub-vi.

 

Many thanks for your help!

 

cheers

 

John

0 Kudos
Message 8 of 9
(5,079 Views)

Glad it works for you.  There's no need to use feedback nodes instead of shift registers in subVIs (although you're welcome to do so if you like them better); just set your while loop in the subVI to execute only once by wiring a constant to the stop condition.  So long as you don't wire an initial value to the shift register outside the while loop it will work fine.

0 Kudos
Message 9 of 9
(5,062 Views)