]> www.fi.muni.cz Git - bike-lights.git/commitdiff
ambient light: make three measurements
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Sun, 16 Dec 2012 16:29:53 +0000 (17:29 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Sun, 16 Dec 2012 16:29:53 +0000 (17:29 +0100)
firmware/adc.c
firmware/ambient.c

index f5d846f2b21d0340bd8f3411a1d214db5ae04583..4213ef56bc01b5114ee2c76f6ef16dfce1e7158d 100644 (file)
@@ -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);
        
index c6c6a654ab67e1bd974366feefd575e98af95f55..735f80e968a940c7a77dc210bb73d07c0ee16ace 100644 (file)
@@ -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--;