Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Buffered DAQmxBaseCreateCICountEdgesChan, error -200141

Here I go again. Thanks to anyone with the intestinal fortitude to look at my problem!

Using NI-DAQmx 1.4.0f2 Base on OS X 10.3.7, with a PCI-6014 DAQ board.

I'm trying to do a finite buffered edge count, but get error -200141, "Data was overwritten before it could be read by the system." from my call to DAQmxBaseReadCounterU32. I'm trying to use a very basic testing program modified from the shipping example, cntBufCont.

My test uses counter 1 to produce a continuous pulse train so that I have something to count, and it counts edges on counter 0. The pulse train specifies no output terminal; the default is pin 40. I specify "/Dev1/PFI9" as the source terminal. I have connected pin 40 to pin 3.

I have an LED connected to pin 40 and pin 3 as well, and I see it come on and go off. Naturally, I can't see it blinking.

The output from the program is:

DAQmxBase Error -200141 on line 8: Data was overwritten before it could be read by the system.
Samples read: 100
0: 0
1: 0
2: 0
3: 0
and more lines like this up to 100.

I can't see anything wrong with the program, but of course that doesn't mean there isn't something wrong! Should I be able to do this on OS X with a PCI-6014? The Read Me for DAQmx Base seems to indicate that I should.

Here's the code:

int main(void)
{
// Task parameters
int32 error = 0;
TaskHandle taskHandle = 0;
char errBuff[2048]={'\0'};
time_t startTime;

// Channel parameters
char chan[] = "Dev1/ctr0";

// Timing parameters
#define bufferSize 100
char clockSource[] = "/Dev1/PFI9";
uInt64 samplesPerChan = bufferSize;
float64 sampleRate = 10.0;

// Data read parameters
uInt32 data[bufferSize];
int32 samplesToRead = 100;
float64 timeout = 20.0;
int32 read;

// parameters for pulse generation
TaskHandle PulseTaskH = 0;
float64 freq = 1000.0;
float64 duty = 0.5;
float64 delay = 0.0;
char pulsechan[] = "Dev1/ctr1";

int i;

int line = 0;
DAQmxErrChk (DAQmxBaseCreateTask("",&PulseTaskH));
line = 1;
DAQmxErrChk (DAQmxBaseCreateCOPulseChanFreq(PulseTaskH,pulsechan,"",DAQmx_Val_Hz,DAQmx_Val_Low,delay,freq,duty));
line = 2;
DAQmxErrChk (DAQmxBaseCfgImplicitTiming(PulseTaskH,DAQmx_Val_ContSamps,1000));
line = 3;
DAQmxErrChk (DAQmxBaseStartTask(PulseTaskH));

line = 4;
DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));
line = 5;
DAQmxErrChk (DAQmxBaseCreateCICountEdgesChan(taskHandle,chan,"",DAQmx_Val_Rising,0,DAQmx_Val_CountUp));
line = 6;
DAQmxErrChk (DAQmxBaseCfgSampClkTiming(taskHandle,clockSource,sampleRate,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,samplesPerChan));
line = 7;
DAQmxErrChk (DAQmxBaseStartTask(taskHandle));
line = 8;
DAQmxErrChk (DAQmxBaseReadCounterU32(taskHandle,samplesToRead,timeout,data,samplesToRead,&read,NULL));

Error:
if( DAQmxFailed(error) )
DAQmxBaseGetExtendedErrorInfo(errBuff,2048);
if( taskHandle!=0 ) {
DAQmxBaseStopTask(taskHandle);
DAQmxBaseClearTask(taskHandle);
}
if (PulseTaskH)
{
DAQmxBaseStopTask(PulseTaskH);
DAQmxBaseClearTask(PulseTaskH);
}
if( DAQmxFailed(error) )
printf("DAQmxBase Error %d on line %d: %s\n", error, line, errBuff);

printf("Samples read: %d\n", read);
for (i = 0; i < read; i++)
{
printf("%d: %d\n", i, data[i]);
}
return 0;
}
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
0 Kudos
Message 1 of 3
(3,271 Views)
OK- I tried a buffered period measurement just to see if I could, and got the same -200141 error.

BUT

I lowered the pulse train frequency to 5 Hz and it was OK. 10 Hz was OK. 20 Hz is NOT OK.

From this really poor response, I infer that the buffered counter applications probably use interrupts to transfer readings from the board. That would further imply that the response to interrupts is pretty slow.

I suppose it could be using polling, and that it doesn't poll very often.
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
0 Kudos
Message 2 of 3
(3,271 Views)
Hi John-

I have a few suggestions for your app. First, in edge counting operations it isn't necessary to specify a sample clock. I would suggest simply creating the channel and then starting the task. You can then read the count register value at any time by calling the DAQmxBaseReadCounter function.

Also, in order to count edges your pulse train will need to be an input to the counter source rather than gate. For your device, the Ctr0 source is pin 37.

I am unsure why you are able to get readings by counting edges on the gate. I have been testing in LabVIEW and have seen good results by using the methods I have suggested here.

Please let us know if you have any luck with these suggestions.

Thanks-
Tom W
National Instruments
0 Kudos
Message 3 of 3
(3,217 Views)