From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Data acquisition and write to file in 1KHz

Hi all,

 

I am doing a very basic data acquisition task. As attched, I am trying to acquire data in the rate of 1 KHz (1-msec); and I would like to store this data into some file for further processing. I am saving the data in some .txt file with first column as time and second column as the analog voltage. But the problem is when I open the .txt file later, and I look into the time stamps in the 1st column, they are not in 1ms interval. In other words my sampling rate is varying between 1-2 msec, which is giving me the average of 1.65 msec sampling rate in the attached example. 

I just need to acquire and store data in 1KHz.

Is this due to the data acquisition block or the writing process, or the timed loop structure?? 

I appreciate any help on this case. 

 

Amir

 

P.S: attached to this post are:

1- "Data Acq and Wr at 1KHz.vi" which is labview code in Labview 8.6

2- "time and voltage.txt", which is the exemplary .txt file. as you can see the first column is the time stamp and the second column is the acquired voltage values.

 

Amir
Download All
0 Kudos
Message 1 of 6
(3,381 Views)

You are not using the DAQ device qujite correctly by doing a single sample read. Skip the timed loop and do a continous acquisition where you set the sample rate and number of samples to read. When you use an N Samp read, you get very precise timing between samples because you are using the hardware timing of the device. I would also suggest that you use a producer/consumer architecture if you want to save a text file.

0 Kudos
Message 2 of 6
(3,369 Views)

Thanks for you quick replies.

I was trying to get your advice into work by using a simple while loop. But that one did not work as well. the sampling rate is more than 3 msec. I attched the file below: 2nd file_Data....vi 

Also I need to say that I am kind of new to labview. So I definitely appreciate more elaborated responses and specifically solved exampled or codes.

 

 

Amir

 

 

Amir
0 Kudos
Message 3 of 6
(3,364 Views)

Amir,

 

What Dennis was talking about is called a Producer/Consumer architecture.  Look at the Design Patterns and examples which come with LV.

 

Basically, it uses two loops running in parallel.  The Producer loop has the DAQ Read VI and Enqueue, and nothing else.  The Consumer loop Dequeues the data and saves it to the file.  Key points: 1. Set the Read to read multiple samples each time it is called. You want the Single Channel, Multiple Samples, 1D DBL option. The number of sampples to read each time through the loop depends on the size of the buffer in the DAQ device, sampling rate, and other things. 2. Do the Create Channel, Sample Timing, and Start Task outside the loop.  After the loop finishes, Stop the Task and Clear the Task, also outside the loop. 3. Accumulate data and write to file in larger chunks and do it less often. You do not indicate how long the acquisition lasts, but writing a few thousands of samples to the file every few seconds probably makes sense.

 

Lynn

0 Kudos
Message 4 of 6
(3,360 Views)

Amir,

 

Refer to these examples for how to setup and use a producer/consumer loop.  Do not be specifically concerned with what the programs do, but how to programmatically make a producer/consumer loop in LabVIEW.

 

https://decibel.ni.com/content/docs/DOC-13770

https://decibel.ni.com/content/docs/DOC-16099

 

Regards,

 

Greg H.

Applications Engineer
National Instruments
0 Kudos
Message 5 of 6
(3,322 Views)

Hi again,

 

Please look at the attached file. Here is an example that shows the problem here I am trying to bring up. Actually this is a simplified example of my actual application, I have not included the second half of it in order to decrease the complexity.

As demonstrated I have two analago inputs that I need to read (position and acceleration) with SPECIFIC requirements which are.

 

1- I need to write the data into a file with the minimum 1-msec resolution, I will use this data for further proecssing in like Matlab. This mean 1Khz sampking rate which I have and it is ok.

2- At the same time I do make certain decisions based on the most recently acquired data in the "timed loop". The decision making part is not included in this vi. for the sake of simplicity. But the point is just that I need the most recent data (like online) to make some sort of decisions. 

 

Everything looks fine and it looks that I am collecting and writing data in a desired way. BUT I just found that the data that I am reading in the timed-loop is not the most recent one with respect to the actual sensors' output. The actual output value of the analog sensor in the DAQ terminal is like 100 msec in advanec. In other words there is a delay in this acquisition process. The value in the timed-loop is like 100 msec delayed from the actual input which is generated by the sensor and acquired by DAQ card. 

This problem makes my decision making part to constantly decide based on the value of 100-msec before. And this is terrible to my application, i.e. this is an intolerable delay for the process.

 

I appreciate if someone can help me with this application. I just need to collect data at 1KHz, as close as possible to real-time (online) or with minimum delay, not 100 msec.

 

Thanks.

 

 

Amir
0 Kudos
Message 6 of 6
(3,300 Views)