Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA reading drastically slowing down at 20Hz (Labview + Arduino + Xbee project)

Solved!
Go to solution

Hi,

I am quite new to Labview and Arduino, so excuse me if I use incorrect terms. I am having some troubles with the following project, I hope you guys can give me some guidance!
I have 16 sensors connected to 16 analog pins on an Arduino mega board. This board has a wireless shield mounted on it, with an Xbee module. I have another Xbee module which communicates with it and is mounted on a USB dongle that plugs into a PC, with Labview 2015.

The A/D output from the Arduino analog pins is read and sent every 50ms to the Xbee module connected to the PC. So every 50ms (that is, a sampling frequency of 20Hz), a new line of comma separated analog readings is sent, using AnalogRead and Serialprint in Arduino. This data is fed to a Labview code with a producer-consumer architecture. This code configures a VISA serial port, reads the data, converts it to a voltage value and writes the data to a text file (see block_diagram.jpg).

The problem is that at a sampling frequency of 20Hz (with the configuration of the attached jpg) when reaching 400 processing iterations the code drastically slows down and values are not parsed correctly. It behaves as if the queue was overflowed (but queue elements indicators show 0), or memory or buffers were full. This seems quite suprising to me since the sampling frequency is so slow. I tried a couple of configurations setting buffer size, flushing the buffer, using waiting times but nothing seemed to work. Is it because the processor loop takes too much time to iterate? I tried disabling the data parsing, the voltage conversion and the text file generation, and just keep the dequeueing reading, and still got the same behaviour.

What may be causing this? Any suggestions to modify the block diagram are very welcome! Is there a more efficient way to do this than with VISA, or queues...?

I am using Labview 2015 on Windows 7.

Thanks!!block_diagram.jpg

0 Kudos
Message 1 of 3
(3,872 Views)
Solution
Accepted by topic author smx

@sminanog wrote:

It behaves as if the queue was overflowed (but queue elements indicators show 0), or memory or buffers were full.


You are thinking along the right things. But the big problem I see here is that you have an ever growing array until you stop the program.  You should move the writing of the file to be inside of your consumer loop.  This will eliminate the need to constantly grow your array in the shift register, using up tons of memory and causing memory copies (which gets very expensive).

 

The other concern I have is the rate at which your data comes in.  If you have a Baud Rate of 9600, then in the 50ms you can transmit 48 bytes.  That leaves 3 bytes per sample, including the comma.  If you have a baud rate of 115200, this turns into 576 bytes you can send in the 50ms.  So the lesson here is to make sure you are using a baud rate that is fast enough to handle the data you are trying to send.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 3
(3,858 Views)

Hi crossrulz,
Thank you very much for your help, it was indeed the baud rate that was too low for the data being sent. I was so focused on the Labview code that I didn't realize, so thanks for the insight!

0 Kudos
Message 3 of 3
(3,776 Views)