11-04-2008 02:00 PM
Hi Eric,
Thanks for posting back with an update. I am slightly confused by your questions regarding the loops and what you are seeing happen with the elapsed time VI. I am finding it hard to envision how your loops are interacting, so an attached screenshot or VI would be greatly appreciated. Regarding the elapsed time VI, it is free running and will not stop at any time once it is started. Measuring elapsed time in separate loops will return the same value for elapsed time (if they are both started at the exact same time), though the dedicated loop will update the time in smaller increments since it will be iterating faster and polling the elapsed time more frequently.
As far as what you are trying to accomplish, it appears from your above posts that you are trying to continuously acquire data for a specified amount of time and log this to a file. For data acquisition, you do not need to worry about when you perform the read within the while loop (caveat: you need to be reading enough to keep the buffer from overflowing if acquiring continuously). The actual acquisition is going to happen deterministically and this data will be placed in a buffer. Thus, no matter what amount of time occurs between reads in your program, you will always be reading data that was acquired by means of hardware timing since you are just pulling the data from the buffer, and this data is guaranteed to not have any sort of "gaps" from when it was acquired.
For example, if you have a buffer which can hold 1000 samples, and you set an acquisition for 1 second at 1 kHz, the hardware will acquire this data in 1 second and automatically place it into a buffer on your computer. You could, however, specify to read only 100 samples at a time in your program. So if you placed a 5 second wait within your while loop, you would have to iterate 10 times to read all the data, and this would take a total of 50 seconds. The data, though, will still be continuous within that initial 1 second.
Please let me know if I explained this clearly or if you have any further information regarding your loops. Thanks again for the post!
11-04-2008 02:33 PM
Thanks for that explanation, dansch. Now I know that I'm not losing data between iterations.
I've made a lot of progress the last few days, and now have a program that works without error for a 60 second acquisition. I'm using finite sample mode on the sample clock DAQmx VI, reading 0.5 second increments in the while loop, and writing to four measurement files using the express VI. The sample clock VI stops the task, but I was having trouble with the while loop continuing, so I stop the loop with some simple iteration count logic. Attached is the code.
Since my measurement files are getting all the expected samples written, I believe I'm okay. However, the "availsampperchan" property is reporting 50,000+ points being kept in the data. When I start the run, the first 10 or 20 iterations go without much (0 to 1250) samples in buffer, but then it baloons like something is slowing down the loop. However, towards the end of the acquisition that number decreases at the same rate. Would you happen to know why this is occuring?
Since it is working without error, we're going to use the code as-is, but I'd like to understand if I'm getting close to a buffer overrun.
Thanks for your help,
Eric
11-05-2008 11:22 AM
Hi Eric,
It sounds like everything is occurring as expected. The buffer is going to fill up at a constant rate, but your software is not going to be able to read at the same constant rate (due to OS lag and other processing in the loop including write to file). Even though you have a 500 ms wait in your loop, it is probably going to take a little bit longer, and thus your "available samples" amount will increase. It is even possible that the acquisition will finish before your loops finish reading. Thus, at some point, you will just be reading data from the buffer and no more data is getting put into the buffer (this is towards the end when the available samples value decreases rapidly).
Overall, because you are performing a finite acquisition, you do not ever need to worry about overflowing the buffer. The buffer will be exactly the size you specify for the acquisition as far as how many total samples you wish to acquire. No matter how slow you empty the buffer, the acquisition will stop when the buffer is full, which is exactly how many samples you wish to acquire. However, when you begin performing continuous acquisitions, this is when you will become concerned at the possibility of overflowing the buffer. This is because the buffer is still a finite size and at some point you will be writing over old data, which should have been read.
There is also a great explanation of buffering found in the DAQmx Help under NI-DAQmx Key Concepts » Reading and Writing Data » Buffering, which I would recommend anyone to read as it is one of the best concepts to understand regarding data acquisition. Hope this helps,
11-05-2008 02:47 PM
Daniel,
Thanks so much for your help. I am now confiden:t that I'm getting what I need from my setup and I'm a little more prepared for my next LabVIEW challenge, wherever it may be 🙂 .