| #GOOGLELINKS# |
LabVIEW programming topics - ms resolution timestamp
[LabVIEW vi collection]
[LabVIEW links]
[LabVIEW store]
[programming topics] [drivers] [utilities] [projects] [events] [related topics]
Introduction
The timestamp related functions in LabVIEW generate a timestamp with a 15.625 ms time step. The clocktick related functions generate a number of clockticks with a 1 ms time step. Basic IdeaThe idea is to catch an initial timestamp together with an initial clockticks# (number of clockticks). Each time a new timestamp is required, just read the new clockticks# and subtract the initial clockticks# and then add the difference (divided by 1000 going from milliseconds to seconds) to the initial timestamp. The CatchUnfortunately the clockticks# goes up to 2^23 - 1 and then wraps back to 0. That could take anyting between 1 ms and about 49.7 days to occur. But when it occurs the clockticks# goes downwards instead of upwards. This would make time go backwards which obviously is not the case in most laboratory experiments. The Solution
If the current clockticks# has gone past the 2^23 - 1 barrier then the clockticks# running since the initial clockticks# can be calculated as follows: The following images demonstrate how to calculate the proper number of seconds to add to the initial timestamp:
DownloadsThe following files were created with LabVIEW 8.5. You might need to do something similar to right-mouse-click and 'Save Link As...' to download these files.
AcknowledgementI thank Paul Rijkers for pointing out the 15.625 ms issue. Notes
Alternative WayKnowing that timestamp variables can hold a higher precision time, Paul Rijkers devolped an alternative set of vis.The core vi (Get_msTimeStamp.vi) provides an easy solution to the problem that occurs after about 50 days. After each call it just makes the intial time equal to the current time. The support vis (Launch_msTimestamping.vi and Init_msTimeStamp.vi) provide a way to initialize and occasionally call the core vi. This has the following advantages for other programs that need the ms timestamp:
Easier Still...
A discussion on Sub-millisecond timestamp, A better tick count [LAVA] suggests something very simple: subtracting two U32's (clockticks#) returns the right answer even if the clockticks# has gone passed the 2^32 - 1 barrier.
Bart Boshuizen, 2009/02/05
|
#GOOGLEADDS#
|