0

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.

  • 2
    And of course you want it on the Due, so my AVR knowledge is little help here. All I can suggest is to crack open the datasheet and learn about the ADC and interrupt facilities on the SAM3X. – Ignacio Vazquez-Abrams Dec 9 '14 at 15:55
3

Ignacio's proposal is surely a good one if you really need higher sample rates, but I would try another approach:
Average your signal before sampling it! This can be done by connecting a simple RC lowpass to your AD input.
With that you get rid off those high frequency noise you don't need, but without wasting CPU time.

| improve this answer | |
0

The ADC is rated at up to 15K samples per second. So reading a 1000 is not a problem. However, care must be taken in the Vcc used for the ADC (AVcc). It must be noise free otherwise it will introduce noise into the digital readings, when it actually isn't there in the analogue signal.

See page 256 on the Atmel 328 datasheet for further information.

The RC Lowpass filter should also be used on the AVcc supply, as well as the pressure sensor signal.

I just thought! Are you using a Serial.print() after each analogRead()??? If so, the serial port will drastically slow down the sample rate. If this is the case perform a number of analogRead()s then use Serial.print() after some form of processing.

| improve this answer | |
  • 1
    The Due does not use an ATmega chip, and AVcc is already fixed on an Arduino. – Ignacio Vazquez-Abrams Dec 12 '14 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.