X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=projects%2Fstep-up%2Fadc.c;h=fc4c7caac3a201b3526c2f5a4908aabc24c5f67b;hb=37d45fd92b03b610195d7d6227140672ccc17b2b;hp=d7679d30b09cff20d7038629cca4d334b8a04b06;hpb=d024b5fce4c9465b99e1f666bb7d3ca4c0706f08;p=tinyboard.git diff --git a/projects/step-up/adc.c b/projects/step-up/adc.c index d7679d3..fc4c7ca 100644 --- a/projects/step-up/adc.c +++ b/projects/step-up/adc.c @@ -1,5 +1,6 @@ #include #include +#include #include #include "lights.h" @@ -105,6 +106,9 @@ void init_adc() current_slow_adc = NUM_ADCS; current_adc = 0; + power_adc_enable(); + ACSR |= _BV(ACD); // but disable the analog comparator + ADCSRA = _BV(ADEN) // enable | _BV(ADPS1) | _BV(ADPS0) // CLK/8 = 125 kHz // | _BV(ADPS2) // CLK/16 = 62.5 kHz @@ -140,9 +144,21 @@ static void adc1_gain20_adc(uint16_t adcsum) } #endif +static void inline adc_based_timer() +{ + static uint16_t pattern_counter; + + if (++pattern_counter > 250) { + pattern_counter = 0; + patterns_next_tick(); + } +} + ISR(ADC_vect) { // IRQ handler uint16_t adcval = ADCW; + adc_based_timer(); + if (read_zero) { setup_mux(current_adc); read_zero = 0;