From: Jan "Yenya" Kasprzak Date: Thu, 28 Mar 2013 18:48:01 +0000 (+0100) Subject: Timer-initiated ADC X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=6193f6a3200efa660bbbe406e317fe7fa0473de0;p=bike-lights.git Timer-initiated ADC Run ADC synchronously with timer IRQ. This partially reverts commit 210916486d18b3dc976c65c7b01b44bca446d856 in order to prepare for selectively enabling and disabling ADC channels. --- diff --git a/firmware/adc.c b/firmware/adc.c index 02af6b3..f55a427 100644 --- a/firmware/adc.c +++ b/firmware/adc.c @@ -65,11 +65,13 @@ static void setup_mux(unsigned char n) static void start_next_adc() { - if (current_adc > 0) + if (current_adc > 0) { current_adc--; - else + } else { // TODO: kick the watchdog here. - current_adc = NUM_ADCS-1; + current_adc = NUM_ADCS; + return; + } adc_sum = 0; // we use the last iteration of zero_count to set up the MUX @@ -96,6 +98,14 @@ static void start_next_adc() ADCSRA |= _BV(ADSC); } +void timer_start_adcs() +{ + if (current_adc == NUM_ADCS) // Don't start if in progress + start_next_adc(); + else + log_byte(0x99); // overrun +} + /* * Single synchronous ADC conversion. * Has to be called with IRQs disabled (or with the ADC IRQ disabled). diff --git a/firmware/lights.h b/firmware/lights.h index 8fce475..2eb1f09 100644 --- a/firmware/lights.h +++ b/firmware/lights.h @@ -28,6 +28,7 @@ void inline log_word(uint16_t word) { } #define PWMLED_ADC_SHIFT 3 /* 1<<3 measurements per single callback */ void init_adc(); void susp_adc(); +void timer_start_adcs(); /* pwm.c */ /* diff --git a/firmware/tmr.c b/firmware/tmr.c index f0d7d93..37b240b 100644 --- a/firmware/tmr.c +++ b/firmware/tmr.c @@ -36,5 +36,7 @@ ISR(TIMER0_COMPA_vect) patterns_next_tick(); pattern_div = PATTERN_DIV; } + + timer_start_adcs(); }