08-13-2013 08:13 AM
Hi,
I'm using an Arduino Uno and LIFA to measure the output of 6 analog pressure sensors. It will be used to manually change the pressure at 6 different points in real-time.
I've succeeded in obtaining and displaying the data. I'm getting around 25Hz per channel/pin before any smoothing, etc...
Although this should be enough for the application, the signal is a bit noisy and I've tried to smooth it using the "Savitsky-Goray Point by Point" filter, which works quite well, but creates a considerable delay in the signal (the filter needs around 60 samples to be really useful).
I've read posts about speeding up AnalogRead (changing the ADC clock, etc...), or using continuous aquisition, but nothing about multiple reading multiple pins and nothing about possible speed optimizations with LIFA/LabView.
My first question would be what should I focus myself more: trying to change the AnalogRead function in the Arduino library, changing the LIFA firmware to create a new "faster" AnalogRead specifically for reading the 6 pins, changing the LabView code, or using LabView without LIFA?
My second question would be, do you have an idea on what is the limiting factor on my setup? Is it the settling time of the ADC changing between channels, the serial comunication back and forth between Arduino and LabView or something else? I'm just starting to use LabView so it's quite hard to me to understand what is the faster implementation and why (I have tried a couple of different ones).
Thanks for all the help in advance!
P.S.:The scaling might be a bit off because I'm using the 1.1V reference on the Arduino (I changed the firmware and the scaling factor in AnalogReadPin.vi)
Solved! Go to Solution.
08-13-2013 09:52 AM
Your largest limiting factor is likely the serial communication. Modifying the analog read function in Arduino will likely provide negligible increase in speed due to the serial communication speed.
One major optimization you can do (without modifying any Arduino code) is to use the Analog Read Port.vi. This will get all 6 analog pin value in a single instruction. This should reduce the number of bytes transmitted by 30 (if I did my simple math correctly).
About programming in LabVIEW:
You should avoid using local variables in your case. Doing this causes a race condition in which the local variable could be read (for your analysis section of code) before it gets updated by the actual sensor value from Arduino. You would simply want to wire the value directly to the function that uses the value.
08-13-2013 11:23 AM
Thanks Nathan!
I'm getting around 60Hz now, not too fast but enough... I had read somewhere that Analog Read Port.vi. wasn't very good for fast measurements so I never got to try it.
About the local variables, the code was written by someone else, I had no idea it could make a difference but I already changed it.
Just one more thing. Right now, with the updated code I'm getting different readouts from the Arduino (used to be around 0.4/0.5 V, now they are 0.2/0.3 V). In relative terms the results are consistent (same sensors higher/lower when they should, as before), any idea on why this might be happening? And do you think these results should be more reliable than the previous ones?
08-13-2013 01:22 PM
MBarreiros wrote:
I'm getting around 60Hz now, not too fast but enough... I had read somewhere that Analog Read Port.vi. wasn't very good for fast measurements so I never got to try it.
I don't see any reason why Analog Read Port.vi would be worse in any case when compared to the single pin VI. By using the port VI, you remove a bunch of unnecessry overhead that is included in each individual call to Arduino. Everything else would be exactly the same i.e. it uses the same functions on the Arduino and simply sends it all back at once.
Just one more thing. Right now, with the updated code I'm getting different readouts from the Arduino (used to be around 0.4/0.5 V, now they are 0.2/0.3 V). In relative terms the results are consistent (same sensors higher/lower when they should, as before), any idea on why this might be happening? And do you think these results should be more reliable than the previous ones?
You previously mentioned that you change the reference for the analog readings (I'm assuming this applies to all uses of analogRead() in Arduino) and that you change the Analog Read Pin.vi accordingly. Did you forget to make this same change in Analog Read Port.vi?