Pages: [1] 2   Go Down
Author Topic: Reset arduino with code  (Read 44764 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Brunsbüttel, SH, F.Rep.GERM
Offline Offline
God Member
*****
Karma: 4
Posts: 596
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: May 06, 2010, 10:27:27 am by RIDDICK » Logged

-Arne

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Brunsbüttel, SH, F.Rep.GERM
Offline Offline
God Member
*****
Karma: 4
Posts: 596
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

ohoh

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

what does ATMEL recommend?

-arne
Logged

-Arne

Boston, MA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1024
wiblocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


0
Offline Offline
Faraday Member
**
Karma: 24
Posts: 3501
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Udo

Logged

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How do you do that? With code?
Logged

Boston, MA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1024
wiblocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what is the watchdog?
i Am a noob a don't know anything of the more complex avr functions
« Last Edit: May 06, 2010, 03:06:01 pm by lalle_calle » Logged

Boston, MA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1024
wiblocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 *)
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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");  
}  
« Last Edit: May 06, 2010, 03:25:30 pm by lalle_calle » Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Melbourne, Fla, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 22
MAKE + Arduino = ROCK!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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]


Logged

0
Offline Offline
Faraday Member
**
Karma: 24
Posts: 3501
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-wink

Udo

Logged

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

Melbourne, Fla, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 22
MAKE + Arduino = ROCK!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can still check the box next to beginner  smiley-grin

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

Pages: [1] 2   Go Up
Jump to: