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=3fdbe3262f3d6467364cd1a73063abd0d3be75e7;hp=9ed80f2d216b069412a2a12a53444c048d8a57eb;hb=HEAD;hpb=09d91b6d1d9c5c6dd9971d9f16e31f66b9c5474e diff --git a/firmware/adc.c b/firmware/adc.c index 9ed80f2..2bca0cf 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); @@ -226,6 +238,7 @@ ISR(ADC_vect) { // IRQ handler ADCSRA |= _BV(ADSC); adc_sum += adcval; read_count--; + pwm_timer(); return; }