LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to make the high resolution relative seconds vi starts from zero after a boolean switch

Solved!
Go to solution

Hi everyone, 

 

I'm trying to program a case structure with a boolean element that contains the high resolution relative seconds vi so that when I switch the boolean from "false" to "true" the relative seconds starts counting from zero. 

 

In the attached vi I tried to make this happen. It actually works. However, when the boolean is "off" for couple of seconds it doesn't start at 0 anymore when the boolean is "true". It seems like the high resolution vi keeps counting even if the boolean is "false" and when it's "true" it starts from its last value which is not 0. 

 

I'm doing this to save the relative seconds in my TDMS-file later. 

 

I apreciate your help 😄 

 

best regards

 

 

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

Hi Ezzow,

 


@Ezzow wrote:

It seems like the high resolution vi keeps counting


The HighResolutionRelativeSeconds gives the amount of seconds since the computer was started. So yes: it keeps "counting" regardless if you call it in a case structure or not...

 

There are lots of threads in this board about creating (time) counters that can handle a "pause" condition gracefully. Search for them!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 10
(1,658 Views)

Hi GerdW, 

 

That's the first thing I tried before posting my problem. However, I couldn't find anything close .. it's hard to find a similar topic when you don't find the good search words .. 

 

 

best regards, 

Ezzow

 

0 Kudos
Message 3 of 10
(1,654 Views)

Hi Ezzow,

 

when you want to count the time when your application is "working" then you need to count only the time when the app is "working"…

 

Conclusion:

When the app is going into "pause" mode you need to store the timestamp of "pause start". When the app switches back into "working" mode you get the time difference between current time and "pause start" to know how long the pause was. You can use that time difference to correctly calculate the "working" time…

(You can do the same the other way around by keeping "working start" and "working stop" timestamps.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 10
(1,626 Views)

Hi GredW, 

 

I did exactely what you told me. But it still doesn't correct my "working time". Could you please take a look on the attached VI? 

 

 

best regards, 

Ezzow

0 Kudos
Message 5 of 10
(1,581 Views)

@Ezzow wrote:

Hi GredW, 

 

I did exactely what you told me. But it still doesn't correct my "working time". Could you please take a look on the attached VI? 

 


I at least can't. Not going to install 2021 on my machine which is used for development of existing projects in earlier versions. "Save for previous" would have made that possible.

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 10
(1,570 Views)

Hi Rolfk, 

 

attached is the same vi for earlier versions. 

 

We don't actually the "stop-time" to calculate the difference. You will recognize that: Difference = Start-Time * (-1) 

 

 

best regards, 

Ezzow

0 Kudos
Message 7 of 10
(1,561 Views)
Solution
Accepted by topic author Ezzow

That code is very hard to understand and you definitely got yourself into a gymnastic brain challenge with all those feedback nodes doing pretty nothing.

 

I would solve it this way: 

Active Timer.png

 

Generally I find shift registers easier to understand although functionally they are the same than feedback nodes (mostly). The middle shift register is actually an additional functionality. For your original problem it is not needed at all.

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 10
(1,539 Views)
Solution
Accepted by topic author Ezzow

@rolfk wrote:

Generally I find shift registers easier to understand although functionally they are the same than feedback nodes (mostly).


 

Personally, I prefer flat code (i.e. nothing hidden in stacks of case structures, for example).

 

Here is my "seemingly" functionally equivalent version:

 

altenbach_0-1669136769735.png

 

(These coercion dots are benign. mixed multiplications are efficient. The compiler knows what to do 😄 Also the feedback node for the ticker is easier because it allows correct global initialization so the difference is guaranteed to start with zero)

 

Message 9 of 10
(1,504 Views)

Thank you Rolfk and altenbach for your time! both codes seem to work perfectely 😄

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