06-25-2007 04:19 PM
Aaron-
To address your other question, arbitrarily modifying the read index to match the write index is probably dangerous to do in terms of alignment of samples in the buffer. Certain devices might transfer data in fixed-width chunks (for example, 32-bit transfers are common on some S Series devices). So, if your number of channels changes then the actual buffer contents might not always represent full scans. If the library reports a buffer overflow and your code adjusts the read index in response, it is possible that you will be adjusting the index into a buffer position that effectively represents the middle of a scan rather than the beginning.
A better bet would be to leave the read index as-is and briefly test for erroneous overflow errors (for example, you might incorrectly interpret the off chance that the DAR is less than the FIFO count as a negative number of samples in the buffer. This is probably the most obvious case to test for).
06-25-2007 11:23 PM
06-30-2007 01:44 PM
07-02-2007 11:41 AM - edited 07-02-2007 11:41 AM
Hi Aaron-
The second condition monitors for the unlikely chance that the DAR rolls over while there are samples buffered in the DMA FIFO. The danger in this situation is that DAR-fifoCount would then be "negative", but since we're using u32 it would be interpreted as a very large number of available samples. This would lead to a (very!) inaccurate sample count and an almost guaranteed erroneous buffer overflow error. I agree that the loop will almost always terminate based on this condition, so a better option than having it might be to simply use your implementation for the do...while conditional and then test for a negative number of samples (i.e. DAR < fifoCount). You might add another flag/return value to indicate the snapshot's validity based on the occurrence of that condition.
Of course, the DAR rolls over anywhere from very seldom (for M Series) to seldom (for faster devices), so the chances of actually hitting this condition are probably slim. It's still good to account for it, though, for robustness.
Let me know if you have other questions. Thanks-
Message Edited by Tom W [DE] on 07-02-2007 11:41 AM
07-02-2007 08:59 PM - edited 07-02-2007 08:59 PM
Message Edited by A squared on 07-02-2007 10:00 PM
07-09-2007 03:56 PM
Hi Aaron-
The positioning and functionality of the rollover check you added seems reasonable enough to me. How is it working in practice on your system?
Thanks-
07-09-2007 06:02 PM
07-10-2007 09:25 AM
Hey Aaron-
Glad to hear it- let me know if you run into anything else.
Thanks-
06-25-2009 12:29 PM
Tom,
I have found the same problem as Aaron and I wanted to say thanks (to both of you) for the detailed explanation and making the code fix available here on the forum.
I can certainly cut and paste the code posted here into my own stuff, but it makes me wonder what other fixes are out there for problems I don't even know about. I re-checked the code downloads to see if there have been any recent updates (i.e. ftp://ftp.ni.com/support/daq/mhddk/misc/dma.zip), but all of the DDK code there looks to be dated a few years old. Is there any other download location that might have the "latest" code that I could review to see if there are any other problems that I should be aware of?
Thanks,
AJ
07-06-2009 08:25 AM
Hi AJ-
I updated the files at the MHDDK download site just now, so you can download the most recent updates (as of 06 July 2009) from the link you mentioned. To anyone interested in the "old" files that have been posted for a long time before today, I archived them here: ftp://ftp.ni.com/support/daq/mhddk/backup/06July2009/