LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create Delay in LabVIEW

Solved!
Go to solution

Hello, I'm looking to create a time delay in LabVIEW. Attached is my program flow daigram. Sorry I cannot upload my VI. It's pretty big and I don't know how to capature all of it.

 

I need to create a delay after my LabVIEW VI starts running and sends digital control signals to my circuit and before I start a circuit calibration loop. After the circuit is calibrated I will just make measurements. I'm using a NI X Series USB 6343 DAQ box to output digital sigals, digital control sigans and read analog signals.

 

I was told LabVIEW excutes the VI from left to right... is this true?

0 Kudos
Message 1 of 20
(17,141 Views)

@akhurash wrote:

I was told LabVIEW excutes the VI from left to right... is this true?


No, this is wrong. Execution order is fully determined by dataflow, not by geometry.

 

We really need to see some of your code. To delay code, all you typically need is to insert a wait in the right place.

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

Thank you for the quick reply. I guess it is better to post the VI. Attached is my program. The while loop all the way to the right is the "main" while loop. And the while loop above the "initalization" stuff is the clock signal. There is a lot of white space.... I left those blank because once I'm done with this program I'm going to comment on it.

 

I'm trying to create a VI that will do the following:

 

--> Initialize circuit by setting inital values and output digital control signals and outputting an analog voltage

--> Wait for about 0.5secs (500ms)

--> Do a circuit calibration

--> Start main "while" loop and just excute the part of the code the user has choosen to excute

 

While everyhing above is happening there should be a square wave output from the DAQ box (which will be the clock input to the circuit).

0 Kudos
Message 3 of 20
(17,128 Views)

I suggest that you look into "state machine" architecture and that you have a maximum of two loops (i.e. producer/consumer) 

 

With your current program, you have too many loops and too many opportunities for race conditions.  You also have no way of determining the execution order of the loops.

>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 4 of 20
(17,104 Views)

Just as I thought, you have 12 independent code segments that all start concurrently because there is no data depedency. The problem is compounded by local variable abuse, breaking all data depedency. You can get rid of most of them. They also cause race conditions and unpredictable results. For example in the big loop there is no way to tell in which order the locals of the same control are read and written (e .g. "offset val"), but the outcome critically depends on the order. You even read and write to it once outside the loop in parallel. No way to tell what happens first!

 

Once you wire things up, it is much easier to create proper data dependency, determine execution order, and insert delays.

 

You can always start small and create more whitespace as needed by ctrl-dragging the mouse. Try it!

 

What's the purpose of the FOR loop with one iteration?

 

It would be much more useful if you could attach the actual VI instead of a poster sized image.

 

0 Kudos
Message 5 of 20
(17,102 Views)

I was trying to use the FOR loop to create a delay. I attached an updated copy of the VI. I removed the FOR loop and all the space. Sorry I'm pretty new to LabVIEW. I actually sent a VERY similar VI to NI asking if everything looked alright and they told me yes....

 

The whole point of this program is to create a square wave (clock) signal and take measurements. There are different "modes" where the control lines will change values. When I say the control lines I mean digital outputs fromt the DAW box into the circuit.

0 Kudos
Message 6 of 20
(17,083 Views)

As I said, it is all in the dataflow!

 

To e.g. delay the big loop on the right, you could wire a wait in front of it. Since there is now a data dependency to the output of the wait function, the loop cannot start until 5 seconds have passed.

 

You still have all the race conditions mentioned. The code is NOT fine!

 

Message 7 of 20
(17,067 Views)

@akhurash wrote:

I was trying to use the FOR loop to create a delay. I attached an updated copy of the VI. I removed the FOR loop and all the space. Sorry I'm pretty new to LabVIEW. I actually sent a VERY similar VI to NI asking if everything looked alright and they told me yes....

 

The whole point of this program is to create a square wave (clock) signal and take measurements. There are different "modes" where the control lines will change values. When I say the control lines I mean digital outputs fromt the DAW box into the circuit.


Instead of trying to guess how LabVIEW works, why not buy a book or two on LabVIEW, do some of the tutorials, look at some of the examples.  It's just like any other programming language.  Anyone can program an app - only someone with training can do it right.

 

One thing that I like about your approach is that you try to keep everything nice and neat looking.  It's way more important than you think.  Imagine how programming in C would look like if you you never used indents???

 

Not sure who you sent your VI to, but many of the people you see here in the forums are the same people who would be reviewing that email...

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 8 of 20
(17,060 Views)

Thank you for the replies guys. I really appreciate it. I did do some basic tutorials on LabVIEW, nothing really on what I'm trying to accomplish. I guess I really should have done that. :(.

 

I'm trying to add the delay before the main loop. I will look into using the "state machine" architecture.

0 Kudos
Message 9 of 20
(17,054 Views)

@akhurash wrote:

Thank you for the replies guys. I really appreciate it. I did do some basic tutorials on LabVIEW, nothing really on what I'm trying to accomplish. I guess I really should have done that. :(.

 

I'm trying to add the delay before the main loop. I will look into using the "state machine" architecture.


I just happened on thsi littel tidbit because I was trying to come up with an easy way of explaining dataflow.  🙂http://blog.sixclear.com/post/3510548005/labview-dataflow-programming

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 10 of 20
(17,041 Views)