Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple channel data acquisition using Lab windows and NiDAQmx

 

I am a beginner with Lab windows. I have NIDAQmx   PCI-6220 card.  I want to acquire analog signals from 5 different channels at the same time and I want to analyze it (FFT).

 

Do you guys have any examples for multiple channel data acquisition?

 

Thanks

 

Regards

Dinesh

0 Kudos
Message 1 of 9
(5,125 Views)
Hello Dinesh,
To acquire data from multiple channels using NI-DAQmx, all you have to do is change the physical channel control.  I would suggest opening a shipping example, like "ContAcq-IntClk".  You can get to that example by going to Help>>Find Examples.  Navigate to Hardware Input and Output>>DAQmx>>Analog Measurements>>Voltage.  To acquire data from channels 0 through 3 from device 1, you would use the physical channel "Dev1/ai0:3".  Additionally, you can use the "," to add non-adjacent channels.  To acquire from channels 5 and 7, you would use: "Dev1/ai5, Dev1/ai7". 
Hope this info helps!
-Alan A.
Message 2 of 9
(5,113 Views)
Hello Alan,
Your help was very helpful for me, but i have little bit diferent problem.
I want to control more channels independently- it means i want to create task, create physical channel, ... for 1st channel
and then to do the same for 2nd channel. but i get an error:
The specified resource is reserved. The operation could not be completed as specified. Task Name: _unnamedTask<1>  Status Code: -50103
 
Here is a sample of my code:
1st is your idea- works fine
2nd is the way how i would like to do it, but 2nd calling DAQmxWriteAnalogF64, gives me error what i mentioned above.
 
thanks, Michal
 
1.
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,"Dev4/ao0:1","",-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",freq,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
for(;i<1000;i++)
  data[i] = 9.95*sin((double)i*2.0*PI/1000.0);
for(i=1000;i<2000;i++)
  data[i] = 4*sin((double)i*2.0*PI/1000.0);  

DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,1000,0,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
DAQmxIsTaskDone (taskHandle, &isTaskDone)  ;
if(isTaskDone==1)
  DAQmxStartTask(taskHandle);     
-----------------------------------------------
2.
 
DAQmxErrChk (DAQmxCreateTask("",&taskHandle1));
DAQmxErrChk (DAQmxCreateTask("",&taskHandle2));
DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle1,"Dev4/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle2,"Dev4/ao1","",-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle1,"",freq,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle2,"",freq,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
for(;i<1000;i++)
  data1[i] = 9.95*sin((double)i*2.0*PI/1000.0);
for(;i<1000;i++)
  data2[i] = 4*sin((double)i*2.0*PI/1000.0);  

DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle1,1000,0,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle2,1000,0,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));

DAQmxIsTaskDone (taskHandle1, &isTaskDone)  ;
if(isTaskDone==1)
  DAQmxStartTask(taskHandle1);     
DAQmxIsTaskDone (taskHandle2, &isTaskDone)  ;
if(isTaskDone==1)
  DAQmxStartTask(taskHandle2);     
0 Kudos
Message 3 of 9
(4,988 Views)
Hi Michal,
What you are seeing is expected behavior.  Your device (Maybe E or M series?) has only one set of analog output timing circuitry.  So, when you start the first task, which is what happens when you call the write function, the device reserves the ao timing circuitry for that task.  Then, when you start the second task, it tries to reserve the same hardware, which it is not allowed to do.  So, you are not going to be able to use your 2nd approach.
It looks like what you are trying to do is output two different sin waves on two different channels.  Another way you might consider doing this would be simply to manipulate your data and update rate, so that you can include both channels in the same task.
 
-Alan A.
 
If you have any more questions, you might want to mention what device and version of NI-DAQmx you are using.
Message 4 of 9
(4,982 Views)
Hi Alan,
thanks for your advice.
The problem what i'm solving now is with PXI6733 and later on with PXI-6723.
 
It seems to be that you're right about timing circuitry, but could i use one set of analog output timing circuitry for both channels? How? 🙂
 
I know the best way would be to include both channels into the one task, but my customer requires to generate one signal e.g. sine wave and depends on result to generate some other signal on the other channel
 
I'm using NI-DAQmx 8.0 i'm bit afraid to install latest version because of compatibility. I use NI-DAQmx also for PXI-6509
 
Thanks Michal
0 Kudos
Message 5 of 9
(4,967 Views)
and another question,
 
do you know if is it possible to generate 2 waves by 2 different channels if i would use external synchronisation e.g over Ctr0Out, Ctr1Out?
i'm talking about PXI-6733, 6723
0 Kudos
Message 6 of 9
(4,955 Views)

So, what I meant by using both channels with the same timing ciruitry would be something like the image below.  Using the same update rate, by having a different number of data points per cycle, you can output different frequency signals.  Also, supplying an external clock still uses the same ao timing circuitry, so that won't help. 

-Alan A.

Message Edited by Alan [DE] on 02-21-2007 10:46 AM

Message Edited by Alan [DE] on 02-21-2007 10:46 AM

0 Kudos
Message 7 of 9
(4,946 Views)
Hello Alan,
theoretically you are right, but...
2nd parameter of DAQmxWriteAnalogF64 says :
"numSampsPerChan  int32 The number of samples, per channel, to write. You must pass in a value of 0 or more in order for the sample to write. If
                                              you pass a negative number, this function returns an error. "
I think it means i have to use for every channel the same number of data points.
Anyhow i tried to modified my program to
--------------------
int32       error=0;
 TaskHandle  taskHandle=0;
 float64     data[1500];
 char        errBuff[2048]={'\0'};
 int         i=0;
 
 for(;i<1000;i++)
  data[i] = 9.95*sin((double)i*2.0*PI/1000.0);
 
 for(i=1000;i<1500;i++)
  data[i] = 4.95*sin((double)i*2.0*PI/1000.0); 
 
 DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
 DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,"Dev4/ao0:1","",-10.0,10.0,DAQmx_Val_Volts,NULL));
 DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1));
 
 DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,500,0,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
 
 DAQmxErrChk (DAQmxStartTask(taskHandle));
----------------------
and i got an error:
" FATAL RUN-TIME ERROR:   "ContGen-ExtClk.c", line 78, col 4, thread id 0x00000A3C:   Array argument too small (12000 bytes).  Argument must contain at least 16000 bytes (2000 elements)."
 
Any idea?
Peace of code, would be helpfull 🙂
 
But anyhow, thanks for your patient with me.
Michal
0 Kudos
Message 8 of 9
(4,926 Views)

So, you'll have to get creative with your array and probably fill it in with dummy data (or zeros) for the second channel, because you are right, it expects the same number of samples for each channel.  So, you might have to use an array twice the size that you actually want.  I'm not exactly sure about that error, does it go away if you increase the size of your array, as it suggests?  Your code looks fine, if you want example code, check out my first post in this thread.

-Alan A.

Message 9 of 9
(4,899 Views)