06-01-2018 03:35 AM
Hi,
My aim is to let three output channel generate different output signals with different sampling rate simultaneously.
Here are my key code to do it:
// data contains 3000 elements, 1000 elements for each channel
for (int i=0; i<1000; i++)
data[i] = 10.0*i/1000.0-4;
for (int i = 1000; i < 2000; i++)
data[i] = 0.0;
for (int i = 2000; i<2800; i++)
data[i] = 3.0;
for (int i = 2800; i<3000; i++)
data[i] = 0.0;
// let scanner move //
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk(DAQmxCreateTask("", &taskHandle));
DAQmxErrChk(DAQmxCreateAOVoltageChan(taskHandle, "cDAQ1Mod1/ao0:cDAQ1Mod1/ao2", "", -10.0000, 10.0000, DAQmx_Val_Volts, NULL));
// three channels have different sampling rate: 100, 20000, 20000. each channel 1000 samples
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle, "", 100.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 1000));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle, "", 20000.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 1000));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle, "", 20000.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 1000));
// DAQmx Write Code
/*********************************************/
DAQmxErrChk(DAQmxWriteAnalogF64(taskHandle, 1000, 0, 10.0, DAQmx_Val_GroupByChannel, data, &written, NULL));
// DAQmx Start Code
/*********************************************/
DAQmxErrChk(DAQmxStartTask(taskHandle));
/*********************************************/
// DAQmx Wait Code
/*********************************************/
DAQmxErrChk(DAQmxWaitUntilTaskDone(taskHandle, 10.0));
DAQError:
if (DAQmxFailed(DAQ_error))
DAQmxGetExtendedErrorInfo(errBuff, 2048);
if (taskHandle != 0) {
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
It seems that my idea is wrong. Is there anyone can give me some suggestion?
Thank you in advance.
Regards
Xiaoran
06-04-2018 01:21 AM
xiaoran94, unfortunately you cannnot set multiple-channel with difference sampling rate.
First, you can create only one task on CompactDAQ. See below.
Number of Concurrent Tasks on a CompactDAQ Chassis Gen II
This implicate that timing engine for AO is only one, so the rate should be unique at one module.
I read your code, you are writing "DAQmxCfgSampClkTiming" three times.
By this operation, only 3rd command is adapted. I guess only "20000.0Hz" is.
You haven't specified corresponding channel...
My idea is using "decimation"
Sample Channels at Different Rates with Multifunction DAQ Device