LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Acquiring data from USB-9215 has varying sample rate

HI!
 
I'm trying to sample "synchronously" from a USB-9215 and a USB to RS-485.
I have put both of them into the same timed loop.
For sample rates below ~5 Hz it works and the ms timestamps are pretty consistent
but as I go above 20 it goes worse and worse.
I imaging it should be able to do this without a problem.
I have tried the loop with only the 9215 and it's the same, so it's not the USB to RS485.
The CPU is not loaded more than to 25%
 
The 9215 I have set up to take one sample from each channel every loop.
 
If I use the NI supplied data logger I have no problems at all and the resulting file shows
very good and stable time stamping.
 
Please have a look at my vi and let me know if there is anything obvious
 
0 Kudos
Message 1 of 4
(3,031 Views)

TomTurbo,

Using the term "synchronously" for what you are trying to do, is a bit of a misnomer. To do any real synchronization the two boards, or operations must share the same sampling clock. That is something you can't really do with USB devices. What it sounds like you are really doing is trying to "simultaneously" sample from the 9215 and the RS-485, all via software timed loops. The short answer is that this will only be successful at low speeds, and will fail when you try to sample faster and faster as you have noticed.

 

The long answer is that when you put both operations in the same while loop, the only thing that you can guarantee is that by the end of the iteration all of the code inside that while loop will have executed. But that is not to be confused with happen at the same time. With only one CPU in your computer only one action can happen at a time, we just think they often happen at the same time because the CPU is pretty fast at doing things. But our limitation is really the OS, the OS controls what has access to the CPU at any given time. With an OS such as Windows XP there is no way to deterministically ensure when actions will take place. Things such as mouse movements and keyboard strikes (among other things) have priority in the operation system and can easily cause your LabView programs to slow down and delay when things will happen. So unless you are running a Real Time system, there is no way to deterministically software time anything, especially when you get to faster sampling rates. That is why you always want to hardware time things, especially when you want to do any synchronization, but as I said that’s really not something the USB devices are designed to do.

Hope this clears some things up.

0 Kudos
Message 2 of 4
(3,017 Views)
Thanks for answering

I agree totally with you about everything you said, and I realize that I wasn't very clear.

I would be happy to accept the fact that everyhting happens within the same loop. What I refuse to believe
is that at a loop time of 30 millisec the computer and LabView isn't able to read a couple of bytes from the serial buffer
and a couple of bytes from the 9215. Something must be wrong.

Tom
0 Kudos
Message 3 of 4
(3,016 Views)

Hello Tom,

I have looked at your VI and do see something that could be causing the problems you have described.  For each loop iteration you are doing a number of VISA operations and you have 4 sets of 5 millisecond waits that operate sequentially, forcing your loop to take at least 20 ms to complete each iteration.  You do not need to have a wait following every VISA write.  If you want to be sure that your USB-9215 can complete a software timed read every few milliseconds, please try running an example.  If you are using Windows, the examples install at Start >> Programs >> National Instruments >> NI-DAQmx Base >> Examples >> LabVIEW.  If you look in the Dynamic >> ai folder, there is an example named Cont Acq & Chart Samples - SW Timed that can be used to get an idea of how fast you can acquire data with the method you are using.  Be aware that the VISA reads and writes will probably cause your loop to iterate slower than it would if you were just doing a DAQmx Base Read.  If you need to get data from USB-9215 at a faster rate, then I would suggest you implement hardware timing.  There are examples of this in the same folder. 

Hope this helps,

Laura

0 Kudos
Message 4 of 4
(2,995 Views)