04-13-2023 10:42 AM - edited 04-13-2023 11:38 AM
I am pretty new to LabVIEW so I am having trouble with what I believe to be a simple issue. Basically the goal of this program it to cycle a relay at determined rate for a determined number of cycles. The program I have written does what I need it to, my issue is I want to activate the cycles with a button. Right now as soon as I press run it will cycle n times (Numeric 3) and not reset. From my understanding a shift register will accomplish my goal, but I appear to be setting it up incorrectly.
Thanks in advance
04-13-2023 11:04 AM
Hello Dfturner,
Use Event Based State Machine Architecture to achieve your Requirement.
There is no Use of While Loop and Even if you remove it will behave like the same.
Its Always better to share the code than images.
04-13-2023 11:40 AM
I went back and re-added the VI to the attachments. Thanks for the response, I will give it a shot
04-13-2023 11:48 AM - edited 04-13-2023 11:54 AM
The Run button is simply "Run What is on your block diagram." What is on your block diagram? A FOR Loop that does stuff. Remember why it's called a FOR loop. It's DO FOR 'insert condition.' Typically the conditions are terminal. Psuedo: FOR i<x, i++: As in DO (the following code) FOR i (iterations) times until i is greater than or equal to x (or phrased while i is less than x). In your code you have the FOR loop iterating at whatever number you put into Numeric 3. And you absolutely should not (and cannot) put INF.
You also have a While Loop that runs once due to the True boolean wired to the stop. What you've written: Do (the following codee) While The Condition is False - or... Do (the following) Until the Condition is True.
It total it's:
Psuedo:
Do the Following For 'Numeric 3' Iterations {
- Initialize Digital Output
- Start
Do the Following Until Stop is True {
- Set Dig Bool
- Wait for (X * 1000) ms
- Set Dig Bool
- Wait for (X2 * 1000) ms
-Check Condition is True (It is True)
Stop While
}
Close and Stop Dig Output
}
I recommend CTRL-H in your block diagram, hover over stuff and read about it - read the detailed descriptions too. You should be able to figure this out with the hints I've given you. And also ask yourself, why is there a While Loop inside your For Loop.
04-13-2023 02:34 PM - edited 04-13-2023 02:46 PM
04-13-2023 09:10 PM
@aputman wrote:
- <many good points>
Also, you equal comparison wired to the stop condition will never do anything useful, because it is always FALSE. The FOR loop will run for as many times you wire to N and then end. At that points, i=(n-1),so i=N can never be true. You don't even need to show the conditional terminal (as in 99% of all LabVIEW FOR loops in the world).
Your while loop does absolutely nothing because it stops after one condition. It is basically a glorified (and completely unnecessary!) sequence frame.
Why do you think you need to configure a task from scratch and destroy it with every iteration of the FOR loop? That typically only needs to be done once.