LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Elapsed Time VI

I have a sub-vi with a simple loop that sits there and just reads a digital line. I'd like the loop to run until the digital line goes high or 3 seconds have elapsed. If the loop ended because of the 3 second timeout, I'd like to report back a timeout error to the caller. Otherwise, I report no error. How do I implement my 3 second timeout? I've tried to use the Elapsed Time VI but I can't get it to work. The trick is that I call this sub VI from several different VIs and everytime I call it I need the timeout period to restart. Is the Elapsed Time VI the right VI for me to use? If so, how? Thanx in advance.
 
Fataneh
0 Kudos
Message 1 of 4
(4,901 Views)
How about this:

Target = Now + 3000 mSec { your desired time }
repeat { use a WHILE loop }
Quit = Read Digital Line or (NOW >= Target)
until Quit

Message Edited by CoastalMaineBird on 11-21-2005 10:52 PM

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 4
(4,894 Views)

Is your subVI that calls the Elapsed Time VI set to be reentrant? If so, everytime it is called LabVIEW will create a separate copy of it in memory and the Elapsed Time VI inside it will have no relation to the other Elapsed Time VI's in the other subVIs. Then if you reset one, you won't affect the other subVI calls. You can set a VI to run reentrant by typing Ctrl-I (File >> VI Properties) and selecting the Execution category. Then click the reentrant checkbox.

You should note, however, that this can cause problems if two copies of the same reentrant subVI try to access the same digital line at the same time, causing a conflict. Non-reentrant VI's don't have this problem, since each subVI has to wait for the other calls to finish executing before it can start.

Also, up until LabVIEW 8 it was not possible to debug reentrant VI's. This feature has been added, however, making it possible to use features such as Highlighted Execution, Single Stepping, probes, etc.

You should also keep in mind that if you implement CoastalMaineBird's algorithm in a non-reentrant subVI, you will likely have the same results as using the Elapsed Time VI, since that is basicly all the Elapsed Time VI does under the hood. Consider modifying CoastalMaineBird's algorithm to include an array of elapsed times to check against in the SAME subVI (one array value for each time you call the subVI in your app).

I am posting a Multiple Elapsed Time subVI and a VI that calls it. This subVI can be called from a non-reentrant subVI and still have two completely independent timers. It will be easy to modify this approach to include 3 or 4 timers, but beyond that consider using an array-based structure. This example is written in LabVIEW 7.1. Let me know if you require an earlier version.

Jarrod S.
National Instruments
0 Kudos
Message 3 of 4
(4,878 Views)

Hi everyone,

I've written an example that can handle any given number of timers (by default it handles up to 32). This VI acts just like the Elapsed Time Express VI, except that it can be called independently inside non-reentrant subVI's. Along with the standard inputs like Reset, Auto Reset, Target Time, and so on, it has a Timer Number input where you can specify an index for a specific timer (0, 1, 2, etc.). If you make an input for your non-reentrant subVI for this index and specify different Timer Numbers for separate subVI calls, then they will act completely independently.

I'll attach it below with a simple example program that calls it. It's fairly easy to use. The first time you specify an index, that timer is automatically reset, so you don't ever have to explicitly call reset, though you can reset it at any time if you like. Let me know if it works out or if you have any other comments!

Message Edited by Jarrod S. on 11-22-2005 03:32 PM

Jarrod S.
National Instruments
Message 4 of 4
(4,867 Views)