Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DACmx running 2 tasks

Hello,
I have a question on how to use DACmx running 2 tasks. - I am building a loop in which:
1. 10ms pulses are written to four DAC channels (NI 9263) (and sent to a certain external object);
2. 15ms after the pulses, I read samples from multichannel ADC (NI 9205);
3. Acquired data are processed and amplitudes of next pulses are calculated.
Again steps 1 - 3.
Properties of read and write tasks are configured out of the loop but pulse amplitudes must be refreshed every ~25ms.
Expected duration of one cycle is close to 25ms. The problem is that I cannot reach cycle time shorter than ~80ms.
I use Visual Basic.NET.
I would appreciate any advice on how to use effectively DACmx functions to solve this problem.
 
Oleg.
0 Kudos
Message 1 of 12
(4,686 Views)

Hi Oleg,

Because CompactDAQ is on USB, you will have system dependent behavior when trying to run control loops.  That said, I think you should probably be able to achieve better than 80ms loop  rates.

What kind of computer are your running on?  Is it relatively fast with a USB 2.0 connection?

There may also be some inefficiencies in your code.  Perhaps you could post it and somone may see some places for improvements.

Thanks,
Sal

0 Kudos
Message 2 of 12
(4,663 Views)
Hi Sal,
 
thank you for the response. I have pretty fast Pentium 4 2GHz computer with USB 2.0.
 
After some gymnastics, I managed to reduce extra time in a loop (between pulses) to 20ms.
 
Attached is the fragment of the code.
Is it optimal to reduce additional time delay between pulses?
 
My second question. - We plan to use up to 4 AI modules. At present the procedure works with 1 module.
Can I call the same Callback function to read data from 4 modules simply by passing module index or I have to create 4 separate Callback functions for each reader?
 
Thank you in advance,
 
Oleg.
 
 
0 Kudos
Message 3 of 12
(4,652 Views)

Hi Oleg,

I'm glad to hear that you were able to reduce your loop time.  I'm not sure if this applies, but I wanted to let you know that if you are not changing any of your task's configurations between loop iterations, then you do not need to call any of the task configuration functions in the loop.  You should only have to call the start and stop task functions in the loop.  Calling the configure sample clock function will increase your loop time.

Your NI-CompactDAQ chassis allows for only one analog input task to be running at a time.  So if you have one chassis with four modules in it, you will have only one AI task and a reader that will get the data acquired by all of the modules.  You can have multiple modules in the task (if all of the modules aren't the same) by calling AIChannels.CreateVoltageChannel multiple times (once for each module). 

If you are going to have many of the same module with the same input ranges in the same task, you can call AIChannels.CreateVoltageChannel only once and list all of the modules in it like this:

meas_channels_task(0).AIChannels.CreateVoltageChannel("cDAQ1Mod8/ai0:15, cDAQ1Mod7/ai0:15, cDAQ1Mod6/ai0:15, cDAQ1Mod5/ai0:15", "", AITerminalConfiguration.Rse, -10.0, 10.0, AIVoltageUnits.Volts)

If you have more than one cDAQ chassis, then you will need to have multiple tasks and multiple readers.

Thanks,
Sal 

0 Kudos
Message 4 of 12
(4,648 Views)

Hi Sal,

thank you for the approach which is new for me.

It looks like good solution, but I am not sure about the structure of output data. For example, if I read channels from 1 module, I get 2D data array - DATA(channels,samples). What is the structure of data array of multi modules task

meas_channels_task(0).AIChannels.Create VoltageChannel("cDAC1Mod8/ai0:15,cDAC1Mod7/ai0:15,cDAC1Mod6/ai0:15,cDAC1Mod5/ai0:15","", ....)?

Thanks,

Oleg.

 

0 Kudos
Message 5 of 12
(4,645 Views)
Hi Oleg,
 
The data will be read out in the order in which they are named in the task.  So for the example code you have, the first 16 channels will be from Mod8, the second 16 channels from Mod7, and so on...  If you were to rearrange the channel ordering in the CreateVoltageChannel function, the data would also be rearranged in the same manner.
 
Thanks,
Sal
0 Kudos
Message 6 of 12
(4,631 Views)

Hi Sal,

As I told, I can build control loop with start/stop commands inside the loop:

meas_channels_task0.Start()

meas_channels_task0.Stop()

In this case I get correct data but loop time increases by approximately 100-130ms.

 

When I move these commands out of loop and use

a_r = read_task(i).BeginReadMultiSample(num_of_samples, Nothing, Nothing)

read_task(i).EndReadMultiSample(a_r)

inside, loop time decreases down to ~20ms. The problem is that I cannot get current data from the device. Instead of this I get the first measurement result obtained at the beginning.

 Would you please advise me how resolve the problem?

 

Thanks, Oleg.

 

0 Kudos
Message 7 of 12
(4,595 Views)

Are you running a finite or continuous task?  If you are running a finite task.. once you read all of the data that you set in "number of samples" your device stops acquiring data.  (you won't get any new data).  To get new data from the finite task, you need to stop it then start it.

A better way to do this would be to use a continuous task...

Take a look at how this is done in the shipping example:

C:\Program Files\National Instruments\MeasurementStudioVS2003\DotNET\Examples\DAQmx\Analog In\Measure Voltage\ContAcqVoltageSamples_IntClk

0 Kudos
Message 8 of 12
(4,588 Views)

Hi Sal,

You are right. I used finite task with stop/start inside loop.

When I use continuous task, I get error message (see attached).

In my case AI reading must be done ~10ms after applying pulse in each loop cycle. How can I synchronize these 2 processes?

 

Thanks,

Oleg.

0 Kudos
Message 9 of 12
(4,586 Views)

Hi,

You are going to have to balance how many samples you get with each read call, how fast you are sampling and how often you are calling the read function.  This will be very specific to your application so there isn't much guidance that I can offer.

Your original description of the problem is not quite a continuous acquisition.  It seems like you are only interested in the data collected 15 ms after the pulse finishes.  If you do continous acquisition, you will be acquiring all of the time.

It sounds like you may want to do some sort of retriggerable analog input acquisition.  This can be pretty complicated to implement but it may give you the best results.

For more info on this, see this link:  http://zone.ni.com/devzone/cda/tut/p/id/5382

 

 

 

 

 

0 Kudos
Message 10 of 12
(4,578 Views)