Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

"Data Samples Overwritten before being Read" Error?

I have been working on this issue for over 3 weeks, I am getting an overflow error (Data overwritten before read), and I can't seem to get rid of it. I tried sevral suggestions, but still can't get rid of it. I am using two counters Gated by PFI7 and PFI4 to measure RPM. Ctr1 is Once Per Rev counter, and Ctr0 reads time reference at every edge. In our application, we average RPM after certain # of Revs, say every 100 Revs, we average them and we get an RPM reading. But the problem is before the averaging, the buffer seems to occur with speed exceeding 1000 RPM which is not nearly close to what we are looking for. I am using 16E-4 series and it supposed to handle high RPM ( I am looking for RPM at around 5000. I appreciate any feedback or suggestions on this issue, or a way may be I can handle the buffer to make it stop overflowing. Here is a snipet of the code:

DAQmxErrChk (DAQmxCreateTask(

"Counter Task1",&taskHandle[1]));

DAQmxErrChk (DAQmxCreateCICountEdgesChan(taskHandle[1],

"Dev1/ctr0","Counter0",DAQmx_Val_Falling,0,DAQmx_Val_CountUp)); // Counter 0

DAQmxErrChk (DAQmxSetCICountEdgesTerm(taskHandle[1],

"Dev1/Ctr0","/Dev1/20MHzTimebase")); // Sets 20MHz as source clock

DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle[1],

"/Dev1/PFI7",40000,DAQmx_Val_Rising,DAQmx_Val_ContSamps,10000)); // using PFI7 as gate

DAQmxErrChk (DAQmxCreateTask(

"Counter Task2",&taskHandle[2]));

DAQmxErrChk (DAQmxCreateCICountEdgesChan(taskHandle[2],

"Dev1/ctr1","Counter1",DAQmx_Val_Falling,0,DAQmx_Val_CountUp)); // Counter 1

DAQmxErrChk (DAQmxSetCICountEdgesTerm(taskHandle[2],

"Dev1/Ctr1","/Dev1/20MHzTimebase")); // Sets 20MHz as source clock

DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle[2],

"/Dev1/PFI4",40000,DAQmx_Val_Rising,DAQmx_Val_ContSamps,10000)); // using PFI4 as gate

DAQmxErrChk (DAQmxStartTask(taskHandle[1]));

DAQmxErrChk (DAQmxStartTask(taskHandle[2]));

DAQmxErrChk (DAQmxReadCounterU32(taskHandle[1],360*RevsToAverage,TimeOut,TimeBuffer,BufferSize,&NumberReadOnTimeCounter,NULL));

DAQmxErrChk (DAQmxReadCounterU32(taskHandle[2],RevsToAverage,TimeOut,OncePerRevBuffer,BufferSize,&NumberReadOnOncePerRevCounter,NULL));

Reading Counter0 is producing BufferOverflow error, I did try doubling the BufferSize even 4X, it didn't help. So, I making the buffer for 72000 samples for example, so it gets the 72000 samples requested in the first iteration of the loop, but when it comes in the next iteration, I don't think the buffer is empty. I do free up the memory on the way out from each iteration too, I am wondering if there is any addiotional housekeeping that I have to dod for the buffer, as I thought NIDAQmx takes care of the flushing.

Thanks for your feedback

0 Kudos
Message 1 of 3
(6,492 Views)
Hi NewBe,

Thank you for posting on the National Instruments forums.

Is this the code that you are using in your application?  One thing that I see off hand is that you are setting up and starting the task, then reading channels, but there is not stop or clear.  Do you have a loop around your read section of code?  You should not be configuring or starting the task after you do your read.  If you want to do that, then make sure you have a close or clear task, depending on if you want to restart the task or reconfigure the task.

Another thing you can try is to for the numSampsPerChan to -1, which reads all of the data from the buffer each time you call the read function.  If that fixes your issue, then it means that you are not reading off of the buffer fast enough so it fills up and you get that overflow error.

Please let me know what you find after trying this.
Thank You,

Nick F.
Applications Engineer
0 Kudos
Message 2 of 3
(6,476 Views)
Hello Nick,
Yes, I do have a loop around the read part, I also do have a stop and Clear tasks after the read loop. I tried -1 and that didn't work. It is a Buffer Overflow error, My computer's spped is good too ( dual core, 4 G Vista). How Can I read the buffer faster? Playing with the sample rate didn't seem to do much either. I also tried mostRecent Sample  property as well as offset= -1*SampsToRead, seems to eliminate the problem, but it seems to skip good chunks of data between requestes (between loop iterations).
My Stop and Clear Task are positioned when exiting the program, when I hit (X) close the dialog, Do you think repositioing Stop and Clear to right after the read loop might solve the problem?
Thanks
0 Kudos
Message 3 of 3
(6,474 Views)