LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Events counting and timing.

Solved!
Go to solution

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

0 Kudos
Message 1 of 8
(541 Views)

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…

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
0 Kudos
Message 2 of 8
(520 Views)
Solution
Accepted by topic author Aladdin2020

Use a latch action button and high resolution relative time, e.g. as follows:

 

altenbach_1-1594308700195.png

 

(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 GCentral
What does "Engineering Redefined" mean??
Message 3 of 8
(501 Views)

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!

0 Kudos
Message 4 of 8
(496 Views)

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.

 

altenbach_0-1594310001361.png

 


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

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

 

image.png

Message 6 of 8
(451 Views)

@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

U32 Subtract 1.png

 

Larger number has rolled over and started counting up from 0, but subtract still gives the "right" (wrong?) answer.

U32 Subtract 2.png

Message 7 of 8
(440 Views)

@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 GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 8 of 8
(428 Views)