Don't rely on the timer IRQ to start next round of ADC measurements,
start it immediately after the previous one finishes.
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()
}
ADCSRA |= _BV(ADIE); // enable IRQ
+
+ start_next_adc();
}
void susp_adc()
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
-}
-
/* 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 */
patterns_next_tick();
pattern_div = PATTERN_DIV;
}
-
- timer_start_adcs();
}