Go Down

Topic: Reset arduino with code (Read 46 times) previous topic - next topic

calle_o

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

RIDDICK

#1
May 06, 2010, 05:06 pm Last Edit: May 06, 2010, 05:27 pm by RIDDICK Reason: 1
1.
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

2.
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)...

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

-arne
-Arne

retrolefty

Quote
2.
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

RIDDICK

ohoh

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

what does ATMEL recommend?

-arne
-Arne

jluciani

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
www: http://www.wiblocks.com
twitter: http://twitter.com/wiblocks

Udo Klein

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

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

Udo

Check out my experiments http://blog.blinkenlight.net

calle_o

How do you do that? With code?

jluciani

Quote
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
www: http://www.wiblocks.com
twitter: http://twitter.com/wiblocks

calle_o

#8
May 06, 2010, 10:05 pm Last Edit: May 06, 2010, 10:06 pm by lalle_calle Reason: 1
what is the watchdog?
i Am a noob a don't know anything of the more complex avr functions

jluciani

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 *)
www: http://www.wiblocks.com
twitter: http://twitter.com/wiblocks

calle_o

#10
May 06, 2010, 10:18 pm Last Edit: May 06, 2010, 10:25 pm by lalle_calle Reason: 1
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:
Code: [Select]

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");  
}  

retrolefty

Quote
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

Volkemon

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:

Code: [Select]
void (softReset){
asm volatile ("  jmp 0");
}


Then, at the point in my sketch I wanted to have the reset happen, I added the code:
Code: [Select]
softReset();

Hope this helps others seeking the same result.

Quote
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.

[glow]Thanks!!!!!!!![/glow]



Udo Klein

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 ;)

Udo

Check out my experiments http://blog.blinkenlight.net

Volkemon

I can still check the box next to beginner  :D

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

Go Up