07-31-2012 03:39 PM
NIDAQmx 7.5 on XP SP 3 with PCI 6034 E.
I want to read the most N most recent samples repeatedly in a 1kHz loop even if zero or less than N samples
have been acquired. I use NIDAQmx C API.
My problem is that the DAQmxReadAnalogF64 stops execution of the program for a few ms even though I have
I have set the property the RelativeTo property to Most_Recent_Samples and the Offset to -N. The problem is
particularly pronounced when the sampling frequency is low. To illustrate the problem, I have timed
the function calls to DAQmxReadAnalogF64
100 Hz, N = 2 => 8.5 ms
100 Hz, N = 10 =>8.5 ms
1'000 Hz, N = 10 => 1.45 ms
1'000 Hz, N = 100 => 1.45 ms
10'000 Hz, N = 10 => 1.06 ms
10'000 Hz, N = 100 => 0.93 ms
20'000 Hz, N = 10 => 0.30 ms
20'000 Hz, N = 100 => 0.21 ms
20'000 Hz, N = 1000 => 0.15 ms
In short, increasing the sampling frequency decrease the latency of the function call and,
to a lesser extent, increasing the number of desired samples also decreases the latency !
have tried setting timeout to -1, zero and 1 ms with no effect. Note that I always get the desired
number of samples and the function call never return an error.
Any help appreciated.
Gabriel Baud-Bovy
Vita-Salute San Raffaele University
08-06-2012 01:24 AM
Hi Gabriel,
DAQmxReadAnalogF64 is a blocking call. One way to avoid blocking on a DAQmxRead call is to only execute the read operation when necessary. The best way to do this is to make use of NI-DAQmx Events to monitor the transition of samples to the PC buffer (i.e. the area that is available to DAQmxRead). The example "C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Cont Acq-Int Clk" shows how to call the DAQmxRead from a seperate callback using NI-DAQmx Events.
Hopefully this helps.
Best Regards.
Claudio
08-10-2012 05:49 AM
Hi Claudio,
Thank you for your answer. I will check this NI-DAQmx Events . I think that my problem was that I would an offset of N-1 samples instead of N samples because I expected that the current position designaged a sample that was alread acquired while it seems it is not the case (I did not find a clear statement in the documentation but I might have missed it). Anyways, DAQmxReadAnalogF64 waited to acquire one more sample before returning and that explains also why it was slower at lower sampling rates.