]> www.fi.muni.cz Git - bike-lights.git/blobdiff - firmware/adc.c
Timer-initiated ADC
[bike-lights.git] / firmware / adc.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).