]> www.fi.muni.cz Git - bike-lights.git/commitdiff
Timer-initiated ADC
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Thu, 28 Mar 2013 18:48:01 +0000 (19:48 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Thu, 28 Mar 2013 18:48:01 +0000 (19:48 +0100)
Run ADC synchronously with timer IRQ. This partially reverts
commit 210916486d18b3dc976c65c7b01b44bca446d856 in order to
prepare for selectively enabling and disabling ADC channels.

firmware/adc.c
firmware/lights.h
firmware/tmr.c

index 02af6b380724ae6f92ccca9407d1e1951a75c53f..f55a42792570670e464c1e66d035b809b6ecc298 100644 (file)
@@ -65,11 +65,13 @@ static void setup_mux(unsigned char n)
 
 static void start_next_adc()
 {
-       if (current_adc > 0)
+       if (current_adc > 0) {
                current_adc--;
-       else
+       } else {
                // TODO: kick the watchdog here.
-               current_adc = NUM_ADCS-1;
+               current_adc = NUM_ADCS;
+               return;
+       }
 
        adc_sum = 0;
        // we use the last iteration of zero_count to set up the MUX
@@ -96,6 +98,14 @@ static void start_next_adc()
        ADCSRA |= _BV(ADSC);
 }
 
+void timer_start_adcs()
+{
+       if (current_adc == NUM_ADCS) // Don't start if in progress
+               start_next_adc();
+       else
+               log_byte(0x99); // overrun
+}
+
 /*
  * Single synchronous ADC conversion.
  * Has to be called with IRQs disabled (or with the ADC IRQ disabled).
index 8fce475ace0f77de596ae7539ffa3fdae9fa04b0..2eb1f09f41464c4e02ae2f6ef29b5dd5eae4dcc3 100644 (file)
@@ -28,6 +28,7 @@ void inline log_word(uint16_t word) { }
 #define PWMLED_ADC_SHIFT 3 /* 1<<3 measurements per single callback */
 void init_adc();
 void susp_adc();
+void timer_start_adcs();
 
 /* pwm.c */
 /*
index f0d7d9350f59abb301bf131c54414d6ffb44028b..37b240b5d65245898722036d00f740ad322b1350 100644 (file)
@@ -36,5 +36,7 @@ ISR(TIMER0_COMPA_vect)
                patterns_next_tick();
                pattern_div = PATTERN_DIV;
        }
+
+       timer_start_adcs();
 }