07-09-2020 09:12 AM - edited 07-09-2020 09:12 AM
Hi,
I’m building a program to count how many times I pressed the button and a timer that counts and displays the seconds (to 3 decimal places) between times that the button was pressed. So far, I was able to construct a simple VI to count the number of presses however, I’m struggling to Implement a timer that counts and displays the seconds between times the button was pressed. I would really appreciate any correction or feedback to point me in the right direction. My VI is attached.
Thanks in advance
Solved! Go to Solution.
07-09-2020 09:52 AM - edited 07-09-2020 09:54 AM
Hi XDX,
first i simplified your VI:
One boolean function is enough to look for falling edges…
@Aladdin2020 wrote:
I’m struggling to Implement a timer that counts and displays the seconds between times the button was pressed.
When the button (which you should give a better label, not just "boolean"!) is pressed you need to store the current timer value in a shift register. In the next iterations you simply subtract the stored timer value from the current value to get the elapsed time…
07-09-2020 10:32 AM - edited 07-09-2020 10:39 AM
Use a latch action button and high resolution relative time, e.g. as follows:
(You could also take the tick count difference and divide by 1000, but you need to ensure that the max time between pushes is below 2^32ms, about 49 days)
(I doubt you need milliseconds, though)
07-09-2020 10:44 AM
Hi altenbach,
Thank you for your help! I appreciate your time! Your solution is pretty creative and it’s exactly what I was looking for. So thank you again!
07-09-2020 10:53 AM - edited 07-09-2020 11:03 AM
Make sure to learn about the various mechanical action modes.
If you have a switch boolean, here's an easier way to tell whenever it goes from false to true. (no need for a pile of not equal, NOT, AND, etc.).
Similarly, use "less than" to detect TRUE>False transition and "Not equal" to detect any change.
07-09-2020 12:59 PM - edited 07-09-2020 01:00 PM
Though > and < operations on booleans in LabVIEW can work, I don't find it as natural as "regular" logic operations. Plus, I still carry some historic memory from a time & place where > and < would have failed. I avoid altenbach's "pile" of logic operators by using the "compound arithmetic" node which supports the option for inverting inputs and output individually.
It's a better fit for the way I think, to-MAY-to, to-MAH-to and all that.
-Kevin P
07-09-2020 01:44 PM
@altenbach wrote:
(You could also take the tick count difference and divide by 1000, but you need to ensure that the max time between pushes is below 2^32ms, about 49 days)
This is a bit off topic, but..
I think going over 2^32 ms in this case doesn't matter as long as you keep the data in the same representation. If you get to where that happens your result should be a negative number, but because LabVIEW is representing it unsigned and the sign bit is not even in the data anymore you will get the correct answer. Hard to explain but I think it's best shown as follows.
Approaching the maximum value for a U32
Larger number has rolled over and started counting up from 0, but subtract still gives the "right" (wrong?) answer.
07-09-2020 02:16 PM
@StevenD wrote:
Larger number has rolled over and started counting up from 0, but subtract still gives the "right" (wrong?) answer.
You don't have a problem at the rollover also long as the time difference is less than ~49 days. After that, the displayed time since last push will start again at zero even if the button has not been pressed for ~49 days! An incorrect result.
01-23-2023 04:26 PM
i want to know what is this and from where i find it ?
thanks
01-23-2023 04:48 PM
@joinde77 wrote:
i want to know what is this and from where i find it ?
thanks
That's a Feedback Node