LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to delay sequences on LabVIEW?

Hi. I'm new to this programming environment and now working on my first project. I'm now using Arduino Mega interfaced with LabVIEW 2013 via LIFA.

 

I use digital write palletes to control relays. However, I'd faced problems regarding the delay time. On Arduino IDE, we simply write delay=1000 to delay the said relays. I'd tried using wait (ms) and wait until next ms but both of them turned on the relays and get delayed only after I hit the stop button.

 

And one more question is why the first channel of my relay turned on right after I uploaded LIFA firmware to the Arduino? Does it supposed to be off (default state)?

 

Any assistance are greatly appreciated. Thanks in advance.

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

I don't see any delays in your LabVIEW code.

If you add delays, then you want to make sure they aren't happening in parallel to your other code.  The either need to be put into subVI's so you can use other wires like the error wire to make sure they happen in sequence with the code that activates something, or have them in sequence frames before or between the frames that do something.

 

Is this VI running on Windows?  If so, the timed sequence structure isn't really intended for Windows applications, it will probably still work though.

 

I don't understand what you are doing with the local variables, constants, and terminals at the bottom of your VI.  Writing a terminal to its own local variable is pointless.  And all of those constants to the other local variables will all happen at roughly the same time with no control over what happens first because of race conditions and no certainty as to what the final state of those controls will be.

 

I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

 

 

0 Kudos
Message 2 of 10
(3,211 Views)

 


I use digital write palletes to control relays. However, I'd faced problems regarding the delay time. On Arduino IDE, we simply write delay=1000 to delay the said relays. I'd tried using wait (ms) and wait until next ms but both of them turned on the relays and get delayed only after I hit the stop button.

 

 


Use the Time Delay vi in your Timing palette

td.PNG

 

As RavensFan was saying use the error cluster to control the flow of your program.

td2.PNG

 

Your LabVIEW programming will improve dramatically by remembering this simple rule.

DO NOT USE SEQUENCES OF ANY TYPE, EVER!

 

 

 

-------------------------------------------------------------------
Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
Message 3 of 10
(3,181 Views)

Why are you using a Timed Loop?  And why a Timed Loop with Frames?  I assume you know that every frame will operate "as fast as it can", i.e. with no delays between frames (other than the Data Flow "rule" that everything in Frame 1 has to execute before Frame 2 starts).  Your Timed Loop says "Do everything inside this once a second", so I predict that Frames 1 through 4 will execute "almost at the same time", then you'll wait 0.999 seconds and "do it again".

 

Bob Schor

 

P.S. -- get rid of the Timed Loop, use a State Machine with Wait (ms) functions where appropriate (to "slow down" a State to be one second in duration).

0 Kudos
Message 4 of 10
(3,180 Views)

@RavensFan wrote:

 

I don't understand what you are doing with the local variables, constants, and terminals at the bottom of your VI.

 


Also, all these will get read/written only once at the start of the program. I think you are looking for a radiobutton control (a container of booleans were only the one changed last is true and the rest are automatically false).


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 5 of 10
(3,173 Views)

Hi RavensFan, I'm sorry but I'd actually uploaded the wrong VI. You may see the newer one that I'd attached on this reply. I'm developing a control system to control the pH level of the soil. Before going further to the pH level countermeasure part, I would like to run the relay in sequence with delay first. In the new uploaded VI, I'd tried to switch on the relay by the local variable boolean (constant) but failed.

 

And yes sir, I'm running my VI on Windows 8.1. Thank you for your guidance.

 

 

0 Kudos
Message 6 of 10
(3,170 Views)

Your booleans and local variables makes no sense whatsoever.I actually can't even imagine what you are trying to do with them.

I do not mean to offend you, but maybe you should consider the free introduction course RavensFan linked to?

 

In addition to the advice you already got, you can move the "Set Digital Pin Mode" functions out of the loop. You only want to do them once before the loop starts.

0 Kudos
Message 7 of 10
(3,139 Views)

Now seeing the delays in the VI, it is possible to comment and make suggestions.

 

Per Hult gave you some good advice there about the configuration of the pins being out of the loop.

And your local variables and terminals at the bottom still don't make sense.  First, they look they should be indicators and not controls.  That they are just status indicators to show what is happening.

 

Writing a value from a control to the local variable of the same control is pointless.

 

In your code up top, it looks like you are trying to cycle through what pumps are on and off, but in each frame, you turn on a pump, but don't turn off any of the others, you just turn off the boolean controls.

 

Your delays are in the same frame as the action.  So when it gets to frame 1, the 2 second wait begins at the same time as the digital pin 1 gets turned on.  So it will look like an instant on.

 

Then when the 2 seconds are done, it moves to the next frame.  There you turn on digital pin 2.  But you don't turn off number 1.  But you do happen to write a false to the misused control/indicator "Boolean 1".

 

When the 2 seconds are done in frame 2, it moves to frame 3.  You turn on digital pion 3, you don't turn off 1 or 2.  But you do write falses to the boolean 1 and 2 "indicators".

 

Same for the final frame.  After the 2 seconds in that one is up, the loop iterates reconfiguring the pins and turning the pumps on again, but that is really meaningless because they were never turned off.

 

In the process of fixing your code, you should look up the "state machine architecture" which is the design pattern your process should fit into.

0 Kudos
Message 8 of 10
(3,128 Views)

Hi RavensFan, can I just program my project on Arduino IDE. Then, on Labview, I just show them as my GUI (Graphical User Interface). Can I obtain the value from pH meter and display it on LabVIEW front panel via low level analog read pin VI? The pH meter will be programmed in IDE.

0 Kudos
Message 9 of 10
(3,070 Views)

Sure you can do that.

 

The architecture you'll put onto the Arduino will probably be similar to what I described for LabVIEW.  (It's still programming, just a different language.)

 

You'll have to take a look at various resources on how the LabVIEW VI would communicate with the Arduino.

0 Kudos
Message 10 of 10
(3,059 Views)