Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Analog Input Measurement

Hallo,

I'm in trouble with an PCI 6221 Multi I/O Card. I want to measure four Inputs parallel, so I tried to add 4 Input (Channel = "dev1/ai0:3") to one task.
strcpy(chan,"Dev1/ai0:3");
DAQmxCreateTask ("",&taskHandleA1);
DAQmxCreateAICurrentChannel(taskHanldeA1,chan,"",DAQmx_val_cfg_Default,0.004,0.020,DAQmx_Val_Amps,DAQmx,Val_External,499.0);
DAQmxSetTimingAttribute(taksHandleA1,DAQmx_SampClk_Rate, 1000.0);

DAQmxStart,Task(taskHandleA1);

then later I go on reading:
double data [4000]; // enough space for 1000 samples per line

DAQmxReadAnalogF64(taksHandleA1,1000,10.0,DAQmx_Val,GroupByChannel, &data[0],4000, &splread);

I show the results on a graph-plot, but what I see: a square, about 250 Values with a negitv, 250values about 20mA's and so one.

I tried also just one Channel substitude
strcpy(chan,"Dev1/ai0");
and then the result seems ok.
But creating and starting a second task with "Dev1/ai1", causes an error - so how can I read all Analog Channels parallel ?

thanks

franky







0 Kudos
Message 1 of 9
(4,745 Views)
Hello franky,
I've got a couple suggestions.  First, you might want to use a different function to set up your timing.  I would suggest using DAQmxCfgSampClkTiming().  I don't think that will affect the problem you posted about, this is just a suggestion.  This follows the examples, makes the code a little nicer, explicitly sets the timing to be finite or continuous and still accomplishes what you intend to do with your current function call (setting the sample rate).
 
As to your problem, you might just want to check how you are displaying your data array.  I ran your code (only difference was I created a voltage channel as opposed to a current channel) and got 4000 samples.  The first 1000 were channel 0, samples 1000 - 1999 were channel 1, and so on. 
 
You have found that you can not have two separate analog input tasks running at the same time, which is expected behavior.  You are adding the channels correctly "Dev1/ai0:3" and your programming looks ok.  So again, I would take a look at your array, and make sure it looks ok. 
 
-Alan A.
0 Kudos
Message 2 of 9
(4,712 Views)
Hallo,
 
using the DAQmxCfgSampClkTiming -Function causes a runtime error: (I took again chan = "Dev1/ai0:3")
 
 NON-FATAL RUN-TIME ERROR:   "mess.c", line 96, col 23, thread id 0x000006A0:   Function DAQmxReadAnalogF64: (return value == -89120 [0xfffea3e0]). Source terminal to be routed could not be found on the device.  Make sure the terminal name is valid for the specified device. Refer to Measurement & Automation Explorer for valid terminal names. Property: DAQmx_SampClk_Src Property: DAQmx_SampClk_ActiveEdge Source Device: Dev1 Source Terminal: Dev1/ai0:3 Channel Name: Dev1/ai0  Task Name: _unnamedTask<0>  Status Code: -89120
 
??
 
 
0 Kudos
Message 3 of 9
(4,707 Views)
Notice in the NI-DAQmx C Reference Help (Start>>All Programs>>National Instruments>>NI-DAQ>>NI-DAQmx C Reference Help) that the source input is the source terminal of the Sample Clock.  If you are not using an external clock (which I don't think you are), you should use NULL or "OnboardClock" for the source input to the DAQmxCfgSampClkTiming function.
 
Example, using the internal clock:
 
DAQmxCfgSampClkTiming(taskHandle,"",sampleRate,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,sampsPerChan);
 
-Alan A.
 
0 Kudos
Message 4 of 9
(4,704 Views)

Hi. I'm using PCI- 6221.

 

I need to measure simultaneously 6 AI (3x voltage, 3x current) and show them in one plot. I have made application in LabView for 1 voltage measure and it's ok. Now i'm trying to do it with at least 2 measures and doesn't work.

I will appreciate with any help.

 

in attachment my example with 1 channel measurement and 'try' with 2 channels.

Download All
0 Kudos
Message 5 of 9
(3,672 Views)

Does PCI-6221 can do simultaneous measures of Analog Inputs? I researched the forum and documentations and many devices cannot do that, unfortunately my card neither... or am i wrong?

 

how should look the program to synchronize many measures? and further... how to present them on one graph?

 

pleeease! help me.

0 Kudos
Message 6 of 9
(3,635 Views)

I can't open either of your VIs. Reattach please.

 

In any case, your task is pretty basic. You want to have a single task with mulitple channels. The DAQ Assistant can do this or just use the low level DAQmx functions. You would have a DAQmx Create Channel for the 3 voltage channels and one for the current channels. A single DAQmx Read output would be wired to a graph to show all channels. Take a look at some of the shipping examples. You just need to insert the extra Create Channel.

0 Kudos
Message 7 of 9
(3,624 Views)

Sorry for broken attachment. hope this one is ok. 

 

Thanks for reply. I don't want to use Daq Express cause i need to change freq during the measurement.

 

0 Kudos
Message 8 of 9
(3,620 Views)

You have two separate tasks and that is not allowed. Simply add the second Create Channel (current) that you have into the first task i.e. right after the one you have labeled for voltage. You would have a single DAQmx Read and you obviously need to change the type to NChannels.

 

The DAQ Assistant is just as capable of changing the number of samples as your code. It is not frequency that you are changing. Frequency would be related to sample rate.

0 Kudos
Message 9 of 9
(3,613 Views)