11-22-2022 02:25 AM - edited 11-22-2022 02:27 AM
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
Solved! Go to Solution.
11-22-2022 02:35 AM
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!
11-22-2022 02:42 AM
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
11-22-2022 03:18 AM
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.)
11-22-2022 07:01 AM
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
11-22-2022 07:28 AM
@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.
11-22-2022 08:12 AM
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
11-22-2022 09:00 AM - edited 11-22-2022 09:03 AM
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:
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.
11-22-2022 11:07 AM - edited 11-22-2022 11:13 AM
@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:
(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)
11-23-2022 01:29 AM
Thank you Rolfk and altenbach for your time! both codes seem to work perfectely 😄