12-17-2013 12:37 PM - edited 12-17-2013 12:38 PM
Hello, I'm using a USB-6211 to continuously monitor an analog voltage input whose waveform is square.
I followed ContAcq-IntClk.c in the examples and print these values in the screen, but the output are werid, they are much larger than the voltage I send.
For example, the amplitude I set is 0.5V, the read out voltages could be more than 8V.
You can see the result in the first picture.
Here is the 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/ai6","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",500.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,50));
DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,50,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[50];
int i = 0;
/*********************************************/ // DAQmx Read Code /*********************************************/
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,50,10.0,DAQmx_Val_GroupByScanNumber,data,50,&read,NULL));
for ( i=0; i<50; i++)
{
printf( "%f\n", data[i] );
}
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;
}
/*********************************/
I thought there might be some mistake, so I used the tool from NI Measurement & Automation Explorer to sample the same analog input channel continuously, now the result is right. You can see the waveform in picture 2.
Have anyone ever met this situation?
Or somebody could give me some tips?
Any advices are appreciated and many thanks in advance!
12-20-2013 02:12 AM - edited 12-20-2013 02:13 AM
Solution:
DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai6","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
modify "DAQmx_Val_Cfg_Default" to "DAQmx_Val_RSE"