From: Jan "Yenya" Kasprzak Date: Fri, 14 Sep 2012 20:32:02 +0000 (+0200) Subject: adc setting according to new pins.txt X-Git-Tag: gerber-fab-20121029-1711~39 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=990989cb746d45fbd2ebf634c6e7c19ce0cfe2df;p=bike-lights.git adc setting according to new pins.txt --- diff --git a/firmware/adc.c b/firmware/adc.c index dc35d6b..5252ae7 100644 --- a/firmware/adc.c +++ b/firmware/adc.c @@ -5,16 +5,18 @@ /* ADC numbering: PWM LEDs first, then ambient light sensor, battery sensor */ static unsigned char adc_mux[] = { // pwmleds should be first - // 0: pwmled 0: 1.1V, ADC3 (PA4), single-ended - _BV(REFS1) | _BV(MUX1) | _BV(MUX0), - // 1: pwmled 1: 1.1V, ADC0,1 (PA0,1), gain 1 or 8 - _BV(REFS1) | _BV(MUX3) | _BV(MUX2), - // 2: pwmled 2: 1.1V, ADC2,1 (PA2,1), gain 20 or 32 + // 0: pwmled 1: 1.1V, ADC0,1 (PA0,1), gain 20 + _BV(REFS1) | _BV(MUX3) | _BV(MUX1) | _BV(MUX0), + // 1: pwmled 2: 1.1V, ADC2,1 (PA2,1), gain 20 _BV(REFS1) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1), - // 3: ambient light: 1.1V, ADC4 (PA5), single-ended - _BV(REFS1) | _BV(MUX2), - // 4: batt voltage: 1.1V, ADC5 (PA6), single-ended + // 2: pwmled 3: 1.1V, ADC4 (PA5), single-ended + // _BV(REFS1) | _BV(MUX2), + // 2: for testing the same as 1 + _BV(REFS1) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1), + // 3: ambient light: 1.1V, ADC5 (PA6), single-ended _BV(REFS1) | _BV(MUX2) | _BV(MUX0), + // 4: batt voltage: 1.1V, ADC6 (PA7), single-ended + _BV(REFS1) | _BV(MUX2) | _BV(MUX1), }; #define AMBIENT_ADC N_PWMLEDS @@ -39,9 +41,9 @@ static void start_next_adc() // all ADCs have been handled current_adc = LAST_ADC; + // TODO: kick the watchdog here. return; found: - // ADCSRB |= _BV(GSEL); // gain 8 or 32 ADMUX = adc_mux[current_adc]; // set up mux, start one-shot conversion adc_ignore = 1; // ignore first reading after mux change ADCSRA |= _BV(ADSC); @@ -56,11 +58,11 @@ void init_adc() | _BV(ADPS1) | _BV(ADPS0) // CLK/8 = 125 kHz // | _BV(ADPS2) // CLK/16 = 62.5 kHz ; - ADCSRB |= _BV(GSEL); // gain 8 or 32 + // ADCSRB |= _BV(GSEL); // gain 8 or 32 // Disable digital input on all bits used by ADC - DIDR0 = _BV(ADC0D) | _BV(ADC1D) | _BV(ADC2D) | _BV(ADC3D) - | _BV(ADC4D) | _BV(ADC5D); + DIDR0 = _BV(ADC0D) | _BV(ADC1D) | _BV(ADC2D) + | _BV(ADC4D) | _BV(ADC5D) | _BV(ADC6D); ADCSRA |= _BV(ADSC);