]> www.fi.muni.cz Git - bike-lights.git/commitdiff
adc: always-running ADC
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 30 Nov 2012 10:23:27 +0000 (11:23 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 30 Nov 2012 10:23:27 +0000 (11:23 +0100)
Don't rely on the timer IRQ to start next round of ADC measurements,
start it immediately after the previous one finishes.

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

index fa0782c4248c6ee67917901cc1340dedfefea087..b7dad0ad59b31a940acecec248c91fd14ba8b2aa 100644 (file)
@@ -51,15 +51,15 @@ static void inline setup_mux(unsigned char n)
 
 static void start_next_adc()
 {
-       if (current_adc > 0) {
+       if (current_adc > 0)
                current_adc--;
-               // set up mux, start one-shot conversion
-               setup_mux(current_adc);
-               ADCSRA |= _BV(ADSC);
-       } else {
-               current_adc = NUM_ADCS;
+       else
                // TODO: kick the watchdog here.
-       }
+               current_adc = NUM_ADCS-1;
+
+       // set up mux, start one-shot conversion
+       setup_mux(current_adc);
+       ADCSRA |= _BV(ADSC);
 }
 
 void init_adc()
@@ -100,6 +100,8 @@ void init_adc()
        }
 
        ADCSRA |= _BV(ADIE); // enable IRQ
+
+       start_next_adc();
 }
 
 void susp_adc()
@@ -151,13 +153,3 @@ ISR(ADC_vect) { // IRQ handler
        start_next_adc();
 }
 
-void timer_start_adcs()
-{
-       if (current_adc == NUM_ADCS) // Don't start if in progress
-               start_next_adc();
-#if 0
-       else
-               log_byte(0x99);
-#endif
-}
-
index e525bfd2cc0c99f5e59fd6abd4e877a38facdb36..81871421a2bf322f4f3e13bd0a3632d24119bad4 100644 (file)
@@ -25,7 +25,6 @@ void inline log_word(uint16_t word) { }
 /* adc.c */
 void init_adc();
 void susp_adc();
-void timer_start_adcs();
 
 /* pwm.c */
 #define PWM_MAX 0x1E4 /* This should be different than ADC frequency 125 kHz */
index 37b240b5d65245898722036d00f740ad322b1350..f0d7d9350f59abb301bf131c54414d6ffb44028b 100644 (file)
@@ -36,7 +36,5 @@ ISR(TIMER0_COMPA_vect)
                patterns_next_tick();
                pattern_div = PATTERN_DIV;
        }
-
-       timer_start_adcs();
 }