#include #include #include uint8_t adc_use; volatile uint8_t channel; uint16_t an_value [8]; unsigned char an_changed; unsigned char read_cycle; uint8_t temp; //Tried a read_cycle with ADATE (freerunning triger) but you get problems with //the channels because as soon the interrupt is executed another adc cycle is started // so the current channel is from two interupts old ISR(SIG_ADC) { channel++; if(an_value[channel - 1] != ADC) { an_value[channel - 1] = ADC; //10 bit conversion an_changed |= (1 << (channel - 1)); } else { an_changed &= ~(1 << (channel - 1)); } //only measure the channels that are in use. while(channel < 8) { temp = 0x01 & (adc_use >> channel); if(temp) { break; } channel++; } if (channel > 7) { channel = 0; read_cycle = 0; } ADMUX = (1 << REFS0) | channel; //start a new measurement if(read_cycle == 1) { ADCSRA |= (1 << ADSC); } } void adc_init(uint8_t adc_use_local) { adc_use = adc_use_local; DIDR0 = adc_use; ADCSRA = (1 << ADEN) | (1 << ADIE) | (1 << ADPS2) | (1 << ADPS1) | (ADPS0); //200khz neccesary for 10 bit conversion ADCSRB = 0; ADMUX = (1 << REFS0); } void adc_read(void) { //find first ad channel that is true while(channel < 8) { temp = 0x01 & (adc_use >> channel); if(temp) { break; } channel++; } ADMUX = (1 << REFS0) | channel; ADCSRA |= (1 << ADSC); read_cycle = 1; } /*filter function exa. 10 point average filter void adc_read_filter(void) { } */