01-20-2016 06:25 PM
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.
01-20-2016 06:27 PM
Elapsed Time express VI.
And AND that with the conditional comparison.
01-20-2016 08:16 PM
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.
01-21-2016 09:43 AM
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.
01-21-2016 09:58 AM
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?
01-21-2016 10:50 AM
This is a perfect use of a reentrant sub-vi.
01-21-2016 11:12 AM
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.
01-21-2016 12:19 PM
@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.
01-21-2016 12:28 PM
Sorry- Should have asked what version of labview. Here is a 2010 version.
01-21-2016 03:05 PM
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.