Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt time USB device versus PCI Card

Greetings:

I've written a VI that uses two hardware solutions (USB - 9215 and PCI 6043E) to gather data.  The program iterates through a loop every 500 ms collecting data at 6000 Hz on the PCI card and I have not yet been able to set a desirable rate for my USB device.   I have had a problem with buffer overflow and would like some education so I may decide the best course of action to resolve.

The easiest solution would be to decrease my acquisition rate.  I've gone from 3000 Hz to 1000 Hz to 500 Hz and am still having a buffer over flow on my USB device.  I don't want to further decrease my sampling rate because it inversely increases the noise in the final sample.  It seems that the issue is that the system does not have enough time to interrupt the processor to pull data off the USB device.  This raises two questions (if I am not pulling all the data off the device, what is my VI completing/computing).  In other words if I am collecting data at 1000 Hz but only have time to pull 990 samples per second does it leave those 10 samples in the buffer for next iteration.  Then those samples would not line up with my previous set of samples for the past 500 ms at the same time stamp.  This issue compounds because each iteration I add 10 samples per second to the buffer.  The other question is how come the USB device has this issue but the PCI device does not.  The USB device is capable of collecting data at 100 kS/s (per channel) but I am well below that limit.

The USB device uses a USB 1.1 port which only has a transfer rate of 183 kB/s.  If I purchased a PCI USB 2.0 card with a faster transfer (480 Mb/S)  rate, will that allow the buffer to be dumped to the processor in a shorter amount of time, or does the interrupt for the USB port requires the same amount of time each iteration regardless of the USB version.  The other solution I can think of is take some functionality out of my program (which I would prefer not to do) or collect data at a slower rate (instead of every 500 ms use every 1000 ms, which I also prefer not to do because I would like the resolution to measure change in my system).  Some education (or pointers towards book/articles) that address these issues would be greatly appreciated.

Many Thanks,
Nick
0 Kudos
Message 1 of 8
(5,191 Views)

Hello Nick,

The difference between how data is transferred over the two different buses (PCI and USB) is ultimately why you are seeing this performance difference.  A PCI device typically transfers data to system memory using DMA transfers.  DMA transfers allow the PCI bus to bypass the operating system and directly transfer data to system memory.  A USB device on the other hand, transfers data using interrupts, where for each data transfer, the device must request and be granted access to system memory from the operating system.  The result is that the speed at which interrupt-driven data transfers can occur are much more system dependant than DMA transfers.

A buffer overflow error indicates that LabVIEW is not emptying data from system memory before it is overwritten by data transferred from the device.  When you specify a 'number of samples per channel' to read in a DAQmx Read VI, LabVIEW waits until that amount of data is available in the system memory buffer, and pulls that data out for processing/displaying.  I think that what might be happening is that the operating system is busy servicing interrupts for your USB device, and LabVIEW is not being given enough processor time to empty data from your system memory.  You might be able to avoid a buffer overflow error by increasing the buffer size in system memory, maybe two or three times as much as it currently is.  Therefore, if LabVIEW is unable to empty the samples from memory for a few milliseconds, the data can just accumulate in the buffer and LabVIEW can process it a few milliseconds later when it has the processor time.  You can trick the DAQmx driver into allocating a larger buffer size by increasing the 'samples per channel' input of the DAQmx Timing VI or the  'samples to read' in the Task Timing settings of your DAQmx task, but keeping the 'number of samples per channel' setting of your DAQmx Read VI the same.  You can also manually set the size of the buffer in number of samples using the DAQmx Configure Input Buffer VI, located in the DAQmx Advanced Task Options palette.  Another option would be to set the 'number of samples per channel' setting of the DAQmx Read VI to -1.  This will cause the LabVIEW to grab all available samples from system memory every time the DAQmx Read VI is called.  Of course, this will probably require you to reprogram your application to handle a variable number of samples for processing.

I hope this information helps, and let us know if you have any further questions.

Regards,
Travis G.
Applications Engineering

Message 2 of 8
(5,180 Views)
Travis,

Thank you for the suggestions and I will manually increase the buffer as the solution I can use for now.  The catch is (and part of me feels like this is just putting a bandaid on the problem) that I haven't solved the problem.  The VI I run is designed to operate for 1000-2000 hours at a time (in fact it is meant to continually work, but be capable of collecting data on four different devices for independent 1000-2000 hour periods).  Thus by increasing the buffer size I will be able to allow the device to continually write more and more data to the buffer and I can time it such that the buffer will not over flow for 2000 hours.  This means that the buffer is continually increasing in size and if at some point I needed to run a test past 2000 hours I could get into a real pinch.

I would prefer to be able to have the program operate in a way that the computer has sufficient time to pull that data from the buffer.  Thus my questions if I purchase a USB 2.0 card will the processor/operating system require less time to interrupt the device than it is currently configured on a USB 1.1 device, leaving labview more time to process the data?  Another route I feel may work but I am not educated on, is there a way to change priorities on interrupt for Labview and the USB device and everything else on the system.  The computer is trully only used for dataq and I would drop interrupt priority to near zero for every other device (besides keyboard and mouse) if that would allow more time for labview and the device, thus allowing the data to be transferred in a timely fashion.

Thank you for the advice and insight
Nick
0 Kudos
Message 3 of 8
(5,167 Views)

Hello Nick,

I understand your concern regarding buffer depth and test duration.  Maybe you could use the method I stated above of setting the 'number of samples to read' of the DAQmx Read VI to -1.  This will allow the DAQmx Read VI to pull all available samples sitting in the buffer when it is called.  This method will give the advantages of having a hardware timed buffered acquisition, and allow the DAQmx Read to fully empty the buffer when it is given the needed processor time.  This will help to avoid a gradually increasing number of samples sitting in the buffer.  The only disadvantage is that you will have to modify any post-acquisition analysis in your program to handle a dynamically changing number of samples.

Regarding the performance difference of using a USB 2.0 host card as opposed to USB 1.1, you will not see a performance increase.  The USB-9215A is a USB Full Speed Device, as noted in the bus interface specification of the USB-9215 Operating Instructions.  Full speed devices, while compatible with USB 2.0, also work with USB 1.1 without any decrease in transfer rate.  This is because a full speed device is limited to a transfer rate of 12 Mb/s, which also is the maximum transfer rate of a USB 1.1 port.  Take a look at the following KB for information about this:

KB
3P882LCC: NI USB DAQ Compatibility with USB 1.1 and USB 2.0

Also, changing the interrupt level of your USB interface most likely wont increase performance.  Rather than altering these settings, I would recommend reworking your program to perform analysis and file logging tasks post-acquisition, and playing with the number of samples to read parameter as I have described above.

I hope this helps.

Travis G.

Message Edited by Travis G. on 03-28-2006 12:51 PM

Message Edited by Travis G. on 03-28-2006 12:52 PM

0 Kudos
Message 4 of 8
(5,155 Views)
Hi,
 
I wanted to clarify Travis's latest response.
 
The USB-9215 is a USB full speed device (12 Mbps) supported by NI-DAQmxBase.
 
The USB-9215A is a USB high speed device (480 Mbps) supported by NI-DAQmx.
 
This is noted on page 13 of the NI 9215 User Guide.
 
 
 
Thanks,
Sal
0 Kudos
Message 5 of 8
(5,143 Views)
Travis/Sal,

Thank you for the insight.  I had to self teach myself LV, (I'm a graduate student and there is not funding for me to take classes),  often I feel that I am completing tasks in a very obtuse manner, since I have little formal training and even learning what I need to learn, has not been intuitive.  Timing has been my largest hurdle to date.

I had (I believed, correct if not true) hardware timed my application by setting task timing to continuous with a clock setting of 6000 Hz and samples to read set to 3000.  Thus the application would iterate through the data acquisition loop every 500 ms (based off the hardware),  (I had checked hardware timing by also comparing the change in system clock each loop iteration and averaged 0.4983 ms over many  (100+ hours)).  The second device is the USB device and I had this set to operate at 500 Hz and 250 samples to read.  The USB device's buffer continually overflowed.  I thought this was because the interrupt time was not sufficiently long and if I upgraded to USB 2.0 the faster data transfer rate, would allow for a shorter interrupt time for data transfer conversely allowing the program to have a longer interrupt and thus more time to transfer data to memory.  I am not knowledgable in this area and since I have a USB-9215A that is capable of 480 Mbytes/sec, does that mean that even though I transfer much less data per second the time required to transfer this data would be reduced, thus providing more time for the OS and PC to process the data?

I took Travis's previous advice and set the USB device to Number of Samples Per Channel = -1.  That way the PCI device that has the fast DMA transfer times the program and the USB follows as a slave just pulling as much data as possible.  I spent several hours today attempting to figure out exactly what this is doing to no avail.  The way the LV Data Acq program is designed is to poll 500 ms worth of data, average the data as a simple method to data smoothing and then record the point.  By setting # samples/channel = -1 my best understanding is that this now just pulls the entire buffer to memory everytime the program operates.  This is confusing to me because in the previous setup for the dataq of the USB device I was buffering the data because the OS was not providing sufficient time (via an interrupt) to move the data to memory for writing.  Why would the OS have sufficient time now?  Does the -1 setting tell the computer and device to disregard all data not pulled?  Does that mean for one iteration of the program if the processor is busy it may pull nothing where another I may get 10000 data points?  How does setting the clock settings in MAX affect the acqusition rate for the DAQmx when the program is operating?  Does Sampling Rate (from clock settings (under tasks) in MAX) affect the acquistion?  Monitioring the USB device buffer it fluctuations between 0 and 1500 in about a ten second loop (it is at 1500 for ten seconds, drops to 0 then the next seconds returns to 1500 for ten more seconds), does that make any sense, because now I thought I was doing bufferless acquistions?  I just want to know that I am collecting enough data to take a representative average data point (my signal is in mV and fluctuates around an average by about +/- 7), I would like at least a 1000 data points per 500 ms cycle and that I am collecting 'new' data every iteration of the program, regardless of how busy the CPU is, I woudl like to understand what I am asking the program to complete by assigning -1 to the Read DAQmx.

Thanks for the guidance so far, it has been helpful
Nick
0 Kudos
Message 6 of 8
(5,139 Views)
Hey NIck,

Sorry about the misinformation before, but as Sal stated, the USB-9215A does support high-speed USB transfers.  I think that upgrading to a USB 2.0 interface will increase your performance.  The operating system will still have to service the device through interrupts, as opposed to DMA transfers as your PCI card uses, and you will not gain any performance increases in this area with a high-speed USB port.  However, only one interrupt is created for each data transfer.  Once the operating system services that interrupt, you will be able to perform the data transfer much faster with the high-speed interface, and you should see a performance increase.

With regards to your other questions, whenever you use the DAQmx Timing > Sample Clock VI, or create a task in MAX and set the Task Timing to N Samples or Continuous, you are creating a hardware timed buffered acquisition.  The sampling rate you set determines the rate of the sample clock for how data is acquired on the device.  The 'samples to read' you specify in the Task Timing in MAX, or on the DAQmx Timing VI, is just used to calculate the buffer size to allocate for the task.  The actual number of samples being read into LabVIEW at a time is determined by the 'samples per channel' input of the DAQmx Read VI.  If you set this 'samples per channel' input to -1, you are still performing a hardware timed buffered acquisition, with a buffer size allocated based on your settings under Task Timing in MAX or in the DAQmx Timing VI.  The device will be continuously acquiring the samples into a buffer in system memory, and all the interrupts and data transfer from the USB device to system memory will occur behind the scenes.  However, when the DAQmx Read VI is called, it will grab all available samples in the buffer.  If the DAQmx Read VI is within a while loop, the rate of the while loop will no longer be controlled by the rate of acquisition and number of samples to read.  Instead, the loop will execute as fast as possible, and whenever it begins another cycle and calls the DAQmx Read VI, the program will not wait at that VI until a certain number of samples have arrived, but will instead immeadiately grab all available samples (which may be zero), and continue executing the rest of the code in the loop.

From your straightforward requirements of what you are trying to do, I would recommend upgrading to a USB 2.0 port.  I would then perform a continuous hardware timed acquisition, with your required sampling rate and increase the 'samples to read' in the Task Timing in MAX and the 'number of samples per channel' input of your DAQmx Read VI (keeping both the same), until you no longer see buffer overflows.  If you want a fixed number of samples to average each iteration, then don't use the -1 samples per channel method I recommended above.  As you increase the number of sample to read, you will be reducing the number of interrupts the OS must service to transfer data from the USB device.  I would also recommend reducing the amount of of other processing that is done in your while loop as much as possible.  Try to move as much of your analysis to post acquisition as possilbe, so that LabVIEW is not tied up with analysis tasks and has time to execute the DAQmx Reads.

I hope this helps to answer some of your questions and sorry if I complicated things by going into these advanced timing topics.

Regards,
Travis G.
0 Kudos
Message 7 of 8
(5,125 Views)
Travis,

Thank you for the information, it has been VERY helpful, and no need for an apology, I welcome all the advice with open arms.  

I will upgrade to USB 2.0 to free other system resources.  I am currently running one of the two devices I have as a timed buffered acquistion and I am running my other device timed at the same rate but with -1 for 'samples per channel to read'.  I don't really care the number of samples I get to average on that device, as there are enough to get a representative sample (it does not need to be the same # of samples every time).

Again Thank you for your advice and direction, it has been most helpful

Best,
Nick
0 Kudos
Message 8 of 8
(5,119 Views)