From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

DAQmax read slow response

Hello all, I'm using cDAQ-9178, NI 9401,NI 9202 to control multiplexer and read analog signals. At the bottom while loop, when I select multiple channels multiple samples and 1D waveform, the plot waveform is responses very quickly to the sensor. However, if I choose multiple channels single sample and 1D DBL, and send to a for loop for calibration, the data responses very slowly to the sensor, a few seconds delays. Can anyone tell me what's the problem here? any solutions? Thank you very much. Attached is the VI.

0 Kudos
Message 1 of 5
(2,249 Views)

Check the datasheet for the 9202.  It is a very sophisticated device that performs a lot of filtering.  One caveat is a limited number of sampling rates.  Your choices are 10 and 50, yet your code specifies 40.  This selection may return an error, or round to either of the nearest choices.  Probe the error output from the read and see if there are any issues.  You can also read back the sampling rate to see how it was altered.

 

Also, cDAQ devices have more overhead than PCI devices and may not be able to transfer a single set of samples at 40 or 50 Hz.  You might be better off with the waveform output updating once per second.

Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.0, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
Message 2 of 5
(2,210 Views)

I don't know the hardware as well as Michael, but I do see that you are specifying 40 samples in Continuous Mode (Good) but are doing a DAQ Read of 1 Sample (Bad).  You are doing calibration, for goodness sake -- why not take 40 Samples (as you've specified in the Timing Module) which will properly "clock" the DAQmx Read function?  It will also obviate the need for a Build Array as you will already have a 2D array.  As a suggestion, if you specify 1D Array of Waveform, then you'll go back to a 1D Array, which will be an Array of Channels (which is what you want to process) and the data will already be a Waveform (so you won't need to "force" it into a Waveform to form "Unfiltered Signal").

 

Bob Schor

0 Kudos
Message 3 of 5
(2,198 Views)

I thought the while loop is set to running at 40Hz, so every iteration the DAQ read 1 sample, I'm expecting a column with 8 rows for 8 channels when I probe from the DAQ Read, and each number is updating at the set rate. If I set samples to read as -1 which will read whatever in the buffer, when I probe the output data, it is either one column or sometimes multiple columns. Should I use the timed loop?

0 Kudos
Message 4 of 5
(2,187 Views)

No!!!  Learn about DAQmx.  The loop that includes a DAQmx Read "times itself".  You (almost) never want to read one sample at a time -- you want to read a bunch.  Learn about DAQmx (that means find some tutorials that teach you about DAQmx).  Here's a very quick "top view":

  • DAQ hardware has a much better "clock" than your PC -- depend on it for timing.
  • You typically sample relatively fast.  Let's assume a (fairly modest) sampling rate of 1 kHz.
  • Suppose we specify a sample size of 1000 points.  At 1 kHz, this will take 1 second to acquire.  Let's configure our DAQ device to acquire 1000 points at 1 kHz, with "continuous sampling" (meaning as soon as the first 1000 points have been acquired, they'll be "delivered" (say as 8 1000-point Waveforms for 8 channels) and the next 1000 points will be acquired.
  • Put the DAQ Read in a loop all by itself, and put an indicator on the While Loop index, "i".  When you run the program, you will see the indicator "count" 0, 1, 2, ... , updating at precisely 1 Hz, i.e. every second.  The DAQmx Read inside the loop serves as the "clock" -- every second it delivers 1000 points for you to use.
  • How much CPU time do you think is occupied by this process?  I'm going to guess that it's a few milliseconds, at most -- more than 99.99% of the CPU time is available to you to do other things (like process the data "on the fly" as it is acquired).
  • Learn DAQmx.  Do not use a Sample Size of 1 (except in the most unusual circumstance, such as "I'd like to know the temperature when I start this study, but I don't need it during the study, so I'll take it once".
  • Learn DAQmx.  If you set up continuous sampling (which you did) and specify a sample size (of 40, which you did), wire that into the sample size of your DAQmx Read and specify multiple samples.
  • Learn how the DAQmx Read works (read its Help description).  You would learn that if you have 8 channels and you specify N channels N Samples, you'll get a 2D Array of Dbl or a 1D Array of Waveform (where you can expect 8 Waveforms, one per channel).
  • The Timed Loop is only for Real-Time Platforms (which a PC running Windows is not).
  • Do not specify a Samples to Read of -1 -- specify it as the number of Samples you specified in the Timing VI.

Yikes.  I got carried away.  Did anybody tell you not to use Local Variables until you have been using LabVIEW for at least a year?  [I just made up that rule -- a better one might be "Never use Local Variables", but that's too harsh].

 

So where did that last comment come from?  I was looking at your code (thanks for attaching it) and saw a Local Variable called "Saved Cals" and went looking for it.  One more suggestion:

  • Never start programming without a very clear idea of what you want to do (in broad strokes).  You should be able to write down (pencil and paper, or MIcrosoft Word, something) the "big steps" you want to take, with some indication of the nature of the data acquired or generated, and some of the major controls/decisions you need to make.
  • Try to think in terms of "Tasks" or "Steps".  This should give you some idea of Program Structure.  Repetition = loops, decisions = Case structure, iteration = For loop, simultaneous "processing on the fly" suggests parallel loops, etc.
  • Sub-VIs are your Friend -- they hide the "messy details" which you rarely need/want to see.  (I'm looking at a For loop labelled "Calibration Loop" -- double-yikes.).

Bob Schor

Message 5 of 5
(2,180 Views)