Pages: [1] 2   Go Down
Author Topic: Is there a reset function?  (Read 9784 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there a reset function at all ? By reset i mean the same as what the wee button does.

Cheers,
Logged

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe look into using the watchdog reset.

--Phil.
Logged

London, Ontario, Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 90
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I found this snip on the net...

It seems to create a macro function to set the watchdog timer for the near future (30ms) and then simply waits for it.


#include <avr/io.h>
#include <avr/wdt.h>

#define Reset_AVR() wdt_enable(WDTO_30MS); while(1) {}

int main(void)
{
Reset_AVR();
}
Logged

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

Be careful using the watchdog timer as a few members here have managed to get in a situation where they can't then get the boot-loader to function right and therefore can't upload any new sketches. At least that is what I got out of it. The fix was to re-burn the boot-loader I think.

If you have a spare unused output pin, I would just wire it in series with a .1mfd capacitor to the reset pin. That is how the Arduino auto-reset works from the IDE. Set the output pin high when you wish to reset.

Lefty

« Last Edit: March 02, 2009, 01:37:19 am by retrolefty » Logged

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If you have a spare unused output pin, I would just wire it in series with a .1mfd capacitor to the reset pin. That is how the Arduino auto-reset works from the IDE. Set the output pin high when you wish to reset.
But note that hardware-based reset approaches like this seem to be discouraged by Atmel.

--Phil.
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
But note that hardware-based reset approaches like this seem to be discouraged by Atmel.

 That's interesting, I wonder why? The auto-reset that the Arduino uses seems to be pretty reliable way to force a restart into the boot-loader.

Lefty
« Last Edit: March 03, 2009, 12:47:05 pm by retrolefty » Logged

Indiana
Offline Offline
Full Member
***
Karma: 1
Posts: 234
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
That's interesting, I wonder why? The auto-reset that the Arduino uses seems to be pretty reliable way to force a restart into the boot-loader.

The difference is that the auto-reset used when uploaded a sketch is performed by an external voltage source instead of directly from the MCU.

The reason using a digital pin to act like an external reset is discouraged is because there is a minimum pulse duration that is necessary to properly reset the chip.  For a 168 it's 2.5us.  When you use a digital pin to programmatically reset the chip, the time from initiating the reset until the minimum pulse duration puts the chip in an undetermined state.  There's no guarantee that the digital output that pulling your reset low will stay low long enough and not leave the chip in a strange state.  Remember that the digital pins are 3-state and will probably get changed to hi-Z very early in the reset process.

If you really want to do something like this, build a simple 555 monostable timer circuit connects to the reset pin.  Then use the digital output to trigger the 555 timer.

Lastly, you can use the watchdog timer method but you have to be sure to use a "modified" bootloader like ladyada's "no-wait" version. As mentioned in the warnings above, the default bootloader does not disable the watchdog timer and your chip will keep resetting.
Logged

Montreal
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could not a long Watchdog do the job?
like longer then what the bootloader need?
Logged

Patgadget
Montreal

Montreal
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just read the specs,
from 16ms to 8 seconds.
so i am sure that someone could find a time that is safe.

Logged

Patgadget
Montreal

Indiana
Offline Offline
Full Member
***
Karma: 1
Posts: 234
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Even if 8 seconds was long enough to get past the bootloader delay and start your sketch (which would have to immediately disable the watchdog), how would you ever upload a new sketch to the chip? Chances are the watchdog would trigger a reset right in the middle of your upload.

The only solution would be to upload the .hex files directly using a programmer and eliminating the bootloader altogether. While doable, it's not something your average Arduino user would want to get into (and eliminates the ease-of-use the IDE upload process provides).
Logged

0
Offline Offline
God Member
*****
Karma: 1
Posts: 513
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

with all the C preamble, this seems to work pretty well, despite the documentation:

Quote
void(* resetFunc) (void) = 0; //declare reset function @ address 0
...
resetFunc();  //call reset
...
« Last Edit: March 10, 2009, 09:32:28 pm by dcb » Logged

Montreal
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This work perfectly
Thanks.
Logged

Patgadget
Montreal

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This works perfectly
Because the Atmel engineers discourage this method, I wonder if you really mean: It seems to work OK on the particular sketch I tried it with, it may work for you.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 137
Posts: 6805
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the "reset function at 0" certainly starts the code back at the very beginning, but it doesn't reset any of the things that are reset by a power-on...
Logged

Montreal
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok,
this code work for my application.
;-)
Logged

Patgadget
Montreal

Pages: [1] 2   Go Up
Jump to: