LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Remain in a state for ms instead of seconds?

I have used the "get date/time in seconds" VI to keep a state machine in a specific state for a certain number of seconds in the past and am wondering what a recommended method to do this for a certain number of milliseconds would be?
 
Thanks,
 
David
0 Kudos
Message 1 of 8
(3,024 Views)
I have been considering using the millisecond timer but would rather not deal with the wrap condition- the example the help file leads to does not seem to handle that situatoin at all...
 
If that's the best way to handle this situation, let me know.
0 Kudos
Message 2 of 8
(3,018 Views)
What do you mean by "wrap condition"? There is nothing to "handle". The difference will always be correct even if the number would roll over between the two tick counts (unless you wait longer than 2^32 milliseconds, of course).
 
Try it!
Message 3 of 8
(3,014 Views)

I mean what you guessed- if the timer wraps around to 0 (after 2^32 ms).  I decided to check if the second value is less than the first value and raise an error in that case.  I thought about writing a sub-VI that would do the extra math in the case that the timer does wrap around but in my case I don't think it's necessary.

 

David
0 Kudos
Message 4 of 8
(2,958 Views)
That's the beauty of unsigned integer math:
 
In case of U32:
 
50 - 20 = 30
20 - 4294967286 = 30
 
🙂
 
As long as the total elapsed time is within (2^32 -1) ms, you're fine. You have 40++ days before your difference starts over at zero.
Message 5 of 8
(2,949 Views)

Hmm,

This is very intriguing - I had always used the "Get time in seconds" VI, as it does give you fractional seconds. But, running a few tests just now showed that I could really only get a precision of about 15ms, rather than the 1ms resolution I can get with the millisecond timer. Thanks for bringing up the subject guys!

Also, davey31415, I am not sure you really need to produce an error on rollover. Say we have a very cheap timer that rolls over from 99 back to 0 ms. If we read time1=95ms and time2= 3 ms, we can figure out that eight seconds have passed. The math is essentially T2-T1 + range or 3-95= -92, -92+100=8 [the number line is a zero-index array, so 0-99 is 100 points]. So, if T2-T1 is <0, then add 2^32ms.

Most likely there is a more elegant way to do it, but that's my thought.


Data Science Automation

CTA, CLA, CLED
SHAZAM!
0 Kudos
Message 6 of 8
(2,948 Views)

That's great to know- never realized unsigned integer math worked out that way.  Thanks!

 

David

0 Kudos
Message 7 of 8
(2,929 Views)
Oh, the Elegant solution arrived while I was typing. Kudos to Altenbach!

Data Science Automation

CTA, CLA, CLED
SHAZAM!
0 Kudos
Message 8 of 8
(2,906 Views)