hello,
i want use adc in program , before wanted test how fast work (i know can calculated, exercise wanted check it) . wrote code should check how fast conversion done:
the problem no matter put in prescaler register similar result - 9k conversions per second:
what doing wrong?
i want use adc in program , before wanted test how fast work (i know can calculated, exercise wanted check it) . wrote code should check how fast conversion done:
code: [select]
void setup() {
//set prescaller
adcsra |= 1<<adps2;
adcsra |= 1<<adps1;
//left adjust result (i want 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 no matter put in prescaler register similar result - 9k conversions per second:
code: [select]
adc results/sec: 8942
what doing wrong?
you're assuming adps0-2 in default power state of 000b. it's arduino core initializes bits. add statement clear them before set them. e.g.
adcsra &= ~(bit(adps2) | bit(adps1) | bit(adps0));
adcsra &= ~(bit(adps2) | bit(adps1) | bit(adps0));
Arduino Forum > Using Arduino > Programming Questions > ADC prescaler and conversion time
arduino
Comments
Post a Comment