LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculation of Time a Button has remained ON

Solved!
Go to solution

Dear All,
I want to calculate the ON time of a button and for this purpose i am using Timed loop, case structure and a button. The problem is when i press the button, the timer starts and indicator gets updated But when i turn the button OFF, it does not stop the timed loop. I am attaching the screenshot of the schematic. Please guide me in this regard,
Thanks in anticipation.

 

0 Kudos
Message 1 of 7
(1,048 Views)

You could do this easily with an event structure. 

Look for a value change event on the button. Store the time each time its triggered (either feedback node or shift register).

 

If the new value is false, subtract the previous time from the current time and you have the ON time.

 

deceased_1-1689852155335.png

 

 

 

 

Message 2 of 7
(1,032 Views)

Times are typically measured, not calculated.

 

Your snippet seems incomplete and broken. Why is there a local variable? Why is there no top-level loop? What's the mechanical action of the button? Are you using "continuous run" mode?

 

(Sorry, posting by phone, cannot run).

0 Kudos
Message 3 of 7
(1,029 Views)

You can do this by using Tick, call it every time the button is on then again when is off, then calculate the difference. 

0 Kudos
Message 4 of 7
(1,011 Views)

@LVNinja wrote:

You can do this by using Tick, call it every time the button is on then again when is off, then calculate the difference. 


I recommend "high resolution relative seconds" instead. Time will be in seconds instead of milliseconds.

0 Kudos
Message 5 of 7
(1,004 Views)

@deceased wrote:

You could do this easily with an event structure. 

Look for a value change event on the button. Store the time each time its triggered (either feedback node or shift register).

 

If the new value is false, subtract the previous time from the current time and you have the ON time.

 

deceased_1-1689852155335.png

 


One potential problem with that is if the button happens to be TRUE when the program starts. (not a problem in a build applications, though).

Message 6 of 7
(950 Views)
Solution
Accepted by RaoJaved

Here's what I might do. (modify according to the requirements, of course).

 

altenbach_0-1690026982217.png

 

Message 7 of 7
(947 Views)