Tuesday, August 5, 2008

U64 Millisecond Tick Count Utility

We all know and love the built-in tick count (mSec) function in LabVIEW. It unfortunately has two intrinsic limitations which, at one point or another, we've all probably encountered. The first is that its output is a U32, which means that it wraps after 2^32 - 1 mSec, or roughly every 49.7 days. The second difficulty is that we don't know when the wrap will happen; it could be tomorrow, or seven weeks from today. The value of the millisecond tick doesn't seem to be tied to any external temporal reference. Well, I've got a solution that at least tackles the first issue... it's the U64 Tick Count.vi shown below.




Its operation is pretty simple and self-explanatory. It's a functional global, in the sense of using uninitialized shift registers in order to maintain state data between calls. When the U32 time function wraps around, 2^32 is added to a running offset count, and the VI has a capability to properly initialize things on its first call. Since I use this in both Windows and RT applications, there's a Conditional Disable structure to provide the appropriate mSec tick function for each. (I'd like to post the VI itself for download, but I haven't yet figured out how to do this on Blogspot. If any of you intrepid readers could fill me in, I'd be grateful.)

With a U64 output, this millisecond timer will wrap approximately every 584 million years. I would guess that this should be sufficient for most applications.

6 comments:

crelf said...

"...this millisecond timer will wrap approximately every 584 million years. I would guess that this should be sufficient for most applications."

I sure hope do! :D

antoine.chalons said...

lol... that's even fairly enough for deep thought to calculate the answer to life, the universe an everything !

http://youtube.com/watch?v=3s24pT_NCts

Nice utility Bob, how about posting in LAVA's code repository ?

Yair said...

"The value of the millisecond tick doesn't seem to be tied to any external temporal reference."

No, but it's reset whenever you restart the computer (at least on Windows, and I assume that the other OSes do it the same way).

If you really wanted, you could probably get a log of when the OS started running last, but it wouldn't really be reliable because of users changing time settings, etc.

Keith Brainard said...

I would add that you have to mind your data types when using the U64, as any inadvertent coercion to another type could eliminate the extra precision you're relying on.

Regarding the Blogger file upload, it seems to me that you'll need another location to host the file, then you could link to it here.

Keep up the great posts!

Dave Korpi said...

Bob.. Hate to be a retard but can you show what is in the OTHER states of the T/F's???

Yair said...

Based on the description, the other cases probably just let the wire straight through. The bottom SR holds N*Max_I32, where N is the number of times the tick count has rolled over, so it's only modified when you start and when you roll over and add Max_I32 to it.