Go Down

Topic: Is there a reset function? (Read 10170 times) previous topic - next topic

giannichan

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

Cheers,

follower

Maybe look into using the watchdog reset.

--Phil.

Mark Bramwell

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

retrolefty

#3
Mar 02, 2009, 07:36 am Last Edit: Mar 02, 2009, 07:37 am by retrolefty Reason: 1
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


follower

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.

retrolefty

#5
Mar 03, 2009, 06:46 pm Last Edit: Mar 03, 2009, 06:47 pm by retrolefty Reason: 1
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

etracer

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.

Patgadget

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

Patgadget

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

Patgadget
Montreal

etracer

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

dcb

#10
Mar 11, 2009, 03:31 am Last Edit: Mar 11, 2009, 03:32 am by dcb Reason: 1
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
...


Patgadget

Patgadget
Montreal

mem

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.

westfw

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

Patgadget

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

Go Up