LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Add time measurement from waveform to TDMS file

Solved!
Go to solution

Hi all,

 

I am measuring voltage using DAQmx and writing those measurements to a TDMS file with a time stamp. In my tirth column i'm trying to get the time in seconds. 

I build a new waveform with a time stamp starting from 0 and convert the time array so that it writs into the tirth column of my TDMS file. But for some reason this is not working, as you can see in the file I've attached.  

 

So what I want in my TDMS file is a column with the date/time, one with the voltage output and one with the sample time. ( In this case the sample rate is 1000  so I want the 0.001, 0.002, 0.003..... and so on in the last column).

 

 

Download All
0 Kudos
Message 1 of 9
(6,516 Views)

So just to be clear TDMS doesn't have columns.  If you are seeing columns it is likely being imported into Excel where it can be viewed that way.  What TDMS does have is channels.  The channel can have properties like when the channel sampling started and what the time between samples is.  Often times it is more efficient in file size to write this information once, rather than writing a new value with every sample.  That being said I can understand for report viewing purposes, that having a sample for each write is useful.  For getting relative time like that I usually just use a for loop adding dT for every sample.  Here is an example.

DAQ_BD.png

But as I said you can try to write the waveform the way it is and all this information will be written as channel properties.

 

0 Kudos
Message 2 of 9
(6,512 Views)

Thank you for your reply and clarification.
This solution is a lot more simple, I didnt think about it that way.

But my worksheet still doesn't show me the right value of dt.

As you can see in the snapshot below....

 

Capture.PNG

0 Kudos
Message 3 of 9
(6,471 Views)

Hi Cappon,

 

you need to keep track of the overall amount of samples written to your TDMS file.

Right now you create dt values just for those 10 samples read in one iteration, again and again…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 9
(6,462 Views)

I'm not sure how to fix the problem with the samples.

Later in the file, it reads more than 10 samples, but at some certain point it goes back to zero again.

 

Capture.PNG

 

 

0 Kudos
Message 5 of 9
(6,458 Views)
Solution
Accepted by topic author Cappon

Hi Cappon,

 

I'm not sure how to fix the problem with the samples.

You already use ArraySize to know the number of samples from last DAQmxRead function.

All you need to do is to keep the overall number of samples by adding the "sample per loop" in a shift register.

When the number of samples is fixed for DAQmxRead then you just need to calculate "number of iterations" * "samples per iteration"…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 9
(6,455 Views)
Solution
Accepted by topic author Cappon

Oh you are so right, sorry I missed that.  This should keep it from going back to zero once in a while.

 

DAQ_BD.png

Noticed that here we start at 0, and add dT for every sample we get, but keep track of where we left off with a second shift register so that the next time we take a reading out time continues where it left off.

Message 7 of 9
(6,443 Views)

Thanks for the reply all.

I solved it with this:

Capture.PNG

Not sure if it's 100 % correct, but it works!

0 Kudos
Message 8 of 9
(6,441 Views)

Hello,

I'm trying to achieve the same functionality but without using a for loop, as it needs time to execute N iterations, there for increases the execution time of the overall while loop.

In my case, I'm sampling 2000 elements at a time, so N = 2000. When I rewrite the code without the for loop, it still counts correctly, but there are only X time values, where X = (Total number of samples) / N.

Do you have any suggestions on how to solve this issue more efficiently?

Is there maybe another way to get time out of Waveform? Or out of Cluster?

Thank you for your help!

Code.png

0 Kudos
Message 9 of 9
(220 Views)