07-12-2012 11:12 PM
Hi,
I want to generate two different analog outputs on a NI USB-6211.
I'm using NI-DAQmx Base for Mac OS X v.3.4.0 in a Xcode 3.1.3 environment (in C) on a MacOSX 10.5 (intel). -- No Labview.
I can get two identical ouput when creating a single task for "Dev1/ao0:1" as suggested in many threads on the subject, but I did not find anything about two different ouput.
In the example below, I want to be able to adjust the relative phase between two sine wave. Just changing the phase in the equation won't do it.
Any suggestions on what I'm doing wrong?
Thank you,
RT1
//////////////////////////////////////////////////////////////////////////////////
static int gRunning = 0;
// Task parameters
int32 error = 0;
TaskHandle taskHandle = 0;
//int32 i = 0;
char errBuff[2048]={'\0'};
time_t startTime;
bool32 done=0;
// Channel parameters
char chan[] = "Dev1/ao0:1";
float64 min = -10.0;
float64 max = 10.0;
// Timing parameters
uInt64 samplesPerChan = bufferSize;
float64 sampleRate = 5120.0*Freq/10.0; // FREQUENCY
// Data write parameters
float64 dataSine[2*bufferSize];
int32 pointsWritten;
float64 timeout = 10.0;
///////////////////
staticint i;
static double phase1=0;
static double phase2=0;
for(i=0;i<bufferSize;i++)
{
dataSine[2*i] = Amp*sin(phase1 + (double)i*2.0*PI/((double)bufferSize));
dataSine[2*i+1] = Amp*sin(phase2 + (double)i*2.0*PI/((double)bufferSize));
}
////////////////
DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxBaseCreateAOVoltageChan(taskHandle,chan,"",min,max,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxBaseCfgSampClkTiming(taskHandle,"",sampleRate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,samplesPerChan));
DAQmxErrChk (DAQmxBaseWriteAnalogF64(taskHandle,samplesPerChan,0,timeout,DAQmx_Val_GroupByChannel,dataSine,&pointsWritten,NULL));
DAQmxErrChk (DAQmxBaseStartTask(taskHandle));
gRunning = 1;
// The loop will quit after 10 seconds
startTime = time(NULL);
while( gRunning && !done && time(NULL)<startTime+DUration ) {
DAQmxErrChk (DAQmxBaseIsTaskDone(taskHandle,&done));
if( !done )
usleep(100);
}
Error:
if( DAQmxFailed(error) )
DAQmxBaseGetExtendedErrorInfo(errBuff,2048);
if( taskHandle!=0 ) {
DAQmxBaseStopTask(taskHandle);
DAQmxBaseClearTask(taskHandle);
}
if( DAQmxFailed(error) )
printf ("DAQmxBase Error %d: %s\n", error, errBuff);
}
//////////////////////////////////////////////////////////////////////////////////
07-16-2012 01:24 PM
Hi RT1,
I believe that what you are looking for is the write function that is called as follows:
Write_ContGenPerWfmIntClk(taskHandle,&data[0],bufferSize)
You will need to create a data buffer that has both waveforms (with different phase properties) occurring successively in the buffer; not with their points alternating in the buffer. For example, the first samplesPerChan points in the buffer (0...samplesPerChan - 1) will contain the first sine wave and the subsequent samplesPerChan samples (samplesPerChan...2*samplesPerChan - 1) will contain the second sine wave.
Please refer to the last post in this forum thread for more information. I have also included the URL to an example where multiple waveforms with several different properties (frequency, amplitude, phase..) are outputted in multiple channels. The example is more complicated than what you would like to accomplish, but the relevant parts of the code to your task are performed as I described above.
http://zone.ni.com/devzone/cda/epd/p/id/4749
Regards,