Forum 2005-2010 (read only) > Frequently-Asked Questions

Faster Analog Read?

<< < (4/5) > >>

itsthemedication:
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: ---
/*
 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:
 http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1208715493/11
 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))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

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

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

void loop()
{
for (i=0;i<100;i++)
{
 value[i]=analogRead(0);
}
for (i=0;i<100;i++)
{
 Serial.println(value[i]);
}
Serial.println();
Serial.println();
Serial.println();
delay(5000);
 
}


--- End code ---


You'll (hopefully) find continuing progress at:

http://sites.google.com/site/measuringstuff/the-arduino


Notaclue12:
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.

wayneft:
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.

pascalito:
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.

Robotbeat:
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).

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version