LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Millisecond timing rollover

According to the Online Help, LabView's millisecond timer rolls over every
2^32 ms (about 5 days). I need to use the timer repeatedly in a VI which
will run continuously over many days (for timeout errors). The times it
will be marking are only on the order of 5 seconds or so, but I don't want
a timer rollover to throw an error in the program. Is there a way to avoid
this, short of detecting when the timer is near its limit and putting in
an artificial wait while it rolls over?

To clarify, it's OK if the timer rolls over, but it cannot roll over in the
5 or so seconds during which I'm timing something. I have to time these
(approx.) 5 second intervals very very often, so it's very likely that a
rollover will happen eventua
lly, and I want to avoid problems with it.

Thanks!

Justin Goeres

Project Engineer
Indio Systems, Inc.
0 Kudos
Message 1 of 5
(5,222 Views)
Justin Goeres wrote:

> According to the Online Help, LabView's millisecond timer rolls over every
> 2^32 ms (about 5 days). I need to use the timer repeatedly in a VI which
> will run continuously over many days (for timeout errors). The times it
> will be marking are only on the order of 5 seconds or so, but I don't want
> a timer rollover to throw an error in the program. Is there a way to avoid
> this, short of detecting when the timer is near its limit and putting in
> an artificial wait while it rolls over?

As long as you're subtracting the output of a previous Tick Count call from
that of a subsequent one, I think you'll be in good shape as long as your
differential is less than 2^32 milliseconds, thanks to the vagaries of U32
math.

That is, (5 - (2^32 - 3))
= 9, and that is the correct millisecond differential
even though the timer rolled over, passed through 0, and ended up at 5.

Regards,
John Lum
National Instruments
0 Kudos
Message 2 of 5
(5,222 Views)
>thanks to the vagaries of U32
>math.

Two's compliment (singed) math must be used:

2^32 - 3 = 4294967296 - 3 =
4294967293 = FFFF FFFD = -3

5 - FFFF FFFD = 5 + (0000 0002 +1) =
5 + 2 + 1 = 8

or

5 - (-3) = 5 + 3 = 8
Randall Miller
0 Kudos
Message 5 of 5
(5,222 Views)
> According to the Online Help, LabView's millisecond timer rolls over every
> 2^32 ms (about 5 days). I need to use the timer repeatedly in a VI which
> will run continuously over many days (for timeout errors). The times it
> will be marking are only on the order of 5 seconds or so, but I don't want
> a timer rollover to throw an error in the program. Is there a way to avoid
> this, short of detecting when the timer is near its limit and putting in
> an artificial wait while it rolls over?
>
> To clarify, it's OK if the timer rolls over, but it cannot roll over in the
> 5 or so seconds during which I'm timing something. I have to time these
> (approx.) 5 second intervals very very often, so it's very likely that a
> rollover will happen eventually, and I want t
o avoid problems with it.
>

Actually, according the math I just performed, the rollover is about
every 45 days, not 5 days. Also, if you are subtracting two times,
which are unsigned numbers, then the delta will always work out
to be what you wanted, even when a rollover happens. A
small unsigned number after rollover minus a large unsigned
number before rollover, yields a small positive number.
Feel free to try it with something like a U8 to see for yourself.

So the rollover is a problem with any absolute times that you
might want to record, but doesn't affect deltas unless they
span more than one rollover -- in which case you can't tell the
difference between having zero, one, two, or any other number of
rollovers. As long as your time interval is less than 45 days
and the resolution of 1ms is small enough, then the built-in timer
should work well.

Greg McKaskle
Message 3 of 5
(5,222 Views)
"Justin Goeres" writes:

> According to the Online Help, LabView's millisecond timer rolls over every
> 2^32 ms (about 5 days). I need to use the timer repeatedly in a VI which
> will run continuously over many days (for timeout errors). The times it
> will be marking are only on the order of 5 seconds or so, but I don't want
> a timer rollover to throw an error in the program. Is there a way to avoid
> this, short of detecting when the timer is near its limit and putting in
> an artificial wait while it rolls over?
>
> To clarify, it's OK if the timer rolls over, but it cannot roll over in the
> 5 or so seconds during which I'm timing something. I have to time these
> (approx.) 5 second intervals very very often, so it's very likely
that a
> rollover will happen eventually, and I want to avoid problems with it.
>
> Thanks!
>
> Justin Goeres
>
> Project Engineer
> Indio Systems, Inc.


Justin,

a simple approach is to use a function that does no rollover: Get
date/time in seconds. It has less resolution than the milisecond
timer, but at 5 sec it should not be an issue.

A vague hint: VISA has built in timeout errors. Please don't waste
your time rewriting VISA I/O functions from the basic vi's. (OTOH I'd
like to do just that in some circumstances: My data disappears into a
"black" VISA box and reappears on the (serial) port, but I can't see
or change what is happening in between).

Johannes Niess
0 Kudos
Message 4 of 5
(5,222 Views)