X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=bike-lights.git;a=blobdiff_plain;f=firmware%2Fadc.c;h=5ebc0a6d0d6076d224c594441773298ff48d6939;hp=9ed80f2d216b069412a2a12a53444c048d8a57eb;hb=b34429defa04d493a49e24ad8840e42600bd0f28;hpb=d52307e8b0b0b1113ba928e19ffa91340d037eda diff --git a/firmware/adc.c b/firmware/adc.c index 9ed80f2..5ebc0a6 100644 --- a/firmware/adc.c +++ b/firmware/adc.c @@ -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);