LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create Delay in LabVIEW

Solved!
Go to solution

Look at Altenbachs post above, if you only need a delay before your main loop you only need to add a Wait and wire it to the loop.

You're abusing local variables, this isn't C, the Controls and Indicators isn't variable definitions. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 11 of 20
(2,856 Views)

I took out almost all the local variables. I only used the ones I needed and also used shift registors and sequences. I do have a question though. Can I use something else instead of the sequences? I'm still learning about LabVIEW so I was wondering if I can improve the VI.

0 Kudos
Message 12 of 20
(2,829 Views)

@akhurash wrote:

... so I was wondering if I can improve the VI.


You don't need to wire the timer output to the frame boundary. The frame does not finish until everything has finished.

Are the boolean controls independent or is only one true at any given time? I wouold recommend a simple radiobutton control and a single case structure. Only the numeric and boolean constant need to be inside the case, the output VIs can be after. Now you only need a single instance of each, greatly simplifying the code.

 

Please attach the actual VI instead of a snippet. The snippet cannot does with some of your code correctly.

0 Kudos
Message 13 of 20
(2,818 Views)

Which timers are you referring to? I put the two 500ms timers in the 4 flat sequences because I need a delay between when the first sequence finishes and the second one starts. And the same with the third and fourth sequences (there has to be a 500ms difference between when the third sequence finishes and the fourth one starts). I also need a 100ms delay in the main while loop before the second sequence is executed (the analog voltage is read).
 
Only one "mode" Boolean can be true at a given time. I'm trying to control a sensor board and all the digital outputs are controls on the board. Each "mode" has different controls for the board (well it's not totally different, only few controls are changed between modes).
 
Technically different "mode" Booleans can be true at the same time when a user is trying to switch between modes. After all the initialization is done only the main while loop and the clock runs. The clock is independent of rest of the code. The controls on the board are set by which "mode" is chosen by the user. If someone changes from "Mode 1" to "Mode 2" there will be a brief time when both "mode" Booleans are true. I was thinking of just stopping the VI and changing the mode and then re-running the VI but that might not be such a great idea... I have to think a little more about this.

Thank you for the advice on taking all the output VI’s out of the case structures. I was thinking about doing that but run into a problem. If I “OR” all the Boolean values to get an output (ex: I would “OR” the 6 Boolean outputs from the case structures for the “FREQ SELECT CH” channel) I might not be the correct output. See the attached drawing of what I’m thinking (it’s simplified)…

 

If “Case 1” is selected and the Boolean for the first input of the OR gate is “1” and the second one is “0” (from Case 2) I will get “1” as the output, which is correct. However, if I have a “0” for the first input and the second input (from Case 2) is “1” I will get a “1” output but that’s not correct because  Case 1 is selected, so the output should be “0”. Is this what you were thinking as well?

Download All
0 Kudos
Message 14 of 20
(2,802 Views)
Solution
Accepted by topic author ashifulk

@akhurash wrote:

Which timers are you referring to? I put the two 500ms timers in the 4 flat sequences because I need a delay between when the first sequence finishes and the second one starts. And the same with the third and fourth sequences (there has to be a 500ms difference between when the third sequence finishes and the fourth one starts). I also need a 100ms delay in the main while loop before the second sequence is executed (the analog voltage is read).

 

The ones in the sequence structure.  There is no reason to wire the output of those wait functions to the edge of the sequence seaquence frame.

 
Only one "mode" Boolean can be true at a given time. I'm trying to control a sensor board and all the digital outputs are controls on the board. Each "mode" has different controls for the board (well it's not totally different, only few controls are changed between modes).
 
Technically different "mode" Booleans can be true at the same time when a user is trying to switch between modes. After all the initialization is done only the main while loop and the clock runs. The clock is independent of rest of the code. The controls on the board are set by which "mode" is chosen by the user. If someone changes from "Mode 1" to "Mode 2" there will be a brief time when both "mode" Booleans are true. I was thinking of just stopping the VI and changing the mode and then re-running the VI but that might not be such a great idea... I have to think a little more about this.

Thank you for the advice on taking all the output VI’s out of the case structures. I was thinking about doing that but run into a problem. If I “OR” all the Boolean values to get an output (ex: I would “OR” the 6 Boolean outputs from the case structures for the “FREQ SELECT CH” channel) I might not be the correct output. See the attached drawing of what I’m thinking (it’s simplified)…

 

 

How can only one mode boolean be true at a time but yet you say "technically different mode booleans can be true at the same time"?  If only one can be true at a time, then you want a radio button control.

 

If “Case 1” is selected and the Boolean for the first input of the OR gate is “1” and the second one is “0” (from Case 2) I will get “1” as the output, which is correct. However, if I have a “0” for the first input and the second input (from Case 2) is “1” I will get a “1” output but that’s not correct because  Case 1 is selected, so the output should be “0”. Is this what you were thinking as well?

 

 

That is exactly your problem.  I assume by "Case 1" you mean the True case of mode 1  ancd "Case 2" the true case of Mode 2, since the only cases you have are true or false.  Right now you have a race condition.  If Mode 1 and Mode 2 are both true, does a true or a false get written to a digital output first?  It is a race between the two case structures.  A single case structure with a case for each mode would solve that problem.

 

Since much of the code is redundant, you could use a For Loop and an array of references and booleans to consolidate the writing of those different boolean outputs.  See attached.


 

Message 15 of 20
(2,778 Views)

Thank you! Not sure why I didn't think of using a for loop but your help is appreciated, :).

0 Kudos
Message 16 of 20
(2,752 Views)

RavensFan: This might be a stupid question to ask but in your VI you don't have the number of iterations (N) wired for the for loops. Is it supposed to be wired or does LabVIEW automatically know N based on the Boolean and channel array?

0 Kudos
Message 17 of 20
(2,716 Views)

It is called auto-indexing.  The tunnels for those two arrays are set for auto-indexing.  That means the Loop runs 1 time for each of the elements in the array.  The N terminal is unneeded in this case.  If you did have the N terminal wired, then the loop would run a number of times equal to the shortest array or the value of N, whichever is smaller.

Message 18 of 20
(2,705 Views)

Hi!

 

I was searching about time delay in labview and I bumbed on your comment. I would like to ask you is it possible to add time delay only for the first time that you want to run your VI ??? and how this is possible?

 

Thank you in advnace

 

Regards from France,

Vasileios

0 Kudos
Message 19 of 20
(2,176 Views)

"First Call."  (Do a search on the functions palette.)

 

I rarely use it.  To me, it feels almost like cheating because a well-thought gameplan should have included an init VI (or state, even) that should have set everything up the first time around already.  Of course, that's a generalization.  I have used it in cases where some equipment just does things differently the first time a certain instrument function is called, but I don't run into that very often.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 20 of 20
(2,170 Views)