Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Buffer Overflow -200141

Hello,
I modified the very simple example "Cont-Ext-Buff-Cnt" to use 20MHz source clock and connected the signal of my encoder to gate. I can read fine with slow RPM, 1000 or lower. But I do get Overflow problem (-200141) for RPM > 1000. I am using 16 MIO E series card. I changed the BufferSize, Rate, # of samples, but still had the same problem over 1000 RPM. I am using Visual C++ 2005/NIDAQmx8.5/Vista. My processor speed is very good. Here is a snippet of the code I am using. Could anyone help me with this issue, or had a similar situation?

DAQmxErrChk (DAQmxCreateTask(

"",&taskHandle));

DAQmxErrChk (DAQmxCreateCICountEdgesChan(taskHandle,

"Dev1/Ctr0","",DAQmx_Val_Rising,0,DAQmx_Val_CountUp));

DAQmxErrChk (DAQmxSetCICountEdgesTerm(taskHandle,

"Dev1/Ctr0","/Dev1/20MHzTimebase"));

DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,

"/Dev1/PFI7",200000,DAQmx_Val_Falling,DAQmx_Val_ContSamps,3600));

DAQmxErrChk (DAQmxStartTask(taskHandle));

while(i < 100) { // # of iterations

i++;

DAQmxErrChk (DAQmxReadCounterU32(taskHandle,1800,TimeOut,Buffer,3600,&ReadOnTimeCntr,NULL));

printf(

"\rTime=%d at loop=%d",ReadOnTimeCntr,i);

fflush(stdout);

}

0 Kudos
Message 1 of 6
(9,107 Views)
Hello NI_Problem,

First of all, welcome to the NI Forums!  Secondly, I hope the screen name isn't a comment about National Instruments.

The error code you referenced is undefined meaning that the error code is not directly associated with an error.  It would help with troubleshooting if you could post the exact text of the error as well.  By overflow problem, do you mean a buffer overflow or a counter overflow? 

If it is a buffer overflow, then increasing the number of samples to read should take care of the issue.  It appears that this may be the problem since the code you posted shows a sampling rate of 200k, but the samples to read is only 1800. A good starting point is to have a samples to read of 10% of your sampling rate (e.g 20k). Also increasing the samples per channel to aquire in you timing call (set to 3600) may increase the buffer size.

If it is a counter rollover issue due to the RPM of your encoder, the way to solve that would be to combine 2 counters to make the rollover value higher (counter 2 increment when counter 1 rolls over).

I found an interesting article on how our buffers work and some errors that may be on interest to you. Post back if this works for you or if you have any more questions.
Neal M.
Applications Engineering       National Instruments        www.ni.com/support
0 Kudos
Message 2 of 6
(9,095 Views)
Hello Neal,
Thank for the reply, and No, the name is not a comment about NI.
I tried your suggestions and still couldn't get it to work. I think the error is Buffer overflow and here what it says: " DAQmx Error: Measurements: Data was overwritten before it could be read by the system.
If Data Transfer Mechanism is Interrupts, try using DMA. Otherwise, divide the input signal before taking the measurement.Task Name: _unnamedTask<0> Status Code: -200141".  I think the "E" card uses DMA automatically, and I don't like to divide the signal of the encoder, as I know it worked before using traditional drivers. Here is the code I am using, this code fails when the RPM of the encoder exceeds about 1300 RPM or so (360 Samps/ Revolution).  I don't know what I am missing as I would think this example would be very trivial.

int

main(void)

{

int error=0;

int i=0;

TaskHandle taskHandle=0;

int32 read;

uInt32 data[8000];

char errBuff[2048]={'\0'};

float64 Rate = 80000;

/*********************************************/

// DAQmx Configure Code

/*********************************************/

DAQmxErrChk (DAQmxCreateTask(

"",&taskHandle));

DAQmxErrChk (DAQmxCreateCICountEdgesChan(taskHandle,

"Dev1/ctr0","",DAQmx_Val_Rising,0,DAQmx_Val_CountUp));

DAQmxErrChk (DAQmxSetCICountEdgesTerm(taskHandle,

"Dev1/Ctr0", "/Dev1/20MHzTimebase") );

DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,

"/Dev1/PFI7",Rate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,50000));

/*********************************************/

// DAQmx Start Code

/*********************************************/

DAQmxErrChk (DAQmxStartTask(taskHandle));

printf(

"Continuously reading. Press Ctrl+C to interrupt\n");

while( 1 ) {

/*********************************************/

// DAQmx Read Code

/*********************************************/

DAQmxErrChk (DAQmxReadCounterU32(taskHandle,8000,10.0,data,8000,&read,NULL));

printf(

"\rAcquired %d samples",read);

fflush(stdout);

}


0 Kudos
Message 3 of 6
(9,092 Views)
Hi again NI_Problem,

There are 3 DMA channels on most of our E series cards, and they should be used automatically.  You can check this easily with the DAQmxGetCIDataXferMech function, and then set it with the DAQmxSetCIDataXferMech function if for some reason it is not DMA.

The three options from the article from my first post are still good to try:
1.  Increase the number of samples per channel with the DAQmx Timing VI.  (Increases buffer size)
2.  Increase the number of samples per channel to read with the DAQmx Read VI.  (Reads faster)
3.  Decrease the samples per channel rate with the DAQmx Timing VI.  (Write slower)

If you go too far, you'll get a buffer underflow error. Your error is slightly odd since it says there is a buffer overflow error, but then the comments sound like it is a buffer overwrite error.  The suggestions above from the article are for a buffer overflow error.  If the issue is an overwrite error, then the problem is with the amount of memory on the card FIFO, not with the circular buffer on the computer.  In this case, the list of things to try are:

1.  Use a Direct Memory Access (DMA) transfer mechanism rather than an Interrupt Request (IRQ) data transfer mechanism.  DMA is faster than IRQ and can improve performance significantly.  For more information about using DMA, refer to the NI-DAQmx Help and the DAQmx Channel Property Node, Data Transfer Mechanism property.  (Note: DAQCard and USB devices do not support DMA.)
2.  Decrease the samples per channel rate with the DAQmx Timing VI.
3.  Disconnect other devices that may try to share the PCI bus.

This would make sense since you are using buffered counters and latching values into that buffer at 20MHz. I do not know your application or what hardware you are using, but this seems a little excessive since at 1300RPM, your encoder is going under 500kHz.  This means at that rate, you are getting 40 values of the same count.

Usually what we do for the counter sample clock is to start an analog task (AI or AO) and use its sample clock (e.g. Dev1/ai/Sample Clock) instead of the 20MHz timebase.

Take a look at the article I linked above and the one in my previous post, that should explain a little better. I hope this helps, if I am misunderstanding your application or I did not explain this well, post back.
Neal M.
Applications Engineering       National Instruments        www.ni.com/support
0 Kudos
Message 4 of 6
(9,079 Views)
Hi Neal,
All I am trying to do in this example is gated readings. The 20 MHZ Timebase is my source Clk, and The encoder is hooked up to the gate and acts as the sample clock. On the rising edge of the Gate, I want to latch the count (Edges Count of the 20 MHZ Src Clk) into the buffer. I didn't quite understand your explanation ,So, if the encoder is spinning at 1500 RPM= 25R/Sec=25*360 S/Sec= 9000 S/sec. How could this be excessive if the Card can handle up to 500KS/s ? I also tried 100KHZ as source Timbase, still didn't get rid of the problem. If this is not the correct way of doing Gated readings, How would you go about achieving the above?
Thanks
0 Kudos
Message 5 of 6
(9,076 Views)
NI_Problem,

Sorry for the confusion,  I did not look at your code closely enough and then my calculation was wrong.  I assumed that you were trying to do a position reading, and it appears you are actually trying to do a velocity (or frequency) measurement.  What I was trying to point out was that if you had your source as your encoder signal and your gate as your 20MHz timebase, you would be repeatedly reading the same values.

The error you are describing is occuring with the FIFO on the card.  This is dependent on your sample clock (gate), not on your source, so it would make sense that the timebase you are using does not affect the behaivior.  I would reccomend making sure that your device is using DMA (with the DAQmxGetCIDataXferMech) to make sure you can get data off of the FIFO as fast as possible.  Another thing to try is to use -1 as your samples per channel to aquire in  your DAQmxCfgSampClkTiming.  This will read all of the values available in the FIFO instead of limiting it.

What exactly is the goal of this program? There may be a better way to go about this.  For example, if you are trying to do a frequency measurement of your encoder, the DAQmxCreateCIFreqChan task might work better).  This allows you to bypass all of the timebase problems and maximize the accuracy.  I don't think that it will change the buffer overflow problem though.

Also, what exact card do you have? I would like to look at the specs and possibly set up a similar setup to give this a try.
Neal M.
Applications Engineering       National Instruments        www.ni.com/support
0 Kudos
Message 6 of 6
(9,056 Views)