Hello,
I want to use ADC in program and before that i wanted to test how fast will it work (i know it can be calculated, but for exercise i wanted to check it) . I wrote code that should check how fast is the conversion done:
void setup() {
//set prescaller
ADCSRA |= 1<<ADPS2;
ADCSRA |= 1<<ADPS1;
//left adjust result (i want to read 8 bits)
ADMUX |= 1<<ADLAR;
//ADC interrupt enable
ADCSRA |= 1<<ADIE;
//ADC enable
ADCSRA |= 1<<ADEN;
//enable global interrputs
sei();
//start conversion
ADCSRA |= 1<<ADSC;
Serial.begin(9600);
Serial.println("Started");
}
volatile unsigned long completions=0;
unsigned long lastPrint = 0;
ISR(ADC_vect) {
completions++;
ADCSRA |= 1<<ADSC;
}
void loop() {
if ((millis()-lastPrint)>1000) {
lastPrint = millis();
Serial.print("ADC results/sec: ");
Serial.println(completions/(millis()/1000));
}
}
The problem is that no matter what i put in prescaler register i get similar result - about 9k conversions per second:
ADC results/sec: 8942
What am i doing wrong?