09-28-2007 06:09 PM
09-30-2007 08:18 AM
Hello Sridhar,
I am just starting with NIDAQmx and cannot give an answer to your question on ReadAnalog64 characteristics.
However I am building an application that reads a single sample from 3 ai-lines and - after processing these 3 - updates a single ao-line. And it seems to work far beyond the 1k frequency. For this, I assumed that I had to start with minimizing task programming overhead. So my approach is:
1. Start a task for analog input, continuous acquisition, using a buffer (8k), overwriting unread samples, and define a function when N(=1) samples are acquired
2. Simular define and start a task for analog output.
3. In the callback function for N samples, I retrieve the most recent available sample and process this.
So there is only once the overhead for the tasks,including starting the tasks. Both analog input and analog output are running continuous until I select a stop-button.
Note that the processing is not synchonous with the actual rate of internal-clock data acquisition. I set this at a value slightly higher than needed. And I use a simple counter to display once in a while the actual processing frequency. With output to the screen it is only a few hundred hertz; with only output to analog task it becomes beyond 1 kHz.
Most of the code is from the examples for daqmx / analog in / voltage. Because one of the function requires an even number of samples, I had to expand the number of ai to four channels. Some of the code for creating the analog input is:
DAQmxErrChk (DAQmxCreateTask("",&gTaskHandleInput));
DAQmxErrChk (DAQmxCreateAIVoltageChan(gTaskHandleInput,chan,"",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(gTaskHandleInput,NULL,rate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,gSamplesPerChannel));
DAQmxErrChk (DAQmxCfgInputBuffer (gTaskHandleInput, SingleSampleBuffer));
DAQmxErrChk (DAQmxSetReadAttribute (gTaskHandleInput, DAQmx_Read_OverWrite, DAQmx_Val_OverwriteUnreadSamps));
DAQmxErrChk (DAQmxSetReadAttribute (gTaskHandleInput, DAQmx_Read_RelativeTo,DAQmx_Val_MostRecentSamp));
DAQmxErrChk (DAQmxSetReadAttribute (gTaskHandleInput, DAQmx_Read_Offset, -1 * gSamplesPerChannel));
DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(gTaskHandleInput,DAQmx_Val_Acquired_Into_Buffer,gSamplesPerChannel,0,ScopeModeSingleSampleCallback,NULL));
DAQmxErrChk (DAQmxStartTask(gTaskHandleInput));
Succes, Jos
10-01-2007 11:28 AM
Hello Sridhar,
I am sorry to say that I have to correct myself. My only excuse it that I have 7 devices at my "development" computer of which there are 3 USB devices of which there is only one single real hardware device.
With all simulated devices I get far beyond the 1 kHz (my target as well) but with the real hardware 'NDAQPad-6015' I am stuck at 350 Hz. So instead of an answer I get curious if somebody else sends a better reply.
Sorry, Jos
10-02-2007
02:16 PM
- last edited on
08-15-2025
01:19 PM
by
Content Cleaner
Hi Srindhar,
DAQmxReadAnalogF64 is a blocking function, so it will wait until NumberOfSamples is received before it returns its values. So the speed at which it runs is very dependent on the sampling rate and the number of samples expected. If you reduce the NumberOfSamples do you see an increase in speed?
Also, there are a few other threads that may help, including some example code to help troubleshoot. Take a look here and here.
Let me know if there's more I can do to help.
10-03-2007 10:35 AM
Hi Mark,
Thanks for you inputs. The number of samples that I am using is only two. My code has two functions one for cards initialisation and other for data acquisition.
My initialisation function: (I initialise for all the 16 channels of the card)
{
< code>
DAQmxCreateTask ("AnalogIn", &Handle);
DAQmxCreateAIVoltageChan (Handle, "AnalogIn/ai0:15", "" ,DAQmx_Val_RSE, -10, 10, DAQmx_Val_Volts,NULL);
DAQmxCfgSampClkTiming (Handle, "" ,1000, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 2);
DAQmxGetTaskAttribute (Handle, DAQmx_Task_NumChans, &numChannels);
<code>
}
My Data Acquisition function:
loop {
<code>
DAQmxReadAnalogF64 (Handle, 2, 10.0, DAQmx_Val_GroupByChannel, dataIn, 32, &numRead, NULL);
<code>
}
I increased the sampling rate to 10000 S/s also but there is no improvement in the timing of loop in the data acquisition function. It is still around 150 which is 6 msec for one loop execution.
But when i comment the read function in the loop the timing is around 500 which is 2 ms for one loop execution.
is there any thing that i need to do extra in my code. Your help would be appreciated a lot.
regards,
sridhar
10-04-2007 01:04 AM
10-04-2007 05:53 PM
Hi Sridhar,
Would you mind sharing some background on your desired application? There may be other things to consider that would help you better overall than just answering these questions.
Let me do my best to clarify a few things that can affect program performance. There is overhead in every while loop, read function, calculation, etc. The read function is going to be one of the more time-consuming calls because it gets the number of specified samples from the buffer, interrupts the operating system, transfers the data across the PCI bus, etc. To reduce this overhead you can increase the number of samples read at a time.
The DAQmxReadRaw will return the binary value before its ADC conversion and scaling, so it theoretically could run faster than DAQmxReadAnalogF64, but could be harder to work with. If you need to do operations in volts, you’d need to convert the data and the conversion you would perform on the binary data would most likely be slower than DAQmxReadAnalogF64, so it’s generally not recommended.
Another limitation is that the operating system has no timing guarantee. The shortest wait function you can even program is 1 ms, because it’s generally not possible to expect a higher timing resolution. It could be faster, but it is entirely possible to go slower depending on what other processes are running. Speed is also dependent on the capability of your computer. The only thing I can think of to make your code faster than 1 ms per loop iteration is to have zero wait in the loop (which you may already be doing). Keep in mind that this doesn’t guarantee anything as the operating system can still decide whether it gives priority to your program or other “critical/important” processes, but it’s the best chance you have before you need to consider investing in a real-time system and FPGA. However, if that is something you want to pursue, please visit www.ni.com/support to get in touch with a salesperson who can spec out a system for you.
10-14-2007 05:56 AM
10-15-2007
03:05 PM
- last edited on
08-15-2025
01:22 PM
by
Content Cleaner
Hi Jos,
When I said there is overhead in every loop, read function, calculation, etc., I was referring to the fact that those operations take more computational power to execute than a simply displaying a hard-coded number.
The reason you are stuck around 300 Hz is due to the specification of the NI DAQPad-6015 for analog output, which can be found on the product page under specifications or in the specification document. The analog output has an update rate of 300 S/s. The PCI-6110 is in a separate league, being a simultaneous-sampling DAQ card with an update rate of 4 MS/s—quite a bit of difference.
To compare specifications of different products, you can visit www.ni.com/products; choose “Data Acquisition (DAQ)” under the “Shop for Hardware” column in the middle of the page. Choose at least one parameter to search and then you can narrow it down to more specific criteria and compare the products by checking their boxes and clicking “Compare”.
I hope this helps.
10-16-2007 02:01 AM
Hello Mark,
I missed that specification.
I started the mentioned application with available equipment i.e. DAQPad-6015 and PCI-6110, but the application needs its own hardware. So yesterday I selected a few options from the M-series e.g. USB-6251 and PCI-6259 with the hardware selection/comparison as you suggested. Learning from you reply, I also looked this morning again through the specifications for the USB-625x family. All these information sources give an update of 2.86 Ms/s for single channel and 1.25 Ms/s for four channels. I did not find any distinction between continuous pumping a full data trace from USB to host computer and repeatedly sending an update of a single sample (for 4 channels).
Can I assume now that the limitation - up to 1.25 Ms/s when using 4 channels - will be not anymore the USB-6251 device nor the DAQmx driver, but maybe will be due to the use of the USB 2.0 bus by other devices and probably will be the processing speed of my computer when it has to process each EveryNSample callback ? Or do I have to look into other kinds of specification ?
Thanks anywhy for your detailed information.
Regards, Jos