I'm having a very bad reset issue and I think it may have to do with my ISR. I use AT90USB646, 16MHz, AVR Studio 4.17. I am using a structure I called filter to do all my software filtering and I have all the filtering within the ISR. I am not sure if this is causing the reset in my ISR. But here is what I have now. BTW, the one reason why I deduced my problem to be the ISR is my AVR does not reset whenever I comment sei() in my main code.
[size=12pt]
int main(void)
{
hardware(0); //initialize all hardware
on; //turn on power led
calibrate(); //calibrate sensors
behavior_Init(); //initialize behavior structures
//LCD_INIT(); //initialize LCD
//LCD_COMMAND(LCD_CLEAR_HOME); // Clear LCD screen, send cursor to start
//sprintf(out,"test"); //lcd test print
//LCD_STRING(out); //print out
//_delay_ms(1000); //power up delay
ADCSRA |= (1<<ADSC); //start conversion
//sei(); //enable global interrupts
while(1)
{
// LCD_COMMAND(LCD_CLEAR_HOME); // Clear LCD screen, send cursor to start
// sprintf(out,"%d %d", straight.priority, winner.priority);
// LCD_STRING(out);
// LCD_ADDR(0x40); // Send cursor to address 0x40 (second row)
// LCD_STRING("str8t, wnr"); // Write "ATMEL Lecture" to LCD
//_delay_ms(50);
arbitrate(); //arbitrate behaviors
LeftMotor(winner.motorLeft, winner.movespeed); //set left motor parameters
RiteMotor(winner.motorRight, winner.movespeed);//set right motor parameters
}
}
ISR(ADC_vect)
{
//read value into sensor index Amux, array input filtIndex
sensor[Amux].input[sensor[Amux].index] = ADCW;
//do filter
//subtract oldest from sum and add newest
sensor[Amux].sum = sensor[Amux].sum - sensor[Amux].oldest + sensor[Amux].input[sensor[Amux].index];
sensor[Amux].output = sensor[Amux].sum >> FILTPOWER;
sensor[Amux].index++; //increment index when all analog inputs are filled
if(filtIndex > 15) sensor[Amux].index = 0;
sensor[Amux].oldest = sensor[Amux].input[sensor[Amux].index];
//prepare indices for subsequent reading
Amux++; //increment mux counter
if(Amux>7) Amux=1; //reset counter when 8
ADMUX &=~0x0f; //clear ADC control reg mux bits
ADMUX |= (Amux<<MUX0); //set adc control mux to next channel
ADCSRA |= (1<<ADSC); //start conversion
}[/size]
ADC ISR causing reset?
[/size]