02-18-2009 07:10 AM
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
Solved! Go to Solution.
02-18-2009 07:36 AM
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
02-24-2009 12:03 PM
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
02-24-2009 01:28 PM
02-24-2009 01:58 PM - edited 02-24-2009 01:59 PM
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.
02-26-2009 04:10 AM - edited 02-26-2009 04:10 AM
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
02-26-2009 09:17 AM - edited 02-26-2009 09:18 AM
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.

02-26-2009 05:48 PM
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
02-27-2009 07:56 AM
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.