Go Down

Topic: Faster Analog Read? (Read 163571 times) previous topic - next topic


May 30, 2010, 02:28 pm Last Edit: May 30, 2010, 03:10 pm by itsthemedication Reason: 1
I know this is an old thread, but I want to thank anyone that is still around for contributing.  I ran the duemilanova using a prescale of 16 (thanks jmknapp!), and performed an analogRead on a 1K Hertz signal.  Here is the result (100 samples of 1000 Hz sine wave):

Gives a 56K sample rate!  Next up, prescale to 16, use a 20 MHz crystal, and rely on i2c to move the data.  Were very close to a very usable $30 DAQ!  Thanks guys.  

Just for comparison, here are the same 100 samples of a 1000 Hz sine wave using the normal prescale of 128 (it automatically resets itself back to 128 when the arduino reboots/resets).

Here's the code ...

Code: [Select]

 Analog Input with prescale change
 Reading a 1 kHz sine wave, 0 to 5 volts
 Using analog 0
 Results stored in memory for highest speed
 using code from:
 with special thanks to jmknapp

#define FASTADC 1
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

int value[100];   // variable to store the value coming from the sensor
int i=0;

void setup()
  Serial.begin(9600) ;
 int start ;
 int i ;
 // set prescale to 16
 sbi(ADCSRA,ADPS2) ;
 cbi(ADCSRA,ADPS1) ;
 cbi(ADCSRA,ADPS0) ;

void loop()
for (i=0;i<100;i++)
for (i=0;i<100;i++)

You'll (hopefully) find continuing progress at:



Thanks to everyone on this thread, I'm getting my first Arduino in a couple of days, and I need read 32 analog inputs several hundred times quickly. The prescale factor of 16 will make this possible. I will try to post how this turns out when/if I get it working.


I know this is an old thread but I'm looking at speeding up the sampling time for Analogreads also and have a couple of questions.  The datasheet talks about increasing the ADC clock to 1Mhz but it may have an impact to resolution.  The datasheet eludes to the fact the reason behind using the default 200kHz clock is because it is optimized around the connected voltage source having an output impedance of 10k or less.  Is it reasonable to assume that you might be able to maintain the same resolution at higher speeds if the output impedance of the voltage source is significantly lower?  Is the resolution loss a function of capacitance charge time in the Sample and Hold circuitry?  I'm going to be connecting a MAX4372 to the Arduino and it has an output impedance of 1.5 ohms so I'm thinking I should be OK with increasing the frequency to a higher speed.  Anyone have any thoughts on this matter?  Thanks.


Dec 08, 2010, 03:22 pm Last Edit: Dec 08, 2010, 03:26 pm by pascalito Reason: 1
Hi !
I'm very interested in fast analog ports on arduino too.
So i tried some speed tests on this instruction v=analogread(pin); (v and pin ar ints).

Prescaler        Maximum sampling frequency
 16                 62.5 kHz
 32                 33.2 kHz
 64                  17.8 kHz
128                    8.9 kHz

To get the maximum precision, i would take just the sampling speed i need, not more. I didnt test at prescaler lower than 16 because of the datasheet 1MHz limit for the DAC speed.


Is it possible to get an analog result faster than 13 ADC clocks, say if less resolution is required? Like, maybe 10 or 11 clocks for 8 bit accuracy?

Also, it appears the 1MHz ADC clock rate "limit" is a soft limit. The spec sheet says that faster ADC clock rates haven't been characterized, but it doesn't say it won't work at all.

I want to push this to the limit because I intend to try to get at least 8 analog signals (16 if I go for the MEGA) streaming into my computer as fast as possible... hopefully 10kHz each. May take some low-level picking around (especially to stream it reliably over USB... that will be a challenge!), but this is my goal.

Does Arduino have separate sample-and-hold circuitry for each analog input pin, allowing simultaneous sampling of all the analog input pins? This would be really nice (though not absolutely required).


Is it possible to get an analog result faster than 13 ADC clocks

No. Not according to the datasheet

Does Arduino have separate sample-and-hold circuitry for each analog input pin

No. The channels are multiplexed. I wonder if you might have better luck with an external A/D converter.


On this thread, someone succeeded in analog sampling at 360kHz (actually, he was operating the ADC at 8MHz--instead of the usual 1MHz--to achieve 360kHz), though I believe at reduced precision:
(I believe they also achieved 10 bits precision at 124kHz).
Also of note is that gabebear is sending data at 2Mbit/s.

These figures are what we should be shooting for. Now that it has been shown to be possible, we can do it.

Since it appears the analog input pins don't each have dedicated sample-and-hold circuitry, I'll have to live with non-simultaneous sampling for multiple inputs. That's okay.

As far as using a dedicated ADC... As long as I'm running it through an Arduino, I don't think it will help my performance considerably, since it still has to be put through the serial connection, which seems to be able to do 2Mbit/s if you tweak it just right (but no more, at least not considerably more).



Does Arduino have separate sample-and-hold circuitry for each analog input pin

No. The channels are multiplexed. I wonder if you might have better luck with an external A/D converter.
After thinking about it for a little while, I realized that my application (a phased array of microphones, with the processing done on the PC-side) doesn't require simultaneous sampling, as long as I know which analog input is being sampled and at what time. I would still have to interpolate between samples when combining the signals even if simultaneous sampling were possible.

And I've looked at different A/D chips and acquisition interfaces. No commercially sold and packaged DAQ device comes close to an Arduino (IF I can sample 8 analog signals at least at 8-bits and, say, 8kHz each... while streaming to my PC at almost 2Mbit/s) or some similar kind of microcontroller for a similar price. Since the Arduino seems to have such a rich community and because I like the relatively-easy-learn environment and because it's so cheap, I think it's a pretty good fit. I hope to later do some similar work with ultrasound in the >1MHz range, but for that I will need a different microcontroller (or, actually, many microcontrollers, with the data captured initially onto their on-board SRAM, since I don't think I'll be able to stream that much data continuously at full duty cycle), since the typical Arduino-type microcontrollers don't support that many samples per second.

If I had thousands of dollars to spend, I would just buy myself some NI high-speed DAQ equipment and LabView (that's what I did before... I'm trying to replicate my senior thesis project using equipment that I own instead of my alma mader's equipment which I no longer have access to). But I don't have much of a disposable income right now.

Eventually, though, I'd like to get into the >100MHz range so I can do some phased array imaging with radiowaves (underground imaging for amateur archeology). But that is clearly out of the realm of microcontrollers. I will need either a different approach or more money for that. Perhaps an arduino driving some programmable analog delay lines.

DAQ equipment (and software like Labview) is expensive. Arduino and associated software are far cheaper.

Go Up