11-21-2005 08:18 PM
11-21-2005 10:52 PM - edited 11-21-2005 10:52 PM
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
Blog for (mostly LabVIEW) programmers: Tips And Tricks
11-22-2005 12:56 PM
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.
11-22-2005 03:31 PM - edited 11-22-2005 03:31 PM
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