Created
July 30, 2011 18:28
-
-
Save dansteingart/1115829 to your computer and use it in GitHub Desktop.
Speeding up the ADC's on an arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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