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.

I think I understand what Dave's VI is doing. There was no need to set up for reentrancy as Dave had already done this. The problem is, it seems to be doing the same thing as the Elapsed Time VI. 

0 Kudos
Message 11 of 17
(1,450 Views)

Here is a look at the probes. You can see the input is true but Elapsed(S) is still 0. 

0 Kudos
Message 12 of 17
(1,459 Views)

@kwalls007 wrote:

I think I understand what Dave's VI is doing. There was no need to set up for reentrancy as Dave had already done this. The problem is, it seems to be doing the same thing as the Elapsed Time VI. 


No.  There is the need for reentrancy.  Yes, Dave already did this for you in the subVI he posted.

 


@kwalls007 wrote:

Here is a look at the probes. You can see the input is true but Elapsed(S) is still 0. 


Are you sure it isn't working?  There are two things that could be going on.

 

1.  If this is a probe snapshot of the very first run that instance of the subVI has run, then of course the elapsed time is going to be 0.

2.  I can be hard to use monitor probes when you are looking at something running quickly.  The For Loop is running really fast.  It can go through multiple iterations of that loop before the probe window can update.  You aren't going to be able to see the data from each iteration because it runs really quick.

 

But the bigger problem here is that although the subVI is re-entrant, you only have one instance of it.  So each time it runs, it is only the one instance and the states of the other For Loop iterations are still affecting it.

 

I think what you need to do is take the concept of the elapsed time, but make it expandable.  Instead of having a subVI that tracks a single value and time, it should use arrays to track multiple values and times.  Use the i loop terminal as an input to the subVI to tell the subVI which index of the arrays you are working with.

 

By the way, that 2nd For Loop should probably just be merged with the first one.  They are both going to run the same amount of times.

Message 13 of 17
(1,434 Views)

I've come up with a way to make it work. I had to take the elapsed time concept and put it into a case strcuture. Since there was already a case structure nearby for the waveform charts, I just added to it. See the attached snips for the old vs new comparison. Dave_Brandt's OnDelay VI also seems to work as expected in this new structure. 

 

 

Download All
0 Kudos
Message 14 of 17
(1,372 Views)

You just turned a very simple timer into a complex timer when you used the sub vi into a for loop. The sub vi is called 1 time and ran many. This will not save the times for each index value in the array. You have to save the shift register data as an indexed array to work how you are using the timer.

0 Kudos
Message 15 of 17
(1,352 Views)

@Dave_Brandt wrote:

You just turned a very simple timer into a complex timer when you used the sub vi into a for loop. The sub vi is called 1 time and ran many. This will not save the times for each index value in the array. You have to save the shift register data as an indexed array to work how you are using the timer.


I'm confused. Why do I need to save the times? All I'm wanting to do is analyze the values live and if values exceeding the threshould are seen for longer than 2 consecutive seconds, shut the motor off. If I'm needing to store them in an array wouldnt that impy that I'm getting behind in analysing the values?

 

It seems to be working properly as it is... If I put the current reading over my threshold for 2 seconds, I get a true output and use that to turn my motor off. If the current reading is only over the threshold for 1 second, the output stays false and I never turn my motor off. But if my logic is truly flawed and will cause instability in my program or will potentially cause me to miss an over the threshold condition, please set me straight. 

0 Kudos
Message 16 of 17
(1,317 Views)

Ondelay_Array.png

 

The timer works by comparing a start time (When the input becomes true) and then each time the vi is executed it gets the current time and subtracts the saved start time to give you the delta time. When you use the subvi in a for loop the last iteration values are what is saved in the sub vi shift registers. The Delta time is then compared to the delay time and when delta time is greater than the on delay set point (2 seconds) then the out put is true and you you have delayed the output. If the input is false then it saves a new start time when the input becomes true again. 

 

 

Attached is how to use saved times in a for loop.

0 Kudos
Message 17 of 17
(1,302 Views)