Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems reading from a task with 2 or more AI channels in C++ Builder..

I´m developing an aplication to be used as a control system.
At first, I was using a task with a single AI voltage channel to read at a certain frequency. I need the aplication to work as close to real time as possible. So I was using my card´s internal clock and using the ReadAnalogScalar function to read everytime a value was available. It was working fine as described below:
- Create Task
- Create AI Voltage Channel
- Configure Clock (internal)
- Start Task
- Read Analog Scalar (inside while loop)
- Stop Task
- Clear Task

Then I needed to read from another Ai Voltage Channel... So I added another channel to the task and changed the read function once the ReadAnalogScalar only works for single channel tasks. I need the data in real time, so I used the read function to acquire only one sample from each channel at a time. So the program looks like this now:
- Create Task
- Create AI Voltage Channel
- Create AI Voltage Channel
- Configure Clock (internal)
- Start Task
- Read Analog (inside while loop)
- Stop Task
- Clear Task

Now, the fisrt time the read function is called, it works fine, but from the second time on it gives me an error message saying that that the task is invalid or doesn´t exist... My guess is that with the read analog scalar function it waited for a value to become available before reading it, so the program worked fine at the exact rate. But now I guess this read function is being called before the task is available for reading...

If anyone knows what is the problem in this program, or another way of reading multiple channels at a fixed rate I´ll be very gratefull.

Thanks,
Marcelo Vieira
0 Kudos
Message 1 of 9
(4,090 Views)
Can you create two tasks, with each input channel in a separate task?

If they have to be synchronized, you can have the second task use the sample clock from the first.
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
0 Kudos
Message 2 of 9
(4,082 Views)
It sounds like the task is being cleared for some reason after the first read call is executed. Are you getting any errors from any of the functions you are calling (esp. the read)? If you want to post the code you are running, I'd be happy to look at it to see if I can find something wrong with it.

Joe
0 Kudos
Message 3 of 9
(4,061 Views)
Hello everyone..

thanks for the help, but I´ve solved the problem.
The code was right, the only problem was that the array I was using in the read function to get the acquired data was too small. Since I was reading from 2 channels, 1 value from each channel, I was using an array with a size 2. But that, for some reason, was giving me the weird error message, saying that the task was invalid or didn´t exist...
So I increased the array size and it´s working fine now.

Now I´m having some problems while adding a AI Current Channel in the same task as the Voltage Channels... Does anyone know if I can do that or do I have to use a different task??

Thanks again,

Marcelo
0 Kudos
Message 4 of 9
(4,051 Views)
You should be able to add a current channel to the same task, as long as the channel is on the same device as the other two channels. If it's on a different device, you'll have to use a different task. What error are you getting?

Joe
0 Kudos
Message 5 of 9
(4,046 Views)
The channels are all on the same device (I only have one device: PCI-6014).
I'm getting the following error: "Requested value is not a supported value for this property."

The error message comes from the following Create Channel code:
iError = DAQmxCreateAICurrentChan(thTaskDAQ, "Dev1/ai5", "", DAQmx_Val_Diff,
-10.0, 10.0, DAQmx_Val_Amps, DAQmx_Val_Internal,
0, NULL);

Thanks for the help!

Marcelo
0 Kudos
Message 6 of 9
(4,035 Views)
I think the problem is that you're specifying an internal shunt resistor, but that's not valid for a PCI-6014. You'll need to use an external shunt resistor and specify the value in the extShuntResistorVal parameter.
0 Kudos
Message 7 of 9
(4,031 Views)
Right after I posted the message, I tryed changing that value to "DAQmx_Val_External" and it created the channel with no errors. But now I'm not really sure of how to place that shunt resistor on my board (I use a SCB-68) and which value should I use.

I'm guessing that it should be a low resistance value connected between the Differential channels (for example ai5-ai12). Is that right? What if I want to do a NRSE or RSE?

Thanks again!

Marcelo
0 Kudos
Message 8 of 9
(4,025 Views)
The shunt resistor needs to be placed in series with the current loop you are trying to measure. A typical resistance value is 249 ohms, when 4-20mA is the expected current. Then you would hook up the PCI-6014 channel to measure the voltage drop across the resistor (which would be about 1-5V for a 4-20mA current). Whether you want Differential, RSE or NRSE depends on whether it is OK for one side of the shunt resistor to be grounded. (Don't do RSE unless it's OK to ground the resistor). I can't really answer that question without seeing your circuit, but most likely differential is what you want.

Hope this helps,
Joe
0 Kudos
Message 9 of 9
(4,018 Views)