07-20-2023 05:38 AM
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.
Solved! Go to Solution.
07-20-2023 06:22 AM
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.
07-20-2023 06:27 AM
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).
07-20-2023 07:42 AM
You can do this by using Tick, call it every time the button is on then again when is off, then calculate the difference.
07-20-2023 07:50 AM
@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.
07-22-2023 06:27 AM
@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.
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).
07-22-2023 06:56 AM