measure in ADC in free running mode

This commit is contained in:
bigalex 2012-10-05 23:24:03 +02:00
parent 5d3c3bcb51
commit d69160608c
2 changed files with 4 additions and 5 deletions

View File

@ -65,10 +65,10 @@ void init_mic(void){
PORTB &= ~(1 << PORTB2);//and to GND PORTB &= ~(1 << PORTB2);//and to GND
ADMUX = (1<<REFS1) | (1<<REFS0); //use internal 1.1V as reference ADMUX = (1<<REFS1) | (1<<REFS0); //use internal 1.1V as reference
ADCSRA = (1<<ADPS1) | (1<<ADPS0);// prescaler F_CPU/8 ADCSRA = (1<<ADPS1) | (1<<ADPS0);// prescaler F_CPU/8
ADCSRA |= (1<<ADEN); // ADC enable - turn it on ADCSRA |= (1<<ADEN) | (1<<ADATE);// ADC enable - turn it on in free running mode
// do one conversion ADCSRB &= (1<<ACME); //leave only ACME as it is (others zerp for free running)
ADCSRA |= (1<<ADSC); ADMUX = (ADMUX & ~(0x1F)) | 5; // select channel 5
while (ADCSRA & (1<<ADSC) ) {} //wait for conversion to end ADCSRA |= (1<<ADSC); // start conversion
uint16_t dummy = ADCW; //read once uint16_t dummy = ADCW; //read once
return; return;
} }

View File

@ -71,7 +71,6 @@ void do_mode0(void){
// single measurement // single measurement
ADMUX = (ADMUX & ~(0x1F)) | 5; // select channel 5 ADMUX = (ADMUX & ~(0x1F)) | 5; // select channel 5
ADCSRA |= (1<<ADSC); // start single conversion ADCSRA |= (1<<ADSC); // start single conversion
while (ADCSRA & (1<<ADSC) ) {}; // wait for conversion to end
curval =ADCW; // read result curval =ADCW; // read result
maxval = (curval>maxval) ? curval : maxval; maxval = (curval>maxval) ? curval : maxval;