]> www.fi.muni.cz Git - bike-lights.git/commitdiff
adc.c: abort the current reading when the timer expires
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Tue, 2 Jul 2013 10:03:19 +0000 (12:03 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Tue, 2 Jul 2013 10:06:00 +0000 (12:06 +0200)
Inside the timer interrupt, we may have changed the PWM outputs,
so the reading of ADC will be useless. Drop it in this case.

FIXME: possible race condition against timer IRQ.

firmware/adc.c

index 9ed80f2d216b069412a2a12a53444c048d8a57eb..5ebc0a6d0d6076d224c594441773298ff48d6939 100644 (file)
@@ -204,6 +204,18 @@ static void adc1_gain20_adc(uint16_t adcsum)
 ISR(ADC_vect) { // IRQ handler
        uint16_t adcval = ADCW;
 
+       /*
+        * After the timer interrupt, drop the current reading.
+        * We may have changed the PWM outputs, so the value is
+        * probably useless anyway.
+        * FIXME: possible race condition - we should make an explicit
+        * notification inside the timer IRQ handler.
+        */
+       if (slow_adcs_wanted) {
+               start_next_adc();
+               return;
+       }
+
        if (zero_count) {
                if (zero_count > 1) {
                        ADCSRA |= _BV(ADSC);