09-27-2013 08:14 PM
Hi,
I'm trying to make a program that will read two analog inputs continuously, and once finished it'll spit out the data to an excel file. My problem is that my VI right now is running through the while loop for reading the data as fast as possible, and so I end up with huge excel files with nothing but 0's for readings in between the reads happening at the rate I specified. Is there a way to synchronize the while loop to run as often as I have set the sample rate for the DAQmx channel so I don't end up with all of these extraneous rows of data?
09-27-2013 09:08 PM
There are several solutions. If you are only collecting data at 1Hz you could do single sample collections or just add a "Wait Until Next ms Multiple" function to your main loop and set the input to 1000. These solutions would work for the program you posted, but there are better options, especially if you need to collect data at a faster rate.
09-27-2013 09:32 PM - edited 09-27-2013 09:37 PM
Why did you set the buffer size to be 1 when you wired a 1 into the Samples per Channel of the Sample Clock VI?
Are you getting errors on your DAQmx Read? You might be, but you won't know it. Put an indicator or a probe on that error wire.
The only way you'd be getting zeroes in your text file is if the DAQmx read is giving errors, it will return the default data of zero.
By the way, you aren't creating an Excel file. You are creating a text file. It just so happens if you open it in Excel, it will import the text for you.
At 1 sample per second, you could put the File writing into the while loop. You'd be better off passing the data to another loop using a queue in a producer/consumer architecture. What you are doing now is not good because you are creating a very large array, potentially running out of memory if you let the VI run long enough before hitting your stop button.
The question of "synchronize the while loop to run as often as I have set the sample rate for the DAQmx channel" makes no sense. The DAQmx Read is inside the while loop. So it is going to iterate once each time the code inside of it completes, and the DAQmx is going to run once fore each iteration of the while loop. One can't run any more often or less often than the other.
09-29-2013
03:06 PM
- last edited on
05-12-2025
09:11 AM
by
Content Cleaner
On the DAQmx Timing VI, get rid of the constant to the Samples to Read. When in continuous mode, that sets the buffer size. Leaving it unwired leaves the default buffer size, which is way larger than 1 samples. And for your DAQmx Read, I would change the polymorphic setting to be Multiple Channels, 1 Sample, 1D Array. It will make things a little simpler on you. And I fully agree with RavensFan that you should be using the Producer/Consumer in order to log your data while you acquire it. That will keep the memory usage down.