Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx Task start delay / Quickly generate arbitrary output voltages

Solved!
Go to solution

HI there,

 

(sorry, I´m new to this forum and could not yet find a reasonable solution using Search)

 

I am developing a C# multithreading application that simultaneously generates a waveform in the "background" using buffered output, grabs images via a firewire camera and processes them. I have a second free DA channel that I would like to use during debugging a a real-time marker so that I can verify on an oscilloscope what the relative state of the concurrent processes is, i.e. output a voltage of 1 V while in processing step 1, 2 Volts in processing step 2 etc. or I would output a short spike at a certain critical point. This is done using a Task like

 

            DA_Task_sgl = new Task();
            DA_Task_sgl.AOChannels.CreateVoltageChannel("/Dev1/ao0", "DA0", -MXVOLTAGE, MXVOLTAGE, AOVoltageUnits.Volts);
            DA_Task_sgl.Control(TaskAction.Verify);
            DA_Task_sgl.Timing.SampleTimingType = SampleTimingType.OnDemand;
            DA_Writer_sgl = new AnalogSingleChannelWriter(DA_Task_sgl.Stream);

 

and later where I want the voltage to change

 

            DA_Writer_sgl.WriteSingleSample(true, voltage);

 

A similar technique worked pretty well using NI-Traditional DAQ, but with NIDAQmx and the Task concept it seems that outputting one voltage value takes about 1.5ms (also of CPU time) which is too slow in many cases. With NI-Traditional DAQ two back-to-back AO_VWrite() calls could generate a spike with aduration of only a few µsec instead. I assume that the delay in NIDAQmx is mostly determined by starting and stopping the Task etc.

 

Is there a way to avoid all this (in NIDAQmx) and more directly access the underlying hardware?

 

(Please don´t tell me that this is a Windows limitation, the NI-Trad code clearly shows that it can be done, clearly the thread might be interrupted during the voltage output, but then is also my processing, exactly what I WANT to check with this technique, but that 1.5 ms delay is always there!)

 

(Current card used PCI-6014 with NIDAQmx 9.x, but I think it´s not the card that is too slow itself, I can get > 100 kHz analog update rate on the waveform voltage channel via DMA)

 

Thanks

 

Joachim

0 Kudos
Message 1 of 4
(3,335 Views)
Solution
Accepted by topic author fabwes

Hi fabwes,

 

The code snippet you posted is doing On Demand AO.  This means that every time you write we go and poke the hardware to generate the voltage.  Your assumption is correct, the slowness you are seeing is because of the Task Model.  Every time you are calling WriteSingleSample the task is started, the voltage is output, and the task is stopped.  I would suggest the following code:

 

DA_Task_sgl = new Task();
DA_Task_sgl.AOChannels.CreateVoltageChannel("/Dev1

/ao0", "DA0", -MXVOLTAGE, MXVOLTAGE, AOVoltageUnits.Volts);
DA_Task_sgl.Timing.SampleTimingType = SampleTimingType.OnDemand;

DA_Writer_sgl = new AnalogSingleChannelWriter(DA_Task_sgl.Stream);

DA_Task_sgl.Control(TaskAction.Start);

DA_Writer_sgl.WriteSingleSample(false /* since we're already started, this parameter is essentially ignored */, voltage);

 

This slight modification gets the overhead of starting the task out of the way before you start writing.

------
Zach Hindes
NI R&D
Message 2 of 4
(3,333 Views)

WOW, This a QUICK response!

 

I see I have not yet fully understood the task model, if it works this way will be great, I will check immediately. Thanx!

 

Joachim

 

 

0 Kudos
Message 3 of 4
(3,331 Views)

YEP, that´s what I was looking for, so easy, two back-to-back 5V/0V call now generate a 5 µs spike!

 

GREAT

 

Joachim

0 Kudos
Message 4 of 4
(3,326 Views)