avr: set up the ADC with bandgap as a reference

This commit is contained in:
Bart Van Der Meerssche 2010-12-29 14:08:20 +01:00
parent 381e235af3
commit d80377ee19
2 changed files with 17 additions and 1 deletions

View File

@ -223,6 +223,18 @@ void setup_pulse_input(void)
EIMSK = (1<<INT0) | (1<<INT1); EIMSK = (1<<INT0) | (1<<INT1);
} }
void setup_adc(void)
{
// disable digital input cicuitry on ADCx pins to reduce leakage current
DIDR0 |= (1<<ADC5D) | (1<<ADC4D) | (1<<ADC3D) | (1<<ADC2D) | (1<<ADC1D) | (1<<ADC0D);
// select VBG as reference for ADC
ADMUX |= (1<<REFS1) | (1<<REFS0);
// ADC prescaler set to 32 => 3686.4kHz / 32 = 115.2kHz (DS p.258)
ADCSRA |= (1<<ADPS2) | (1<<ADPS0);
// enable ADC and start a first ADC conversion
ADCSRA |= (1<<ADEN) | (1<<ADSC);
}
void setup_timer1(void) void setup_timer1(void)
{ {
@ -298,6 +310,7 @@ int main(void)
//PORTD |= (1<<PD5); //PORTD |= (1<<PD5);
setup_datastructs(); setup_datastructs();
setup_adc();
setup_timer1(); setup_timer1();
setup_pulse_input(); setup_pulse_input();
setup_analog_comparator(); setup_analog_comparator();

View File

@ -115,6 +115,9 @@ CSTANDARD = -std=gnu99
# Place -D or -U options here # Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)UL CDEFS = -DF_CPU=$(F_CPU)UL
# Enable debugging mode
#CDEFS += -DDBG=1
# uncomment and adapt these line if you want different UART library buffer size # uncomment and adapt these line if you want different UART library buffer size
CDEFS += -DUART_RX_BUFFER_SIZE=64 CDEFS += -DUART_RX_BUFFER_SIZE=64
CDEFS += -DUART_TX_BUFFER_SIZE=64 CDEFS += -DUART_TX_BUFFER_SIZE=64