Hi,
I am having some issues with a program using the ADC - I would greatly appreciate comments by anyone who has encountered something similar before!
The system is an AtMega 128 at 16Mhz with the UART0, ADC and Timer1 running. The timer 1 interrupt triggers every 5000 cycles (every 132.5uS) and triggers the ADC (3200sps). Within the timer interrupt I am incrementing a counter and checking how many ticks have passed since the last counter reset depending on which I change the "state" of the code (a virtual state machine). The ADC interrupt checks the state and writes to a different location depending on the state. Outside the interrupts the main is stuck in an infintie loop where according to the state some relays are switched on and others are switched off. The UART is running with interrupt-driven code that takes data from a circular buffer which is filled as appropriate by the main.
The strange behaviour is that the ADC always keeps giving the same value, namely the value of the first reading it takes. For example, if the first ADC reading is 410 (and the first reading corresponds correctly to the voltage input) all further readings are 410, even when I change the voltage on the input pin. I have observed this voltage both using JTAG debug and by dumping data out through the UART. My first suspicion was on damaged ADC hardware (for a moment I had driven the input above the supply voltage) but I swapped the processor with a known good one and the issue remained. Also using a hex file from an old project the ADC worked normally and updates the value.
ISR(ADC_vect) // { cli(); if (machine==state1) { accumulator1 += ((ADCH<<8)+ADCL); } if ((machine==state2)||(machine==state3)) { //Subtract old "end of buffer" accumulator2 -= temp_array[temp_array_pointer]; //Get ADC value and write in old "end" / new "start" muqqu = ((ADCH<<8)+ADCL); //"muqqu" variable exists only for watch temp_array[temp_array_pointer] = muqqu; //Add new "start" accumulator2 += temp_array[temp_array_pointer]; //Increment pointer and if the top is reached wrap around temp_array_pointer++; if (temp_array_pointer>=64) { temp_array_pointer = 0; } } sei(); }
Any ideas?
N