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=194b00e0b0de070d3ab0369b287560df8f93f37a;hb=8b54d4bdf1305a636d6c1d03e6a725061f47c612;hp=2bd4bfff81804ad3ad00d87fb790ea7c1f9da269;hpb=b02a7f779bb5da598bab17456d0afda65adc863b;p=tinyboard.git diff --git a/projects/step-up/adc.c b/projects/step-up/adc.c index 2bd4bff..194b00e 100644 --- a/projects/step-up/adc.c +++ b/projects/step-up/adc.c @@ -1,5 +1,6 @@ #include #include +#include #include #include "lights.h" @@ -11,6 +12,7 @@ volatile static unsigned char current_adc, current_slow_adc; static uint16_t adc_sum, read_zero, drop_count, read_count, n_reads_log; +volatile uint16_t jiffies; static void setup_mux(unsigned char n) { @@ -105,6 +107,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 @@ -142,12 +147,18 @@ static void adc1_gain20_adc(uint16_t adcsum) static void inline adc_based_timer() { - static uint16_t pattern_counter; + static unsigned char count; + + if (++count < 40) // about 100 Hz jiffies + return; + + count = 0; + ++jiffies; - if (++pattern_counter > 250) { - pattern_counter = 0; + if ((jiffies & 0x0007) == 0) { patterns_next_tick(); } + timer_check_buttons(); } ISR(ADC_vect) { // IRQ handler