Endless loops in embedded programs

Error message

Deprecated function: The each() function is deprecated. This message will be suppressed on further calls in menu_set_active_trail() (line 2405 of /home/minmaro3/domains/scienceprog.com/public_html/winavr/includes/menu.inc).


A series of instructions that are constantly repeated. Also called an "infinite loop," it can be caused by an error in the program or be intentional. For example, a screen demo on continuous replay just keeps repeating itself.

Probably you have noticed that many programs have similar structure like:


int main(void)
int i;
 while(1) //infinite loop or super-loop
 return 0;

Often in embedded program structure you may find endless loops: while(1) {}; Why they are used here and what does it give to embedded programs?

First of all endless loops are used here because there is no any operation system to return to/ So application keeps running until power is removed.

Why it is good to use endless loops:

  • Super-loops are simple to use, because it is easy to build, debug test and maintain;

  • Endless loops are hardware efficients as they require minimal hardware resources;

  • They are highly portable.

But there is other side of using super loops:

  • Super-loops doesn't guarantee accurate timings;

  • Endless loops operate at full microcontroller power and may not be necessary in all applications. They can have big impact on system power consumption.

To avoid unnecessary power consumption, it is good practice to use various sleep modes. All not needed functions should be disabled. Sometimes you may only need microcontroller to wake on some external event like external interrupt, or TWI (I2C) event.

You need to consider all these factors when designing battery driven projects.