Don't ever divide by zero on AVR atmega32!

Embedded Systems Topics
Post Reply
PraveenAlexis
Moderator
Moderator
Posts: 78
Joined: Wed Jul 20, 2011 3:06 pm
Location: Sri lanka,Wattala

Don't ever divide by zero on AVR atmega32!

Post by PraveenAlexis » Sat Sep 10, 2011 8:19 am

[media]http://www.youtube.com/watch?v=mZ7pUADo ... r_embedded[/media]
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Don't ever divide by zero on AVR atmega32!

Post by Neo » Sat Sep 10, 2011 10:53 am

The reason I think is that the microcontroller becomes uncontrollable after such illegal operation that will lead to unexpected behaviours such as ON/OFF pins, Input/Output state of ports, etc... Just imagine a Port (or a Pin) which was configured to work as an input, become an output as a result of an illegal operation. Usually after such illegal operation, your code no longer has control over the microcontroller. When you become a professional in programming, you will easily identify the possible lines of code which can lead to an illegal operation.

Stack Overflow is another tricky problem. Stack is used for many things. More importantly to backup registers at the time of procedure call. After the call is done, registers are restored so that the calling function can continue from it's last state. When you call lots of functions within a single function (good example is recursion), then the requirement for stack become high. However Stack is a hardware implementation so it is limited mostly to a specific amount of memory. So calling lots of functions will make the CPU to go Stack Overflow which will make the CPU uncontrollable.

So it is not only Atmel, all other processors also have a chance to blow off with these illegal operations (mostly due to the way you wired it).

Here is an example: Don't ever allow to stack overflow on AVR Atmega88V.
[media]http://www.youtube.com/watch?v=4YEL7Jx26Wk[/media]
Post Reply

Return to “Embedded Systems”