/* Test des Free run mode im ADC ATmega328P, aka Arduino Uno/Micro/Nano */ #define F_CPU 16000000UL #include #include #include #include #include #define ADC_CHANNELS 3 #define ADC_AVERAGE_CNT 4 #define FREERUN volatile uint16_t adc_avg[ADC_CHANNELS]; volatile bool adc_run; // ADC initialisieren void adc_init(void) { ADMUX = (1 << REFS0); // AVcc als Referenz, ADC0 als Eingang ADCSRA = (1 << ADEN) | // ADC einschalten (1 << ADIE) | // Interrupt einschalten #ifdef FREERUN (1 << ADATE) | // Free Running Modus aktivieren #endif (1 << ADPS2); // Prescaler auf 16 sei(); // globale Interrupts aktivieren } // ISR für den ADC-Interrupt ISR(ADC_vect) { static uint8_t channel; static uint16_t adc_accu[ADC_CHANNELS]; static uint8_t avg_cnt; uint8_t i; PINB = (1<= ADC_CHANNELS) { channel = 0; if (++avg_cnt == ADC_AVERAGE_CNT) { avg_cnt = 0; for (i=0; i