Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Analog Output Multiple Channel Write Configuration

Hi,
I'd like to write into multiple channels Analog Outputs and my doubts are around  the configuration of the timing and buffer.
Let's put an example:
double SamplesPerChannel = 1000.0;
double ao1_freq = 100;
double a01_amp = 2.0;
double ao2_freq = 20;
double a02_amp = 1.0;
double dataToWrite[2000]; // buffer os size =numChannels *SamplesPerChannel
int        numChannels = 2;
int        i=0;
double sampleClockRate = a01_freq*SamplesPerChannel ; //I've used the maximum frequency
 
for (i=0; i<SamplesPerChannel ;i++)
{
    data[i] = amplitude*sin((double)i*2.0*PI/SamplesPerChannel );
}
for (i=SamplesPerChannel ; i<SamplesPerChannel *numChannels ;i++)
{
    data[i] = amplitude*sin((double)i*2.0*PI/SamplesPerChannel );
}
 
 DAQmxCreateTask("",&taskHandle);
 DAQmxCreateAOVoltageChan(taskHandle,"cDAQ1Mod4/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL);
 DAQmxCreateAOVoltageChan(taskHandle,"cDAQ1Mod4/ao1","",-10.0,10.0,DAQmx_Val_Volts,NULL);
 DAQmxCfgSampClkTiming(taskHandle,"",sampleClockRate ,DAQmx_Val_Rising,DAQmx_Val_ContSamps,XXX);
 DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL);
 DAQmxWriteAnalogF64(taskHandle,SamplesPerChannel ,0,10.0,DAQmx_Val_GroupByChannel,dataToWrite,NULL,NULL);
 DAQmxStartTask(taskHandle);
 
..............
 
1.- ¿Is correct the way I've calculated the sampleClockRate ? ¿ Or should it be: sampleClockRate=a01_freq*SamplesPerChannel *numChannels?
2.- XXX is the buffer size, but again I'm not sure if it should be 2000(numChannels *SamplesPerChannel ) or 1000 (SamplesPerChannel ).
 
As you can see my problem is to understand how affects having more than one channel in the timing configuration.
 
Thanks in advance
 
 
 
0 Kudos
Message 1 of 2
(3,011 Views)

Hi,

 

The sample clock rate specified is for ALL the channels that means, if you put a clock rate of 20.000 and u have 5 channels, all channels will be scanned at 20.000 samples per second (20.000 samples/s at channel .0, 20.000 samples / s at channel 1, etc...)

 

The same is for the buffer size the buffer size specified is per channel. So a 5000 for example would mean 5000 samples buffer for each channel (5000 for channel 0, 5000 for channel 1, etc...)

 

Hope that helps,

 

Regards,

Jaime Cabrera

NI Applications Engineering Spain
0 Kudos
Message 2 of 2
(2,975 Views)