04-19-2023 10:15 AM
Hi,
I did aVI to control an electrical relay (attached) and now I want to run it every x seconds. I have tried timed loops, while loops, and I keep getting the same problem: the program works fine one time and then the relay stays open but the loop continues running.
Thank you
04-19-2023 10:32 AM
Hi Wavicle,
I tried running your code and it seems like the loop would run for whatever time (s) you set. Once the time has elapsed, then it would stop. What do you mean by the loop continues running?
Also, try to give more details. Is it a continuous cycle? or do you want the program to stop when the relay opens? How long do you expect the relay to be ON and how long do you want it OFF? If you can give a little more detail, that would be great.
04-19-2023 10:43 AM
Never (well, hardly ever) use a Frame Sequence! [Almost the only exception would be for FPGA coding]. What is it that you want to repeat? Whatever it is, do the following:
Relays, of course, provide slightly more tricky timing, as there are two times to consider, both mentioned above. One is the repetition time of the loop ("Do this every 5 seconds"), and the other is the fraction of the time (Duty cycle?) that the Relay is Closed. In the early days of LabVIEW, there was no "easy" way to have a Delay occur at a particular "point in time" relative to other code that was serialized by sitting on the Error line other than using a Frame Sequence around the Delay and running the Error Line through it. Now there are options, including the Stall VIM and Time Express VIs.
Bob Schor
04-19-2023 11:06 AM
@Wavicle wrote:
I did aVI to control an electrical relay (attached) and now I want to run it every x seconds. I have tried timed loops, while loops, and I keep getting the same problem: the program works fine one time and then the relay stays open but the loop continues running.
When attaching code, please provide sufficient information. For example, what are the VISA command strings for "open relay" and "close relay"?
As a fist step, get rid of the instrument communication and work out the code logic just controlling an LED of the front panel.
Explain exactly what should happen and when:
Also: Please NEVER maximize the front panel and diagram to the screen. You need to be able to program while looking at other windows (e.g. the help window!!!!). We don't want to stare ant 90% whitespace!). Also never use the "continuous run" button.
04-19-2023 11:34 AM
@altenbach wrote:
As a fist step, get rid of the instrument communication and work out the code logic just controlling an LED of the front panel.
Here's how that could look like.
04-20-2023 03:05 AM
Hi,
What I want to do is to open the relay for x milliseconds then close it, wait x seconds and repeat the opening and closing process again, then wait, and so on. The relay state would be closed at the start and after the time target should be closed. the typical time target for the opening and closing sequence is milliseconds then the typical time target to wait until repeating are seconds.
The VISA command strings for "open relay" and "close relay" are A001 01A2 and A001 00A1.
When I tried to put everything inside a while loop the problem I had was that it opened and closed the relay, then waited the seconds I wanted, and then opened the relay and left it open while the loop was advancing.
Thank you
04-20-2023 10:32 AM
@Wavicle wrote:What I want to do is to open the relay for x milliseconds then close it, wait x seconds and repeat the opening and closing process again, then wait, and so on. The relay state would be closed at the start and after the time target should be closed. the typical time target for the opening and closing sequence is milliseconds then the typical time target to wait until repeating are seconds.
Well, maybe this can give you some ideas....
Should be easy to add the instrument communications.
04-20-2023 10:43 AM
Is this a mechanical or solid state relay and the make/model number? If mechanical- can it even open/close on the order of milliseconds?
-AK2DM
04-20-2023 11:00 AM - edited 04-20-2023 11:02 AM
@AnalogKid2DigitalMan wrote:
Is this a mechanical or solid state relay and the make/model number? If mechanical- can it even open/close on the order of milliseconds?
Good point. Well, it could be 900ms, who knows. 😄
Then there's all the communication overhead....
(Even in my code, you won't be able to see the LED flash if the on-time is significantly below 50ms, even if the LED is set to "synchronous display". We could use a chart instead.).