LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

Events counting and timing.

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.

Message 1 of 8
(542 Views)

Re: Events counting and timing.

Hi XDX,

One boolean function is enough to look for falling edges…

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…

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
Message 2 of 8
(521 Views)
Solution

Re: Events counting and timing.

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)

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 3 of 8
(502 Views)

Re: Events counting and timing.

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!

Message 4 of 8
(497 Views)

Re: Events counting and timing.

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.

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 5 of 8
(485 Views)

Re: Events counting and timing.

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

Message 6 of 8
(452 Views)

Re: Events counting and timing.

@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.

Message 7 of 8
(441 Views)

Re: Events counting and timing.

@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.

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 8 of 8
(429 Views)