LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

synchronise loop with computer time

Solved!
Go to solution

I would like to run a while loop exactly every 1 minute, with the minute occuring as per the computer time at 0 seconds.

 

a timed loop runs a minute after the loop is started and is not syncronised with the 0 seconds of the computer time.

 

how do I achieve this? I realise the first loop will be less than 1 minute due to the synchonisation.

 

0 Kudos
Message 1 of 6
(1,428 Views)

Use the current computer time and compare the number of seconds to zero.  If it is, do whatever it is you want to do in the While Loop.  If it isn't, then execute a false case of a case structure that does nothing.

 

 

Message 2 of 6
(1,420 Views)

I thought of doing this, but it then the main loop needs to run  at 1 second, when I only need it to be 1 minute.

is there another way?

0 Kudos
Message 3 of 6
(1,417 Views)

Why can't the main loop run at 1 second?

 

Just let it do nothing the other 59 seconds.  You really don't want slow running while loops because if the user hits stop, it will take 1-2 minutes for the loop to realize this and stop the while loop.

Message 4 of 6
(1,412 Views)
Solution
Accepted by topic author hydzik

thanks, that helped me.

 

i was initially thinking the 1 second loop would consume additional resources, but realised this is negligible.

 

I ended up using quotient/remainder on the computer time in seconds and checking when the remainder was 0, as this allowed for second interval.

0 Kudos
Message 5 of 6
(1,354 Views)

Technically there's a miniscule change you can miss a minute by this approach. As the windows timer isn't perfect and due to the multitasking the 1000ms wait can be a couple ms longer in some cases (not all the time). If this happens you could end up with the ms timer reading just before and after the '0'-second.

(It's basically the Nyquist theorem applied on these timings)

 

The solution is simple, check at a time that cant miss, e.g. 750ms. 🙂

If checking <500ms you'll have to handle the case of 2-3 hits during the same second.

 

A common solution is to store and compare to last used time, and when >=1min has passed, do action, set new last time.

 

/Y

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 6
(1,334 Views)