NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Undefined Interupt and Tips how to debug them....

November 20, 2012
by fishberg5051
fishberg5051's Avatar

Hi everyone,

I am attempting to use an interupt in my code, and when I enable the interupts with the sei(); and cli(); functions, my chip keeps resetting and starts over from main().

Reading elsewhere someone suggested that an interupt was undefined and my overall question is if there are any tips or tricks on determine which one is not defined? I have access to a jtag ice debugger but no idea what to look for.

Overall I'm attempting to get the input voltage to have a more accurate temperature sensor vs hardcoding the input voltage value.

It should also be mentioned I'm using a 1284P, and I understand it may be difficult to offer suggestions based on the examples I provided but it's worth a shot.

some code examples I'm attempting is:

sei();
setup_adc();

void setup_adc(void)
{
ADMUX = 0xE; //set the band gap voltage as the ADC input
ADCSRA = (1<<ADEN) | (1<<ADATE) | (1<<ADIE) | (1<<ADSC) | 5;
//ADMUX |= (1 << ADLAR) | (1 << REFS0); // left adj. and AVcc as reference
//ADCSRA = (1 << ADEN) | (1 << ADIE) | (1 << ADPS2); // Enable ADC, interrupt, prescaler 16

}

ISR(__vector_default){
PORTD |= (1<<PD6);

//delay for 1000 milliseconds to let the light stay on
delay_ms(1000);

// turn off LED
PORTD &= ~(1<<PD6);
}

ISR(ADC_vect) //ADC End of conversion interupt
{
unsigned char adc_data;
adc_data = ADC>>2; //read 8 bit value
if(adc_data > 0)
    vcc = 1.1 * 255 / adc_data;
else
    vcc = 1;
}

So overall what is happening when I debug is the ADC_vect fires once, but then the __vector_default continuously fires for the board has become reset at this point and hits the sei(); and setup_adc(); functions over and over and over and over again.

Any ideas are welcome, and thank you for your time.

November 20, 2012
by Noter
Noter's Avatar

Could it be a power problem and the brown-out detector is causing the reset?

The only way I know to find an unknown software interrupt is to setup the EMPTY_INTERRUPT(vector) for each vector, one at a time, and compile/run. As soon as you don't reset then that's the one. You can find all the vectors in iom1284p.h and perhaps start by setting EMPTY_INTERRUPT on all vectors and if you still reset then it's not an unexpected interrupt that's causing it.

November 20, 2012
by BobaMosfet
BobaMosfet's Avatar

fishberg5051-

The problem is that you are doing a delay within your ISR. Don't. Ever.

BM

Post a Reply

Please log in to post a reply.

Did you know that you can make a capacitive proximity sensor with some aluminum foil and paperclips? Learn more...