09-02-2010 09:58 AM
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
Solved! Go to Solution.
09-02-2010 10:08 AM
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.
09-02-2010 10:16 AM
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
09-02-2010 10:33 AM
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