LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to display and record elapsed time during instrument reading

Solved!
Go to solution

Elapsed time is one of the most useful Express VI for beginners (and not only for beginners sometimes !). There are many questions on this forum that would be solved by this VI.

0 Kudos
Message 11 of 22
(15,558 Views)

PRCalDude,

 

Here you go! Converted to 8.0

 

 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ben Sisney
FlexRIO V&V Engineer
National Instruments
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0 Kudos
Message 12 of 22
(15,549 Views)

"- Now there are 2 loops : 1 loop for acquisition (while loop) and 1 loop for user interface operations (while loop + event structure : this is a very powerful structure in LabVIEW and you should have a look at some examples to understand the way it works)"

 

I am confused by your vi.  I see only one loop, a WHILE loop,and below it is an ERROR IN-ERROR OUT wired together. 

 

I am desperately trying to understand how to measure (and USE the actual time value in a calculation) the time (milliseconds) in between voltage measurements, and I cannot find a clear explanation of the ELAPSED TIME function.  Using a sequence structure to subtract TICK COUNT function output was sternly rejected in favor of shift registers on the WHILE loop by other NI helpers, but, they didn't provide details about how to do it.  Can you suggest a simple way to measure the time (millisecond resolution) that elapses in between voltage measurements.  Here is what I want to achieve.

 

1.) Measure Voltage1 and convert to position 1

2.) Measure Voltage2 and convert to position 2

3.) Subtract Pos2-Pos1, and  divide by the time between VOLTAGE measurements to get the velocity.  (change in position divided by change in time)

 

It appears that shift registers on the WHILE loop will achieve this, but, I can't figure out how to use either the TICK COUNT or the ELAPSED TIME function to do it!!!! 

 

I am trying to teach myself about these time functions by creating "experimental vi's" and watching what they do.

For example, in the attached code, why don't the two methods of measuring time give the same result?  I am using shift registers to subtract the time measured by the TICK COUNT function, and I am using ELAPSED TIME function, but, I really don't understand how the ELAPSED TIME function is triggered and when it stops, in other words, how do you know what is the beginning and the end of the elapsed time it is reporting back to you?  How do you know the time that it takes one iteration of a WHILE LOOP, a FOR LOOP, or a CASE STRUCTURE to iterate.  I have read the DETAILED HELP on the ELAPSED TIME function many times, but, I can't figure it out.  For example, it says the "time target (1 second) is the amount of time that must elapse before the TIME HAS ELAPSED boolean is set to TRUE."  Does this mean it won't report a time value less than one second?  What the heck is the "TIME HAS ELAPSED BOOLEAN?"

 

Thanks for any advice you can give.

0 Kudos
Message 13 of 22
(15,332 Views)

Hello dav2010,

 

I'm glad to hear you're learning by doing! Did you look at both VI's in the ElapsedTime.zip file? The SimpleTimer.vi has the one while loop and error cluster you speak of but the Test_Stand_one_panel_report.vi has the two loop architecture including the event structure in the bottom one. If you look at the SimpleTimer.vi you will see they are using a Get Time/Date in seconds TIMESTAMP vi, which uses a different datatype than the elapsed time or tick count vis. I understand you're looking for ms resolution.

 

For the Elapsed Time express VI, the Time has Elapsed boolean is for the functionality like if you want a while loop to run for a specified amount of time (time target input), it will become true when that time target value matches the elapsed time value, and you could use that boolean to wire to the while loop stop button. You can set the time target input to whatever you want, but it will only take a second input, so yes, no less than one second. The elapsed time start time uses the Windows current time (if the value is 0) or it is set by the user input as an offset from 01-01-1904 00:00:00 as the context help says.

 

Looking at the detailed help of the tick count.vi, it " Returns the value of the millisecond timer. The base reference time (millisecond zero) is undefined. That is, you cannot convert millisecond timer value to a real-world time or date. Be careful when you use this function in comparisons because the value of the millisecond timer wraps from (2^32)1 to 0. "

On a Windows OS, you can't really know the time it takes one iteration of a for or while loop to within a few ms. Running LabVIEW or any program on a Windows OS can have a lot of jitter, but a real-time computing system is able to very reliably execute programs with very specific timing requirements. This could be something that may better fit your application: Do I Need a Real-Time System?

 

But to help you measure and use the actual time between voltage measurements, I would suggest taking a timeSTAMP value every iteration, (convert it to numeric if you wish) and subtract the two values to see the number of elapsed seconds. Here is a community example that may be helpful. Please let me know any further questions.

 

Thank you,

Deborah Y.

Deborah Burke
NI Hardware and Drivers Product Manager
Certified LabVIEW Architect
0 Kudos
Message 14 of 22
(15,086 Views)

Thanks, Deborah,

I will study the examples you suggested, but, I am confused about one point.  The end of your note suggests using a TimeStamp...isn't the resolution of the timestamp function only good for 1 second, as opposed to milliseconds?

Thank you again for the advice.

David

0 Kudos
Message 15 of 22
(15,071 Views)

Hello dav2010,

 

I apologize for the delay in response. Te get resolution finer than a second, you need to specify the format of the string if you want to see the decimal seconds returned by the time stamp. To do this, wire the 'Time Format String' input of the Format Date Time String block with %H:%M:%S%2u <-Here the number 2 is the precision of seconds I want, so my time string was '16:47:37.55'. The full list of format strings is found in the context help window when you hover the mouse over the Format Date Time String block. Also, check this article, How Can I Add My ms Value to a Timestamp Indicator?

 

Regards,

Deborah Y.

Deborah Burke
NI Hardware and Drivers Product Manager
Certified LabVIEW Architect
Message 16 of 22
(15,047 Views)

Thank you, Deborah.  That time stamp function will be very useful for me going forward.  I have an immediate need for it.

Dave

0 Kudos
Message 17 of 22
(15,044 Views)

Hi Deborah,

 

In your example, you use %H:%M:%S%2u.  Does this give resolution to 10ms?

 

If I used %H:%M:%S%3u, would that give me ms resolution?

 

I am sorry, but, this article, How Can I Add My ms Value to a Timestamp Indicator?, is extremely difficult for me to use.  It calls out 3 vi's, but, only 2 are shown, and it appears that the time stamp is the same no matter what.  It is extremely confusing what this vi does, and what the sub-vi does too.  The sub-vi has no START button.  I couldn't extract any useful information from it.

 

Dave 

0 Kudos
Message 18 of 22
(15,025 Views)

Hello Dave,

 

The %H:%M:%S%2u does give you ms resolution, note that 2 is the added precision of seconds I want, so my time string was '16:47:37.55' meaning 16hours, 47minutes, 37seconds, and 55ms.

 

I apologize that the VI wasn't as insightful, the description still gives one method of how to add the ms precision to timestamp, "You can use the Date/Time to Seconds.vi to convert the string to a timestamp data format. Then convert the timestamp to a double using the To Double Precision Float.vi. This will give you a double with the time in seconds without the ms precision. Next add the ms value to the converted double and use the To Timestamp.vi to convert back to the timestamp format."

 

Does inputting the %H:%M:%S%2u to the 'Time Format String' input of the Format Date Time String.vi give you the added functionality you seek?

 

Regards,

Deborah Y.

Deborah Burke
NI Hardware and Drivers Product Manager
Certified LabVIEW Architect
0 Kudos
Message 19 of 22
(15,005 Views)

Hi Deborah,

I am using this basic vi to identify output from a light sensor.  When the light sensor is activated, the boolean becomes true.  What I would like to be able to do is to identify the time of the BEGINNING of each TRUE, so I can time them, and subtract them to get things like frequency and velocity etc.  How can I make the timestamp activate only at the beginning of the TRUE.  The TRUE state might persist for a long time, e.g. 100 ms or so, and the OFF state in between, the FALSE will persist longer than that.

Thanks for your advice.

Dave

0 Kudos
Message 20 of 22
(14,987 Views)