LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Struggling to set a timer in my VI.

Solved!
Go to solution

Hi Gerd,

If I dont have the Elapsed Time VI in a case structure, it will just be counting up to infinity, and the 'TimeElapsed?' will be true at all times

0 Kudos
Message 21 of 27
(338 Views)

Hi lorc,

 


@lorc34 wrote:

If I dont have the Elapsed Time VI in a case structure, it will just be counting up to infinity, and the 'TimeElapsed?' will be true at all times


Did you read the help for ElapsedTime?

It offers a Reset input…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 22 of 27
(335 Views)

Hi Gerd,

Yes I know about the reset function. But lets say when the level is exceeded, I reset the elapsed timer, it will start counting from zero. Once it hits 4 seconds it will equal true. However, prior to resetting it, it was already equal to true, because its just going off to infinity.

0 Kudos
Message 23 of 27
(328 Views)
Solution
Accepted by topic author lorc34

Hi lorc,

 


@lorc34 wrote:

But lets say when the level is exceeded, I reset the elapsed timer, it will start counting from zero. Once it hits 4 seconds it will equal true. However, prior to resetting it, it was already equal to true, because its just going off to infinity.


I don't understand your problem.

  • When the time target has elapsed then the Elapsed output will switch to TRUE.
  • ElapsedTime will count time up until you Reset (or have AutoReset enabled).
  • When you reset the timer then it starts to count time starting from 0 and the Elapsed output will be FALSE as long as you don't reach the time target again…

What's wrong with this behaviour?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 24 of 27
(311 Views)

Hi Gerd,

 

I just cant figure out how to implement the VI the way I want using no case structure even with your latest message/advice

 

This should probably not be very hard. If it was a textual programming language it would only be a fine lines of code:

timer_started = False

start_time = None

turnGreenLightOn()

 

while True:

    if level_exceeded() and not timer_started:
        turnRedLightOn()

        turnGreenLightOff()

        start_time = time.time()

        timer_started = True

 

    if not level_exceeded() and (time.time() - start_time >= 30

        turnRedLightOff()

        turnGreenLightOn()

        timer_started = False

 

If the level does not exceed, the green light will be on.

 

If the levels DOES exceed, the red light will stay on even if the level becomes low again. It will ONLY turn back to green, once the 30 seconds has passed. (or if we push a button, but lets ignore that for now..)

 

If the level stays at an exceeding level, the red light will always stay on no matter what the timer does.

0 Kudos
Message 25 of 27
(292 Views)

I have the behaviour I exactly need working in this VI, with the only problem being, the ElapsedTime VI runs even when its case structure is not active. Its in the True case, and even when that case structure is wired False, it still runs in the background. If it did not run in the background, it would work exactly as I need

0 Kudos
Message 26 of 27
(285 Views)

Okay I have it working now based on what you said Gerd using the Elapsed time VI without a case structure. It uses a NAND gate with a true constant so that when the level exceeded is true, the reset is set to false and it records, and then the elapsed time goes to a shift register which resets the NAND input to false. 

 

Thank you for your help

 

EDIT: actually a NAND gate with a true constant on one input is just a NOT function 🙄

0 Kudos
Message 27 of 27
(273 Views)