Software > Software

ADC ISR causing reset?

(1/2) > >>

dual:
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.


--- 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]

--- End code ---


ADC ISR causing reset?
[/size]

waltr:
Do you have an ISR (interrupt service routine)? If not then when an interrupt happens it goes back to the beginning of your code and looks like a reset.

dual:
yeah, it's in the code that I posted. I have seen it work too when I used to not have the filtering within the ISR itself

airman00:
Your ISR looks way too long.

Have you ISR only have the read and set to a variable(remember to declare it as volatile). Your main code should have all the ifs and thens. Perhaps set the variable to 0 after doing the filter algorithm thing, so that after each ISR is done( the variable would obviously be > 0 in the ADC ISR), the code knows when to apply the filter.

--- Code: ---volatile int variable=0;

while(1){

while(variable !=  0) {
// DO FILTER STUFF
variable = 0;  // clear variable
}

// DO MOTOR STUFF
}


ISR(ADC_vect) {
variable = Analog_Read();  // or whatever the function to read analog is.
}


--- End code ---

rgcustodio:
I think the length of the interrupt handling function doesn't matter. The only effect it will have is that other interrupts will be missed while the interrupt handler is running!

sei() enables interrupts from being seen by the processor. If you don't call it your processor will not see any interrupts and thus your interrupt handler will not be called. Not sure if the AVRs need to call sei() on startup. Check your processor's documentation.

Other things to consider:
1) interrupt handler registration. Are you registering your interrupt handler properly?
2) variables accessed in the interrupt handler. Are they all properly initialized? Some might be uninitialized causing invalid memory access. This might be way of the system of handling invalid memory access inside an interrupt, to reset the system.
3) did you disable the interrupts (cli()) when one interrupt is already running??

Regards,

Navigation

[0] Message Index

[#] Next page

Go to full version