Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Having trouble acquiring analog samples faster than 50khz

I have a NI-6115 DAQ and am using the included ANSI C example to continuously acquire a voltage signal.  I am reading samples from a single analog input.   The only modifications I have made to the included example are to bump up the sampling rate (tried 2MHz, but only could get 50kHz) and the number of samples to read at a time(have tried between 1-10X the sampling rate).  I need to sample at around 2MHz, but thus far I have only been able to acquire samples at 50kHz, with a 1M value buffer size).

 

Any ideas?

 

Thanks

J Klein

0 Kudos
Message 1 of 3
(2,739 Views)

Hey Klein,

It should work I tried running it on my computer and it works fine.  Try this code:

 

#include <stdio.h>

#include <NIDAQmx.h>

#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else

int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData);

int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData);

int main(void)

{

int32 error=0;

TaskHandle taskHandle=0;

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

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

// DAQmx Configure Code

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

DAQmxErrChk (DAQmxCreateTask("",&taskHandle));

DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,

"",2000000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,100000));

DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,100000,0,EveryNCallback,NULL));

DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));

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

// DAQmx Start Code

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

DAQmxErrChk (DAQmxStartTask(taskHandle));

printf(
"Acquiring samples continuously. Press Enter to interrupt\n");

getchar();

Error:

if( DAQmxFailed(error) )

DAQmxGetExtendedErrorInfo(errBuff,2048);

if( taskHandle!=0 ) {

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

// DAQmx Stop Code

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

DAQmxStopTask(taskHandle);

DAQmxClearTask(taskHandle);

}

if( DAQmxFailed(error) )

printf("DAQmx Error: %s\n",errBuff);printf(

"End of program, press Enter key to quit\n");

getchar();

return 0;

}

int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples,
void *callbackData)

{

int32 error=0;

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

int32 read=0;

float64 data[100000];

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

// DAQmx Read Code

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

DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,100000,10.0,DAQmx_Val_GroupByScanNumber,data,10000,&read,NULL));

if( read>0 ) {printf("Acquired %d samples. Total %d\r",read,totalRead+=read);

fflush(stdout);

}

Error:

if( DAQmxFailed(error) ) {

DAQmxGetExtendedErrorInfo(errBuff,2048);

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

// DAQmx Stop Code

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

DAQmxStopTask(taskHandle);

DAQmxClearTask(taskHandle);

printf(
"DAQmx Error: %s\n",errBuff);

}

return 0;

}

int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status,
void *callbackData)

{

int32 error=0;

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

// Check to see if an error stopped the task.

DAQmxErrChk (status);

Error:

if( DAQmxFailed(error) ) {

DAQmxGetExtendedErrorInfo(errBuff,2048);

DAQmxClearTask(taskHandle);

printf(
"DAQmx Error: %s\n",errBuff);

}

return 0;

}

 

 

Also what error message you are getting. May be you are not reading fast enough or the data buffer you set may be too small.

 

Good Luck

 

-lab

0 Kudos
Message 2 of 3
(2,712 Views)
Thanks for the reply!  I'll give this a shot and get back to you if things don't work out.
0 Kudos
Message 3 of 3
(2,692 Views)