Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Attempted writing analog data that is too large or too small -->USB6009

 Hi,
I'm using the attached example in VC++ to write voltages by a USB-6009 Using the function DAQmxWriteAnalogF64 . I get an error -200561 ("Attempted writing analog data that is too large or too small") occurs when I'm writing voltages with the analog out range set to 0 .. 5 Volt.
 
Parikshit

************************* code***************************************

#include <stdio.h>
#include <math.h>
#include <NIDAQmx.h>
#if defined(WIN32) || defined(_WIN32)
#include <windows.h>
#endif
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
#define PI 3.1415926535

int main(void)
{
 int         error=0;
 TaskHandle  taskHandle=0;
 float64     data[1000];
 char        errBuff[2048]={'\0'};
 uInt32      i=0;
 for(;i<1000;i++)
  data[i] = 9.95*sin((double)i*2.0*PI/1000.0);
 i = 0;
 /*********************************************/
 // DAQmx Configure Code
 /*********************************************/
 DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
 DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,"Dev1/ao0","",0.0,5.0,DAQmx_Val_Volts,NULL));
 /*********************************************/
 // DAQmx Start Code
 /*********************************************/
 DAQmxErrChk (DAQmxStartTask(taskHandle));
 printf("Generating samples continuously. Press Ctrl+C to interrupt\n");
 while( 1 ) {
  #if defined(WIN32) || defined(_WIN32)
   Sleep(1);
  #else
   #error - This example requires a platform specific sleep call.
   /*********************************************/
   // This example requires a platform specific sleep call.
   // For example:
   //
   // #include <windows.h>
   // Sleep(1);  // For Windows platform
   //
   // #include <unistd.h>
   // usleep(1000); // For Linux platform
   /*********************************************/
  #endif
  /*********************************************/
  // DAQmx Write Code
  /*********************************************/
  DAQmxErrChk (DAQmxWriteAnalogScalarF64(taskHandle,1,10.0,data[i],NULL));
  if( ++i>=1000 )
   i = 0;
 }
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;
}
0 Kudos
Message 1 of 6
(5,342 Views)
Hi Parikshit,

According to the equation in your code, 9.95*sin((double)i*2.0*PI/1000.0), your sine wave will have an amplitude of 9.95 V and thus will output at a range of +/-9.95 V.  This is outside your analog out range of 0 to 5 Volts.  Try the range -10 to 10 volts and see if you get the same error.

I hope this helps!

- Erik
0 Kudos
Message 2 of 6
(5,297 Views)
I tried changing the  values of data from 9.95 and tested between -10 to +10 but the error remained which u can see in the attached image
 data[i] = 10.0*sin((double)i*2.0*PI/1000.0)
0 Kudos
Message 3 of 6
(5,286 Views)

I have managed to remove the error by slightly modifying the code so that reading's dont go into the negative zone but even though the program works fine the output is not generated on the voltmeter.I know the problem is in the program bcoz the program in VB works fine.

here is my modified  code please help.

----------------------------------------------------------------------------------------------------

#include <stdio.h>
#include <math.h>
#include <NIDAQmx.h>
#if defined(WIN32) || defined(_WIN32)
#include <windows.h>
#endif

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

#define PI 3.1415926535


int main(void)
{
 int         error=0;
 TaskHandle  taskHandle=0;
 float64     data[1000];
 char        errBuff[2048]={'\0'};
 uInt32      i=0;


 i = 0;

 /*********************************************/
 // DAQmx Configure Code
 /*********************************************/
 DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
 DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,"Dev1/ao0","",0.000000,5.000000,DAQmx_Val_Volts,NULL));

 /*********************************************/
 // DAQmx Start Code
 /*********************************************/
 DAQmxErrChk (DAQmxStartTask(taskHandle));

 printf("Generating samples continuously. Press Ctrl+C to interrupt\n");
 while( 1 ) {
  #if defined(WIN32) || defined(_WIN32)
   Sleep(1);
  #else
   #error - This example requires a platform specific sleep call.
   /*********************************************/
   // This example requires a platform specific sleep call.
   // For example:
   //
   // #include <windows.h>
   // Sleep(1);  // For Windows platform
   //
   // #include <unistd.h>
   // usleep(1000); // For Linux platform
   /*********************************************/
  #endif
 for(;i<1000;i++)
 {
  data[i] = 5.0*sin((double)i*2.0*PI/1000.0);
       if(data[i]<0)
     data[i]*=-1;
   printf("\ndata[%d]=%0.2f",i,data[i]);
   DAQmxErrChk (DAQmxWriteAnalogScalarF64(taskHandle,1,-1,data[i],NULL));
   if(i%1==0)
    getch();
 }
  /*********************************************/
  // DAQmx Write Code
  /*********************************************/
  //DAQmxErrChk (DAQmxWriteAnalogScalarF64(taskHandle,1,-1,data[i],NULL));
  //if( ++i>=1000 )
  // i = 0;
 }

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;
}

 

0 Kudos
Message 4 of 6
(5,278 Views)
Thank u guys now it is working fineSmiley Happy
0 Kudos
Message 5 of 6
(5,275 Views)
Great!  Let us know if you need any additional help.

Good luck with your application,
- Erik
0 Kudos
Message 6 of 6
(5,262 Views)