Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Weird Analog Voltage Input with USB-6211

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.

 

11.png

 

 

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.

 

2.JPG

 

Have anyone ever met this situation?

Or somebody could give me some tips?

 

Any advices are appreciated and many thanks in advance!

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

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"

0 Kudos
Message 2 of 2
(3,880 Views)