LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a cycle loop

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

0 Kudos
Message 1 of 10
(1,154 Views)

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:

  • They can have six different mechanical actions that control both when their value changes (on pressing, or on release, or both) and whether or not reading them "changes them back" (the "Latch" property.
  • The "square" Boolean controls, by default, have "Switch until Released" as the default property.  This makes them ideal for use in Event structures where you want something to happen once every time you push a button (it actually happens when you take your finger off the button -- as a result, you will "rarely" see such a control in its "On" (or "True") state.
  • I don't think I've ever used "Latch when pressed".  On rare occasions, I've used "Switch until Released" (whose symbol is a "push-button", which is how it acts).  Otherwise, I stick with the default "Switch when pressed" for all non-square Controls and "Latch when released" for Square one (though I'll sometimes, for "Style" reasons, want a non-momentary Boolean control that is a "Push-on, Push-off" (or "Switch when pressed") action).

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

0 Kudos
Message 2 of 10
(1,130 Views)

Thank you for the feedback. I have attached the'19 version

0 Kudos
Message 3 of 10
(1,127 Views)

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:

  • Understand Data Flow, and the concept that "Data Flows in Wires"
    • Any Structure that has Data flowing into it cannot execute until all the inputs have data.
    • No Structure with Data flowing out of it has any data on the output wires until the Structure exits.
    • If you have two Structures that don't have any data flowing from one to the other, you cannot tell which runs first, and LabVIEW basically runs them at the same time (so-called "Parallel Programming").  You get this "for free".
  • "Almost never" use a Frame Structure.  Much better are using the Error "Wire" (lower left and lower right corners of many functions) to show a sequence of program actions.
  • Learn the distinction between Integers, blue wires and Controls) and Dbls (or "Floating Point"), orange wires.  If you are counting it, it is an Integer (signed or unsigned, 8, 16, 32 (most common), or 64 bit.  If you are measuring (or computing or estimating) it, it is a Float.  Your values "Cycles" and"SP" (?? Set Point? Don't hide names) should be I32's, probably.
  • When you put a Numeric Indicator on the Front Panel, by default it will be a Float.  To make it an Integer (I32), right-click it and choose "Representation".

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

Message 4 of 10
(1,090 Views)

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!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 10
(1,072 Views)

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.

0 Kudos
Message 6 of 10
(1,043 Views)

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.

0 Kudos
Message 7 of 10
(1,042 Views)

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

0 Kudos
Message 8 of 10
(1,028 Views)

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

0 Kudos
Message 9 of 10
(987 Views)

See if this can give you some ideas....

 

(quick draft. Needs more polishing)

 

 

0 Kudos
Message 10 of 10
(980 Views)