LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Data acquisition error

Hi,

 

I am trying to measure nutrient solution ions continuously. I am using NI USB 6343 and LabVIEW 2017. I tried to get/record 100data per second. But, the obtained data rate was not uniform and there was some time gap (like 3, 5 or 8 seconds).  I saw similar problems in the LabVIEW discussion forum. I modified the code inserting "wait(ms).VI" and replacing the "While Loop" by "For Loop". The problem remained the same. I can't understand, is it hardware or software problem? Eagerly waiting for your help...

0 Kudos
Message 1 of 10
(3,162 Views)

Simple, use 2 different loop. One with a priority to acquire all the point and another one that do analysis and save data.

Benoit

Message 2 of 10
(3,153 Views)

Hi Bseguin,

Thanks for quick reply. I am a little bit confused about the loop (While or For Loop). I have attached a picture here. Did you mean this?

0 Kudos
Message 3 of 10
(3,141 Views)

Not at all.

Your current solution will not run in parallel, but rater in serial.

Look at the design pattern: producer consumer, or queue.

Benoit

Message 4 of 10
(3,135 Views)

This is a "not-understanding-the-hardware-or-the-software" error.  Let me explain:

  • Consider the Dreaded DAQ Assistant (the Express VI at the left side of your code).  Consider what happens when this is in a loop by itself.  You configured the Express VI as N-Samples, 10 channels, with 100 samples acquired at 1kHz.  When the Express VI runs,  However, you wired in 100 samples at 100 Hz, so we'll go with that.  When the VI runs, it "blocks", waiting for (100 samples / 100 samples/sec) = 1.000 sec, after which it returns 100 samples.
  • If this was in a loop by itself, it would probably run slightly slower than once/second, as when it finished one loop (of N samples), the loop would restart and you would again ask for N samples.  On the other hand, if you set it up for continuous sampling, as soon as it finished the first 100 samples, it would both give them to you and restart the next acquisition even before the loop restarts.
  • OK, now put other "irrelevant, time-consuming" code inside the loop, say, selecting signals, doing computation using a Formula Node, and displaying 5 Waveform charts.  Remember the Principle of Data Flow -- the loop cannot restart until all the functions inside the loop have completed.  So the DAQ Assistant takes 1.000 second, and the remaining code, which has to run after the data has been acquired, takes X seconds, so the entire loop takes 1+X seconds (where X might not be the same each loop, as it depends on the data).
  • Note that if you have a loop with the DAQ, but no processing (as the first bullet point suggests), it will acquire and run at 1.000 loop/sec (if you have Continuous Sampling).  So what do you do?
  • Look up the Producer/Consumer Design Pattern.  The idea is as fast as the data comes into the (Producer) Loop, you put it into a Queue and dequeue it in another (Consumer) loop, where you process the samples, plot them etc.  You actually have a lot of time for this, as the moment the Producer gives you the data, it goes into its next Loop and effectively "waits" until the end of the loop, meaning the Consumer has an entire second (in your example) to process and plot the data.  And if it takes a little longer?  No problem, it will just start to fill up the Queue (and may "eventually" become a problem ..).

Bob Schor

Message 5 of 10
(3,114 Views)

Hello Bob Schor,

Thanks for your nice explanation. I have tried to modify my data acquisition code using "Queue" option. One of them is using DAQassist and another DAQmax. The DAQmax code shows some error. I can't understand how to fix that. In DAQassist code, I can't get my desired number of data. It gives 6~9 data per second.

Would you please check the code and find out the problem, please?

Download All
0 Kudos
Message 6 of 10
(3,098 Views)

OK.  First, you want to read the white paper Learn 10 Functions in NI-DAQmx and Handle 80 Percent of your Data Acquisition Applications.  Here are (some of the) specific problems with your code:

  • You correctly state that you are configuring a multi-channel set of AI Voltage Channels.  This takes a single DAQmx function -- you should not use a For loop (which will, in fact, loop only once, but will produce an Array of Channels instead of the desired "scalar" I/O Channel wire.
  • Your DDA (Dreaded DAQ Assistant) version of the code says you want to collect 100 samples at 1kHz (but incorrectly says to use N Samples instead of Continuous).  You are missing the DAQmx Timing Function, which should be wired with 1000 in "Rate" input, "Continuous" in Sample Mode, and "100" in "Samples per Channel".  This goes before the Producer Loop.
  • In the first bullet point, you removed the For loop around the Create Channel function, so you have a simple I/O wire going into the Producer.  Now remove the For Loop inside the Producer.  Change the Analog In to be NChan NSamp (it will do 9 channels, 100 samples) and branch the #Samples wire you used for the Timing Function and connect it to the number of samples/channel on the DAQmx Read.  Remove the timing function -- the DAQmx Read "times itself", using the much-more-reliable clock in your DAQ device (your PC has too many things going on simultaneously to be "trusted" for DAQ timing).  You should decide if you want a 1D Array of Waveforms or a 2D Array of Data.  Note that with a 1D Array of Waveforms, your Consumer becomes "Process N channels" (which "looks like" a For Loop, possibly with a Case Statement for differing Channels).  You can also use the For-Loop-Over-Channels with the 2D array structure, but you might need to transpose the 2D data array first (check if the rows are Channels or Samples).
  • Congratulations on using Channel Wires for connecting the Producer and Consumer (I'm a great fan, been using them for almost four years).

With those changes, it should be very close to being correct.

 

Bob Schor

Message 7 of 10
(3,080 Views)

Hello Mr. Bob_Schor,

 

Thanks again for explaining everything. I tried to modify according to your guidelines. But the problem remained the same. 7 or 8 data per second. Would you please check the code again?

0 Kudos
Message 8 of 10
(3,069 Views)

Hello Mr. Bob_Schor,

Would you please check the modified code because the problems remained the same... Eagerly waiting for your response. 

0 Kudos
Message 9 of 10
(3,030 Views)

Very strange.  Sometimes "simplifying" can suggest what's going on.  I'd suggest "simplifying" and running the following program:

Simple Sampling.png

This is your Producer, except (a) I added a DAQmx Start at the beginning (sometimes it will "auto-start", but I like to "be sure"), (b) removed the Consumer, simply throwing the data away, but (c) adding two indicators, one to show the loop "clocking" (it should count up once/sec, as you are sampling 100 samples at 100 Hz), and verifying that you are getting a 100 x 10 array out (it might be 10 x 100, let me know).

 

Bob Schor (technically "Dr. Bob", but who uses titles?) 

Message 10 of 10
(3,024 Views)