10-09-2023 02:43 PM
I am fairly new to LabVIEW, so I am having trouble programming a cycling loop. For the programming I have put in Boolean lights, but I will end up putting relays in place of them.
The way I have it set up I have a case structure, the true portion of it controls the cycling and the false portion resets the counter to 0. For the switch I have a "latch when pressed" button in parallel with a "less than" command. The idea is the button will activate the loop and the "less than" will keep it going until the cycles reach the set point.
I believe my problem is with the counter I set up in the last sequence. If after the first cycle it were to add 1 then it should keep the loop going. I put a "does not equal zero" In line to keep it from restarting when the structure goes false.
I am sure I could have made it much more eloquent, but for the most part it does what I am going for. If you hold the button until one iteration is counted then it works as planned.
Thanks in advance
10-09-2023 03:33 PM
Thank you for attaching your VI. As you have seen, LabVIEW is a "different" Programming Language in being "drawn", not "typed". Newer versions of LabVIEW (such as LabVIEW 2023) can "recognize" and process the code from earlier versions, but those of us who have been using LabVIEW for years and may not have upgraded to the latest version (I'm running LabVIEW 2019, myself) will not be able to open and view your VI.
Could you please open your VI, and then "Save for Previous Version", specifying, say, LabVIEW 2019? [You probably don't need to go "backwards" more than 2-4 years to reach 90-95% of the long-time users].
Somethings you should know about Boolean controls:
That being said, and the fact that you are "fairly new" to LabVIEW, lead me to guess that you are being misled by the "mechanical action" you gave your Boolean control. But without being able to examine the LabVIEW code (which requires you to re-attach it after "Save for Previous" and going back at least 2 years), I can only guess ...
Bob Schor
10-09-2023 03:39 PM
Thank you for the feedback. I have attached the'19 version
10-09-2023 07:03 PM
OK. I remember my first exposure to LabVIEW after years of Macro-11 "Real-Time" programming. I made many of the same "mistakes" (not really "mistakes", just really bad LabVIEW code because I didn't "get" the underlying idea of Data Flow). Fortunately, I had a mentor who quickly made me "see the light" (and a few good books). So here are a few tips and hints:
Whew! I took a break here to have dinner, and when I got back, there was an error ... Fortunately, I was able to get things back.
Here's a (too brief) example of decreasing the need for Frame Structures. if you want to change a Boolean, then wait 1 second, then "do something else", instead of having two Frames, one to change the Boolean and one to wait, put both in the same Frame! Because they are "disconnected", you can't tell which comes first (the "Third Law" of Data Flow) so they run "at the same time". But you can't exit the frame until they both finish -- one finishes in, say, < 1 microsecond, but the other takes 1 second, so "concurrent" time is the same as "sequential".
As you learn a little more LabVIEW, you'll learn that you can use a While Loop with a Case Structure inside it to make a "State Machine", where you "Do something" (turn on a valve, wait 1 second), then you "Do the next thing", then "Do the third thing", etc. When you get into using DAQmx to interact with hardware (i.e. generating a Digital Pulse to actually turn on a valve), you will encounter functions with Error Lines which makes sequencing so much simpler (just string your functions along the Error Lines).
Bob Schor
10-10-2023 01:02 AM - edited 10-10-2023 01:04 AM
Hi,
one more hint: learn about using shift registers! Then you need much less local variables (or their evil twin "value" properties):
You also should learn NOT to maximize windows! Using AutoCleanup on the frontpanel will arrange items quite nicely in recent LabVIEW versions (including LV2019) - and will also set a reasonable window size!
10-10-2023 11:36 AM
Thank you for the help. I will try to continue with that thought process. I was originally trained on MATLAB so my brain sometimes tries to go in that direction.
10-10-2023 11:38 AM
Thank you for the feed back. I am trying to become more familiar with shift registers, I have a general knowledge of what they are and how they work, I just need to apply it more moving forward.
10-10-2023 01:27 PM
Look at @GerdW's version of your code. Now get rid of the two Sequence frames that just have a 1-sec wait by putting the waits inside the preceding Frames that do nothing more than set Boolean values. The "Third Law of Data Flow" says that since the Wait and Boolean operations are not connected, they both happen "more-or-less" at the same time, so instead of waiting 0.0000001 sec + 1000 ms (which rounds off to 1000 ms), you'll wait 1000 ms (see the difference? It's "two fewer frames", no change in how the code runs). When you learn a little more LabVIEW, you may learn about State Machines and get rid of the Frames altogether.
Bob Schor
10-11-2023 08:49 AM - edited 10-11-2023 09:45 AM
This is all completely wrong. Your count is stored in the feedback node, so resetting an indicator does not really do anything to it.
A 1 second wait is too long for a responsive program, so spin it 20 times faster and keep track of the timing to decide what state is next. Notice the word "state". What you need is a state machine!
As a quick demo to show how to do timing can be found here.
10-11-2023 09:23 AM