From b34429defa04d493a49e24ad8840e42600bd0f28 Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Tue, 2 Jul 2013 12:03:19 +0200 Subject: [PATCH] adc.c: abort the current reading when the timer expires 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 | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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); -- 2.39.3