From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Delay/Timer only in a conditional loop.

Solved!
Go to solution
Hello,

I want to use a delay(or some kind of timer) within my program. I intend to use to it within a conditional loop. Specifically, if a particular condition is true, then I want to wait for 50ms and then check another condition, which if true, I want to stop my program.

I have used wait vi in the timing section. But this vi pauses my whole program. Specifically, when the above mentioned condition is met, I want the delay vi to execute along with my data acquistion vi. At present, when the delay vi executes, everything (data acquisition, peak detetction, plotting etc) in the program pauses. I guess its correct functionality of wait vi but it does not suit my need.

Does someone have any alternate for pausing (delay/timer) a particular condition loop without affecting the other parts of my program? Specifically, only the conditional loop delays for a certain time while other features like data acquisition, peak detetction, plotting etc excute normally.

Message Edited by Neuropotential on 02-22-2010 12:47 PM
Message Edited by Neuropotential on 02-22-2010 12:48 PM
0 Kudos
Message 1 of 27
(4,814 Views)
If your codes are in parallel loop, your delay in one loop shouldn't affect another loop.  However, if your codes are all in series, your delay will affect all subsequent codes.
------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
Message 2 of 27
(4,800 Views)
My codes are in parallel. But still it pauses the whole system. Do you want me to post a screenshot of my VI?
0 Kudos
Message 3 of 27
(4,794 Views)
Please post your code
------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 4 of 27
(4,784 Views)
I do not have the code now. Will post it once I reach home.
0 Kudos
Message 5 of 27
(4,779 Views)
There is a case structure (at the bottom left) which has a delay of 10 s when the condition is true. After 10 seconds, it would stop the
program (data acquisition). The program correctly identifies the true condition and also stops the program after 10 seconds. But during
these 10 seconds, it also halts the data acquisition. I want the data to be acquired simulatenously as the delay timer is ticking down.
0 Kudos
Message 6 of 27
(4,753 Views)
Solution
Accepted by topic author Neuropotential

That's because the Wait (ms) Timer tells the code to wait that long before continuing execution.

 

What you want to use is the Elapsed Time Express VI.  It stores the time in a shift register and outputs a True only after the specified amount of time has passed, it doensn't tell anyting to Wait.  Make sure you read the help on it.  It has multiple inputs such as Reset, and Auto-Reset you'll want to pay attention to if this is a function that you will need to handled a series of elapsed time measurements.

Message 7 of 27
(4,747 Views)

Yes. This is exactly what I was looking for. But, there is a issue. In practise, i will not be looking at 10 sec delay but a very small number like 50 ms. With this approach, when I set a value of 50ms, my program stops after close to 90-93ms (After 50ms, there is a AND gate, when true stops the program; Refer to the attachement).

 

There are multiple reasons which I see. First is obvious I am using a windows xp with lot of other stuff going on simutaneously. Also. elapsed time vi is an "express vi". Do you think this can be one of the primary reason for such a delay? Finally, I intend to use this program on RT based machine.

Do  you see it working exactly as expected on those machines or do I have to modify my code? Please guide me. 

 

Also, how to I mark your post as answer and other good things. 

 

Thanks 

0 Kudos
Message 8 of 27
(4,735 Views)
2 more things: 1) The elapsed time when I start labview fresh goes upto 125ms when 50ms was specified. I think thats because of xp. Also, I do not calculate this elapsed time. I just added an indicator to the express vi output as shown in image.jpg in the my previous comment.
0 Kudos
Message 9 of 27
(4,724 Views)

Looking at your code, it is clear that the delay code and the DAQ code are not in parallel.  Both the delay code and the DAQ code are in the same loop.  The DAQ code can't continue to the next iteration when the delay code is still running, since they are constrained to the same loop.  If you want two sections of code to run in parallel, you need to separate the two sections into two loops that are not in a sequence structure (if possible use state machine instead).  Then, you can use a queue to pass variable between the two loop. 

 

Go to New... and select the producer/consumer template.  Study it a little, and you will see what I am talking about.

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
Message 10 of 27
(4,701 Views)