Go Down

Topic: Stack overflow (Read 1 time) previous topic - next topic

DuaneB

Hi,

How is a stack overflow visible in a project ? Does it reset the Arduino or is there a specific interrupt that gets triggered or do you just find out through unexpected behavior ?

Thanks

Duane B

rcarduino.blogspot.com
Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

Grumpy_Mike

Quote
do you just find out through unexpected behavior ?

That's the one.

DuaneB

Thanks,

I have just made a few changes that should be good for 30 or 40 bytes, I am running on an 1K ATMega8 and the project is behaving as if a global variable is being overwritten with zero after a period.

Duane.

Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

AWOL

Quote
or is there a specific interrupt that gets triggered

You mean some sort of mechanism that pushes the machine's current state and registers onto the stack?   ;)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

DuaneB

Quote
You mean some sort of mechanism that pushes the machine's current state and registers onto the stack?


Now that you mention it - :smiley-red:

Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

electricteardown

You might be able to see it occur if you run the hex file in a simulator like AVR Studio 4, I show it happening here:

http://www.youtube.com/watch?v=bCl4-eBn4SM

Nick Gammon


You mean some sort of mechanism that pushes the machine's current state and registers onto the stack?   ;)


Very amusing. :)

The stack that is no more?
http://www.gammon.com.au/electronics

majenko

Some more advanced microcontrollers do have a system for handling this.  It's just like an interrupt, but it's called an "exception".   They are more critical than interrupts, and you aren't always expected to be able to return from it.  They are usually linked to such events as "address error", or "divide by 0" and other such critical events.

Not something the low-end Atmel chips do I'm afraid.
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

AWOL

My favourite was the 68000 double bus error.
A single bus error caused the processor to jump via a vector when an area of memory that wasn't mapped was accessed.
A double bus error occurred when the bus error vector pointed to a region of memory that wasn't mapped!
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Nick Gammon


How is a stack overflow visible in a project ?


The Blue Screen Of Death.

Oh, wait. There isn't a screen.
http://www.gammon.com.au/electronics

majenko


My favourite was the 68000 double bus error.
A single bus error caused the processor to jump via a vector when an area of memory that wasn't mapped was accessed.
A double bus error occurred when the bus error vector pointed to a region of memory that wasn't mapped!

I'm sure my guru meditated on that problem many a time :)
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

DuaneB

Just out of interest - I am not near an AVR now, what does it do for divide by zero ?

Duane B
Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

AWOL

Divide by zero?
Nothing at all.
Carries on, regardless.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

James C4S


Just out of interest - I am not near an AVR now, what does it do for divide by zero ?


Code: [Select]
void setup() {
Serial.begin(9600);
unsigned int numerator = 47;
unsigned int denominator = 0;
unsigned int result = numerator / denominator;

Serial.print("Int: ");
Serial.println(result);
float floatNumerator = 47.0;
float floatDenominator = 0.0;
float floatResult = floatNumerator / floatDenominator;
Serial.print("Float: ");
Serial.println(floatResult);
}


Resulted in:
Code: [Select]

Int: 65535
Float: 0.00
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Grumpy_Mike

Divide by zero is a concept that we have, to the computer it is just another operation. Sometimes we build the "this is a bad thing" concept into the processor, other times into the software, but the processor dosn't cair.

Go Up