Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding elasped time data to data stored to spreadsheet

I have written a VI to read data from a serial port with the option to record the data to a spreadsheet. I probably have not done this in the most optimal way but it works. NowI would like to add elasped time to the data that is saved to the spread sheet. The data is read in a 400 hz so the timer must be in millisecond increments. I tried using one of the example from lab view but it did not work, the elapsed time would never start at zero. I believe it was starting in the timer from the point when i began execution of the program, not when the data started recording. I have attached my code. Basically they way i tried was to make a timer various ways and then feed that into another input in the spreadsheet. That feeding it into the spreadsheet worked fine, just never had the right time. Any ideas?
0 Kudos
Message 1 of 6
(3,925 Views)
Hello,

Are you trying to get the time elapsed since the program started for each time you read in data? Or are you trying to get the time imbetween each reading? I'm assuming you were using the Time to Match.vi example program, which is designed to return the amount of time it took the program to complete from when the start button was pressed. The way it works is that at the very beginning of the program, it passes the value of the counter into the while loop, getting an initial time. After most of the code is executed, the last thing it does is take the current value of the timer, and subtracts that from the original time it passed to the while loop.

I took a look at your code, and it looks like yours does the same thing... passes an initial time value to the loop, and then each iteration of the loop takes a new time and subtracts it from the original time. When you run this, you should have a gradually increasing time elapsed number. Is that what you are seeing?

john m
Applications Engineering
0 Kudos
Message 2 of 6
(3,916 Views)
Yeah, the time was increasing each time. That way would work, however the first time recorded does not = 0 and it would be nice if the first point started at zero. Also the last time i tried it, it looked like data was being recorded faster than ther counter could count because some of the subsquent data points had the same time recorded. However, i may have had the time formatted wrong that time, i can't really check because i only have labview at school, not here at home. Since the data input cycle at 400 hz there should be 2.5 ms between each point.
0 Kudos
Message 3 of 6
(3,913 Views)
Unfortunately, I do not believe you are going to be able to see the exact timing that you are wanting to see. I am assuming that you have a device that is putting out data every 2.5 ms. When this data goes into the serial port, it is actually stored in a first-in first-out UART until LabVIEW comes and gets it. So, even though you are going to be receiving data that was collected every 2.5 ms, the timing of the program will not be exactly the same. In fact, it's going to be dependent upon the system clock, and if any other programs are using a lot of processor time, the program may slow down a bit even though you will still be collecting the data at the same rate.

Hope this helps!

john
0 Kudos
Message 4 of 6
(3,897 Views)
Knowing that the data points are space 2.5 ms appart, is there an easy way to write some code that will start time at zero for the first step in the loop and then just add 2.5 ms each iteration after the first?
0 Kudos
Message 5 of 6
(3,891 Views)
We could try to implement something like this, but basing the time on the system clock is rarely able to be that accurate. The problem is that if something like VirusScan software kicks on and pulls some processor time, the loop might take a little bit longer to execute, and won't be exactly 2.5 ms.

If you just want to be able to display a number that reflects the time between the data that was collected, and you know that it was acquired every 2.5 ms, what about just using a numeric, starting it at 0, and then incrementing it by 2.5 each iteration of the loop?

john
0 Kudos
Message 6 of 6
(3,875 Views)