LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I'm looking for a simple way to code an if statement that is dependent on the amount of time that has passed.

More simply, what I want is a way to code the following: If X>Y for at the last Z seconds, true. Else, false.

 

Basically I have a threshold voltage that I don't want to exceed for more than 2 seconds, but anything under 2 seconds is fine. I will use the boolean output to enable or disable a motor depending on this. 

0 Kudos
Message 1 of 17
(4,346 Views)

Elapsed Time express VI.

 

And AND that with the conditional comparison.

Message 2 of 17
(4,343 Views)

What RavensFan mentioned will only check if the condition was true at the point the time elapsed.

 

Instead use the Reset input of the Elapsed Time VI with the (negated) condition you're checking for. You basically want to reset the timer so long as the voltage is under the threshold. Once it goes over the threshold, the reset input will false, so the timer will run. If the voltage drops back below the threshold the timer will reset again. If the voltage stays above the threshold for 2 seconds or more, the Timer Elapsed output from the express VI will be true, and you can use this to stop the motor.




Certified LabVIEW Architect
Unless otherwise stated, all code snippets and examples provided
by me are "as is", and are free to use and modify without attribution.
Message 3 of 17
(4,298 Views)

If you want to avoid using an express vi you could try this one that I coded, but if you need to code for efficiency you should compare this to the express vi they mentioned. It may be faster. I didn't check.

Glad to answer questions. Thanks for any KUDOS or marked solutions 😉
Message 4 of 17
(4,232 Views)

Thanks for the input! 

 

RavensFan's recommendation is actually how I currently have it set up. This enables me to ignore the inital current rush when the motor is first turned one. 

 

MichaelBalzer's  recommendation is something I had already tried, but it doesnt function like we would expect it to. I've attached a snip of my code. After investigating with probes, what seems to be happening is that even when the reset input goes to false, it never stays counting and the timer elapsed output never goes to true. If I probe the elapsed time output it jumps up to around .1 occasioanlly, but always returns right back to 0.

 

Any other suggestions?

0 Kudos
Message 5 of 17
(4,222 Views)

I would also take a look at the MGI Library

http://www.mooregoodideas.com/mgi-library/

 

Look under timing there are some clean VIs for since last call etc.

0 Kudos
Message 7 of 17
(4,047 Views)

@kwalls007 wrote:

Thanks for the input! 

 

RavensFan's recommendation is actually how I currently have it set up. This enables me to ignore the inital current rush when the motor is first turned one. 

 

MichaelBalzer's  recommendation is something I had already tried, but it doesnt function like we would expect it to. I've attached a snip of my code. After investigating with probes, what seems to be happening is that even when the reset input goes to false, it never stays counting and the timer elapsed output never goes to true. If I probe the elapsed time output it jumps up to around .1 occasioanlly, but always returns right back to 0.

 

Any other suggestions?


I see you have things in a For Loop where you are working on multiple channels of the Analog Input.  Do you want for each channel to have its own independent timer?  In the For Loop, the timer is going to reset whenever any given channel tries to reset it.  It is one timer that affects all channels.  I doubt that is what your goal is.

 

I can't open Dave's VI to see what he is doing, but he does talk about using re-entrant subVI's.  But it sounds like what he is doing is probably what you want.  Bascially, you need to have individual timers, one for each channel.  A reentrant subVI (with preallocated clones) would allow you to keep the state of a particular timer separate from all other instances of that subVI and their timers.

Message 8 of 17
(4,167 Views)

Sorry- Should have asked what version of labview. Here is a 2010 version.

Message 9 of 17
(4,151 Views)

RavensFan wrote:

I see you have things in a For Loop where you are working on multiple channels of the Analog Input.  Do you want for each channel to have its own independent timer?  In the For Loop, the timer is going to reset whenever any given channel tries to reset it.  It is one timer that affects all channels.  I doubt that is what your goal is.

 

I can't open Dave's VI to see what he is doing, but he does talk about using re-entrant subVI's.  But it sounds like what he is doing is probably what you want.  Bascially, you need to have individual timers, one for each channel.  A reentrant subVI (with preallocated clones) would allow you to keep the state of a particular timer separate from all other instances of that subVI and their timers.


I do want each channel to have its own independent timer. I belive you have hit the nail on the head. 

 

I'll give Dave's VI a look and see what I can make of it. I'm not sure what re-entrant subVI's are, but I'm going to read up and see if I can implement something. 

0 Kudos
Message 10 of 17
(4,115 Views)