Reset arduino with code

I would like to reset my arduino every 30 min or so. So that Micros never roll over. Is there a reset function?

unsigned integer math is immune to a single overflow:
example with 8 bit (uint8_t):
last time stamp: 253
current time stamp: 5
difference: 5-253 = -248 modulo 256 = 8

u could connect an IO pin X to the reset pin via a 1kR resistor...
if that IO pin X is INPUT/LOW no reset is triggered (like the reset button is unpressed)...
if that IO pin X is OUTPUT/LOW a reset is triggered (like the reset button is pressed)...

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1246541553

-arne

u could connect an IO pin X to the reset pin...
if that IO pin X is INPUT/LOW no reset is triggered (like the reset button is unpressed)...
if that IO pin X is OUTPUT/LOW a reset is triggered (like the reset button is pressed)...

I've read in a AVR datasheet that this method is not recommended as it has fundemental flaws. One of the first things the reset cycle does is set all I/O pins to inputs, therefore removing the reset signal too quickly for a complete reset cycle. If ATMEL says don't try to do it this way, then it probably is a poor choice.

Lefty

ohoh

that watchdog trick seems to be risky, 2...

what does ATMEL recommend?

-arne

The watchdog reset works. I have used it to do wireless software
updates using an XBee. Sending the string "RESET" triggered
the reset. IIRC I had to modify the bootloader.

In one of the Atmel app-notes enabled/disabling that watchdog
is discussed. My software-reset FAQ is at --
http://wiblocks.luciani.org/FAQ/faq-software-reset.html

(* jcl *)


www: http://www.wiblocks.com
twitter: http://twitter.com/wiblocks
blog: http://luciani.org

I would vote for the watchdog as well. Just enable it and wait :slight_smile:

But take care: you have to disable it immediately after the reset or the Arduino will be caught in an endless reset loop.

Udo

How do you do that? With code?

How do you do that? With code?

Yes. Enable the watchdog and then loop.

(* jcl *)


www: http://www.wiblocks.com
twitter: http://twitter.com/wiblocks
blog: http://luciani.org

what is the watchdog?
i Am a noob a don't know anything of the more complex avr functions

A hardware device that is used to reset a uC. The watchdog has a timeout
period. If you do not set a flag before a timeout period has elapsed then the watchdog
will reset the uC and your program will start at the beginning. An automatic
"reboot"

The watchdog can be external or internal to the uC. Maxim, TI, etc make external
watchdog ICs that you connect to the reset pin. The Atmel uCs (and all of the
uCs that I have seen) have internal watchdogs.

(* jcl *)

i found that this worked

void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile (" jmp 0");
}
But i am not shore if the memory gets wiped so it may lead to a buffer overflow.. i shall test my theory.

EDIT: nope it did a clean memory swipe; works for me and it resets the micros function

Here is my testing sketch:

void setup() 
{ 
  Serial.begin(9600); 


} 

char olle[500];

void loop() 
{ 
  Serial.println(olle);
  olle[0] = 'a';
  olle[1] = 'b';
  olle[2] = 'c';
  olle[3] = 'd';
  olle[4] = 'e';
  olle[5] = 'f';
  olle[5] = '\0';
  Serial.println(olle);
 unsigned long ii = micros();
 Serial.println(ii);

 
 delay(2000);
 if(ii>10000)
   software_Reset() ;

} 

void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile ("  jmp 0");  
}

EDIT: nope it did a clean memory swipe; works for me and it resets the micros function

Others that have done it that way have reported that it's not a true reset in that the hardware peripherals are not put into their default condition. Might still work for you in your specific application, but it's not a true reset condition, just a restart of the sketch.

Lefty

Gotta love SEARCH! I needed a way to restart my sketch if a condition was met.

calle_o 's solution worked GREAT for my application. I inserted this code at the end of my sketch:

void (softReset){
asm volatile ("  jmp 0");
}

Then, at the point in my sketch I wanted to have the reset happen, I added the code:

softReset();

Hope this helps others seeking the same result.

Others that have done it that way have reported that it's not a true reset in that the hardware peripherals are not put into their default condition.

I am enough of a noob that I dont fully understand what that means! :-? I think all my hardware peripherals (pushbuttons, serial 4-digit display,MAX6675 thermocouple board and 24LC256) wont need a reset. The 'softReset' is called after I overwrite the 24LC256 memory with zeros to prepare it for the next test.

But it seems to work in my application so far... I will post back if any problems occur.

Thanks!!!!!!!!

1 Like

The problems arise if you take any of the register settings for granted. Since Arduino software will overwrite most of the settings it will work most of the time. That's what you noticed. For beginners this is equivalent to a real reset :wink:

Udo

I can still check the box next to beginner :smiley:

I will now research 'register' and learn some more. Thanks Udo!

Of course, there remains the original question of why it would be preferable to avoid micros rolling over (which can be easily handled anyway) vs. losing many hundreds (if not thousands) of microseconds during a reset.