AnalogRead too slow… Faster alternative?

For a program that I'm working on, I want to get an accurate reading from a noisy pressure sensor. So, the idea that I have is to do a thousand AnalogRead commands on the same port very quickly and then average them. The pressure readings become very precise, however, the program that I am running becomes very slow. I need my program to be orders of magnitude faster.

I'm sure that there's a faster way to do AnalogRead commands, especially because I am requesting the same port over and over. Maybe there's a way that I can take lower resolutions of readings and then average those? I don't know. Can anyone help me? I am an amateur Arduino user looking to learn.

I have done a little bit of research on my own and had trouble finding concrete examples.

See this tutorial (among many other discussions that are quite rapidly accessed via Google) http://www.openmusiclabs.com/learning/digital/atmega-adc/

For rapidly reading the ADC without using AnalogRead, see this example http://wiki.openmusiclabs.com/wiki/Example

The pressure readings become very precise, however, the program that I am running becomes very slow. I need my program to be orders of magnitude faster.

How long is it taking? I'm pretty sure you can get more than 1000 readings in 1/10th of a second if you are not doing anything else.

If you are sending every reading to the serial monitor, that will slow things down.

...I'll bet an average of 1000 readings is no more accurate than an average of 100 readings. You could also use an analog filter (a resistor and capacitor) to reduce the noise. And/or you might want to use some "fuzzy logic" to throw-away outlier readings, especially if there are readings that you know are outside of the true range.

If you want a faster A/D then put this in the setup function:-

// set up fast ADC mode
   ADCSRA = (ADCSRA & 0xf8) | 0x04; // set 16 times division

Averaging 1000 readings suggests there is something seriously wrong somewhere that needs to be fixed. I would have no confidence in the average of 1000 readings unless I had confidence in the average of any consecutive 10 of them.

I suspect you should be thinking of greater intervals between readings and much fewer readings.

...R

Hi, what is the make and model of the pressure sensor, and what are you measuring?
1000 samples sounds very high as Robin2 states.
Is the noise from the fluctuation/noise from the media you are measuring, the sensor or from the leads between the sensor and the arduino?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

Tom… :slight_smile:

I want to get an accurate reading from a noisy pressure sensor.

Can you post the datasheet of that noisy sensor? maybe you should consider a more stable one........

solve in HW what is difficult in SW and vice versa

95% confidence limits for your average can be calculated as Y +/- 2.2*s/sqrt(r)

where Y is the average you calculate. 2.2 is actually a factor based on the degrees of freedom in your s s is the standard deviation of your data r is the number of data points.

even assuming a standard deviation of 100 units, 1000 points gives you your mean within +/- 7 units. 100 points gives you your mean within +/- 22 units.