Skip to content

Instantly share code, notes, and snippets.

@dansteingart
Created July 30, 2011 18:28
Show Gist options
  • Save dansteingart/1115829 to your computer and use it in GitHub Desktop.
Save dansteingart/1115829 to your computer and use it in GitHub Desktop.
Speeding up the ADC's on an arduino
#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
void setup() {
int start ;
int i ;
#if FASTADC
// set prescale to 16
sbi(ADCSRA,ADPS2) ;
cbi(ADCSRA,ADPS1) ;
cbi(ADCSRA,ADPS0) ;
#endif
Serial.begin(9600) ;
Serial.print("ADCTEST: ") ;
start = millis() ;
for (i = 0 ; i < 1000 ; i++)
analogRead(0) ;
Serial.print(millis() - start) ;
Serial.println(" msec (1000 calls)") ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment