06-06-2024 08:08 PM
Hello all,
I'm using a USB-6009 to read voltage signal from 3 sources. I have it reading 3 signals at the moment and writing data to a text file. When i plot the data in excel, i get 3 stepped plots attached below. I was expecting 3 linear plots with a positive slope not a stepped plot. I'm running a tensile test. My guess was it had to do with my sampling rate, number of samples read, and my wait time for the while loop, so i changed my sample clock parameters. My sampling rate was 1000, # of samples to read was 250. I changed both to 50 and 50 respectively, while leaving my wait time interval as 20ms (same as previous run). I then get the linear plots i predicted but then after a while the value drops off suddenly while the test is still running (pic2 below). Can anyone help me understand how to set the parameters appropriately for a 5 minute long test?
PS. I need the wait time set at 20ms, because i need to synchronize this data with another one. So, how do i set the sampling rate and # samples to continue to feed the right amount of data?
I have attached VI below.
Thanks
06-06-2024 08:57 PM
Several comments.
Bob Schor
06-06-2024 10:22 PM
Hi Bob,
Thanks for your reply. I've re-uploaded a 2019 file. No, I can't say I know about Producer/Consumer loops.
06-07-2024 01:18 AM
Hi femicu,
@femicsu wrote:
I'm using a USB-6009 to read voltage signal from 3 sources. I have it reading 3 signals at the moment and writing data to a text file. When i plot the data in excel, i get 3 stepped plots attached below. I was expecting 3 linear plots with a positive slope not a stepped plot. I'm running a tensile test. My guess was it had to do with my sampling rate, number of samples read, and my wait time for the while loop, so i changed my sample clock parameters. My sampling rate was 1000, # of samples to read was 250. I changed both to 50 and 50 respectively, while leaving my wait time interval as 20ms (same as previous run). I then get the linear plots i predicted but then after a while the value drops off suddenly while the test is still running (pic2 below). Can anyone help me understand how to set the parameters appropriately for a 5 minute long test?
Simple suggestion: Setup the DAQmx task as you do, but use the DAQmxRead in the "N channels N samples" mode and read waveforms!
06-07-2024 08:13 AM
Thanks for attaching your VI saved for LabVIEW 2019.
I largely agree with @GerdW, but have some additional "teaching" comments
I don't think you fully understand how DAQmx works, specifically the modes for A/D Clock setting. You (correctly) specified you wanted to sample at 50 Hz, and collect 50 samples at a time (so that the Analog A/D Read should fire once and return 50 (not 1) samples), but you also specified "Finite Samples" (because you didn't wire the Sample Mode input on the top left of the Sample Clock VI, right next to Sampling Rate).
A related "mis-understanding" is (as Gerd pointed out) you asked for only 1 sample in your A/D Read. This should be 1D Wfn NChan NSamp which will read and return all 50 samples you specified using "Continuous Sampling". Not only that, but while it is giving you those data, it is continuing to sample, so you don't miss any samples and you don't lose any time in getting the data from the A/D.
Suppose you do nothing else in this loop, just throw the data away, no plotting, no saving to disk. What will happen is once a second, the A/D will give you 50 more points until you stop the loop! The timing is all done by the DAQ hardware, which is much more accurate and precise than your PC's clock (which powers the LabVIEW "Wait" functions. So get rid of all of the timers (the DAQ hardware should always show a loop time of 20 ms).
I think you should be plotting your data on a Chart, not a Graph. Charts "scroll", so as points come in, the Chart moves to the left, showing the newer points on the right. New points come once/second, so if you wired the output of the A/D directly to a Chart, you should see N plots "jumping" every second as new data come in. A second should be more than enough time to "process" these data (and, after all, once the DAQ Read gives you a sample, it won't have anything else to do for another 0.9995 seconds, more or less).
But suppose you wanted to plot, not the data, but an Time-Spectrum of the data (or some complex function that would take occasionally more time to process). That's where the Producer/Consumer Design Pattern comes in. When you get the output from the DAQ Read (once/second), you "export it" from the Data Acquisition (a.k.a. "Producer") Loop via a Queue, or a Stream Channel Wire, and send it to a separate free-running Data Processing (a.k.a. "Consumer") loop that does the complex processing. For example, you might want to stream the data to disk, but might not want to open the disk file until you got the first batch of data. No problem -- as long as the writing of the data itself can be done in less than the 1 second between acquisitions, if it takes a little more time to open the disk files for writing, the data will be "stored" in the Queue or Stream Channel until the "writer" can write them all out.
One more thing I just noticed -- you are taking the Waveforms you get from the DAQmx Read and are adding an additional "Elapsed time" to each data point. This is unnecessary, inaccurate, and slow -- let the hardware do this for you, that's why NI designed the Waveform data structure to do.
Bob Schor