09-02-2011 02:43 PM
Hi Brain,
I tried executing the example program for analog continuous wave generation. I was sucessful in generation of the wave, but when I stop the execution my DAQ board still outputs a DC voltage.
But I want the output to go to Zero once I'm done withthe execution. Is there something else that I need to add to the code to acheive this.Please help me.
Thanks,
Diya
09-02-2011 02:46 PM - edited 09-02-2011 02:46 PM
Diya,
With Analog Out the card will always output the last voltage it was given. If you want to have it go to zero after you are done, you can write a 0 to your line at the end of the program.
I hope that helps.
Brian
09-02-2011 02:52 PM
Brain,
I tried doing that but I'm seeing an error message which says "Specified resource is reserved".
I want my wave to be continous and just go to zero when I hit enter to end program.
Can you help me out with the syntax of the program? i.e. where should i give the statement data=0.0; in my code?
Thanks,
Diya
09-06-2011 02:49 PM
Diya,
In order to get it to output a zero, I changed the error section to write a zero and then output it before it stops the program. Here is how I modified it:
Error:
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandle!=0 ){
/*********************************************/
//DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxWriteAnalogF64(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,0,NULL,NULL);
DAQmxStartTask(taskHandle);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;
And that would bring my output back to zero.
I hope this helps.
Brian P.
09-06-2011 03:34 PM
09-09-2011 02:50 PM
Hi Brain,
I've the same problem back again.. It just worked for once and it is not working again.. 😞
This is my code :
#include <stdio.h>#include <math.h>#include "NIDAQmx.h"
#pragma hdrstop
//---------------------------------------------------------------------------
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
#define PI3.1415926535
int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData);
#pragma argsusedint main(int argc, char* argv[]){
int error=0;
TaskHandle taskHandle=0;
float64 data[100001];
char errBuff[2048]={'\0'};
int i=0;
int freq;
printf("Please enter the Desired Frequency\n");
scanf("%d", &freq);
for(;i<100001;i++)
data[i] = 5*sin((double)i*2.0*PI* freq/240000.0);
/*********************************************/// DAQmx Configure Code/*********************************************/DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,"Dev1/ao1","",-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",240000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,50000));
DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));
/*********************************************/// DAQmx Write Code/*********************************************/DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,50000,0,-1.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
/*********************************************/// DAQmx Start Code/*********************************************/DAQmxErrChk (DAQmxStartTask(taskHandle));
printf("Generating voltage continuously. Press Enter to interrupt\n");
getchar();
getchar();
Error:if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandle!=0 ) {
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxWriteAnalogF64(taskHandle,240000,0,10.0,DAQmx_Val_GroupByChannel,0,NULL,NULL);
DAQmxStartTask(taskHandle);
DAQmxStopTask(taskHandle);
DAQmxClearTask(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 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;
}
//----------------------------------------------------------------------------------
09-09-2011 03:10 PM
Hi Brain,
I've attached the C file.
Thanks,
Diya
09-12-2011 11:02 AM
Diya,
I am sorry that it is not working for you again. When you say not working, what exactly do you mean, are you getting an error? What has changed from when it was working?
I looked at your code and everything seems to be in order so I am thinking that we do that self test again, where we output the data and then read the data back in using a test panel.
Please let me know what errors you are getting if any.
Regards,
Brian P.
09-12-2011 02:30 PM
Hi Brain,
I tried executing the code even using the test panel method you suggested earlier. Still didn't work. 😞
Previously when I posted that it worked and the reason behind it might be, when I hit enter to abort the generation of the sine wave, maybe I got lucky and it stopped exactly at the point zero and it seemed to be working But after I executed the code couple of times it never worked again, i.e.. It never ended at zero. It is giving me some DC offset values but not going to Zero.
Regards,
Diya
09-13-2011 01:02 PM
Hi Diya,
I ran your code and it executed properly as it zeroed after pressing Enter to interrupt. Does the waveform (prior to zero) look correct in the AI Test Panel? Could you take a screenshot of the test panel after you press Enter?
Kind Regards,