From: Jan "Yenya" Kasprzak Date: Sun, 16 Dec 2012 16:29:53 +0000 (+0100) Subject: ambient light: make three measurements X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=bike-lights.git;a=commitdiff_plain;h=dd1738d1117607d5a47050274d805748b11f48d1 ambient light: make three measurements --- diff --git a/firmware/adc.c b/firmware/adc.c index f5d846f..4213ef5 100644 --- a/firmware/adc.c +++ b/firmware/adc.c @@ -33,7 +33,7 @@ static void inline setup_mux(unsigned char n) break; case 3: // ambient light: 1.1V, ADC5 (PA6), single-ended ADMUX = _BV(REFS1) | _BV(MUX2) | _BV(MUX0); - sum_shift = 0; // 1 measurement + sum_shift = 3; // 3 measurements break; case 4: // batt voltage: 1.1V, ADC6 (PA7), single-ended ADMUX = _BV(REFS1) | _BV(MUX2) | _BV(MUX1); @@ -146,7 +146,7 @@ ISR(ADC_vect) { // IRQ handler if (current_adc < N_PWMLEDS) pwmled_adc(current_adc, adc_sum); if (current_adc == AMBIENT_ADC) - ambient_adc(adcval); + ambient_adc(adc_sum); if (current_adc == BATTERY_ADC) battery_adc(adcval); diff --git a/firmware/ambient.c b/firmware/ambient.c index c6c6a65..735f80e 100644 --- a/firmware/ambient.c +++ b/firmware/ambient.c @@ -15,8 +15,8 @@ typedef struct { * and having small overlaps in order to provide a bit of hysteresis. */ static ambient_zone_t ambient_zones[] = { - { 0x0000, 0x3120 }, // dark - { 0x30f0, 0x5000 }, + { 0x0000, 0x3400 }, // dark + { 0x3300, 0x5000 }, { 0x4c00, 0x8000 }, { 0x7800, 0xffff } }; @@ -46,7 +46,7 @@ void ambient_adc(uint16_t adcval) { unsigned char old_zone = ambient_zone; - ambient_val += adcval - (ambient_val >> 6); + ambient_val += adcval - (ambient_val >> 3); while (ambient_zones[ambient_zone].lo > ambient_val) ambient_zone--;