From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

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 10
(2,398 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 LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 10
(2,377 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)

 

 

Message 3 of 10
(2,358 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 10
(2,353 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

 

Message 5 of 10
(2,341 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

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 6 of 10
(2,308 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 10
(2,297 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.

0 Kudos
Message 8 of 10
(2,285 Views)

i want to know what is this and from where i find it ?

thanks 

joinde77_0-1674512752540.png

 

0 Kudos
Message 9 of 10
(1,409 Views)

@joinde77 wrote:

i want to know what is this and from where i find it ?

thanks 

joinde77_0-1674512752540.png

 


That's a Feedback Node

0 Kudos
Message 10 of 10
(1,401 Views)