Pages: [1] 2   Go Down
Author Topic: Reset command  (Read 21357 times)
0 Members and 1 Guest are viewing this topic.
Sweden, Malmö
Offline Offline
Full Member
***
Karma: 2
Posts: 200
Rooky
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it possible to use a reset command in the code to reset the Arduino?
What command would that be?
Logged

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

One way of doing a software reset is to enable the watchdog timer and let it timeout. A google search should turn up code examples for doing this.
Logged

Sweden, Malmö
Offline Offline
Full Member
***
Karma: 2
Posts: 200
Rooky
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,

Was thinking on putting a small relay to do actual button pressing and controlling it by a digital output high command.  ;D
Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 91
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just linked from a digital pin to the reset pin, with a pull down resistor.  When you want to reset just set the digital pin high.  I had my test set up so that I could send a reset command through the serial link.  Is this what you're after?
Logged

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

This seems to come up from time to time, but the Atmel do say that using a pin to reset the chip is not good practice.

Quote
You should not try to use another pin of the AVR to pull the external RESET line. The pins of the AVR are tristated halfway through the minimum reset time, this releases the RESET line and hence nothing happens.

There is example code for the preferred way to do a software reset here:
http://support.atmel.no/bin/customer?=&action=viewKbEntry&id=21
Logged

Sweden, Malmö
Offline Offline
Full Member
***
Karma: 2
Posts: 200
Rooky
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks DaveAK and mem.
Both good solutions, one hardware and one software!
I think i will try the software one first if fail the hardware one should do the trick.

Logged

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

huh? Perhaps my previous post wasn't clear. The company that designed the chip say that you shouldn't use a pin to do a reset

It may work for some, but why do something the designers say is wrong?
Logged

Sweden, Malmö
Offline Offline
Full Member
***
Karma: 2
Posts: 200
Rooky
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Aha,
Did read your post but just checked the link without reading to carefully.
So software it is, thanks again mem.
Logged

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

cheers MEM

I got following from the link you provided and it works great.

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

int main(void)
{
wdt_enable(WDTO_30MS);
while(1) {};
}
Logged

Switzerland
Offline Offline
Sr. Member
****
Karma: 0
Posts: 276
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hmm yea the code does work, but
now i can't load any sketch to the arduino anymore..
It does reset itself that quick that the sketch
can't get uploaded...

What can I do?

Thx
Geko
« Last Edit: February 09, 2009, 07:45:13 am by GekoCH » Logged

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

Couldn't one use the same hardware trick that the Arduino IDE uses to reset the chip? Wire a .1 cap from an output pin and toggle it? Maybe I'll try and breadboard up an experimate and see if it works later today. Have a cold today and feel like c**p.  :'(

Lefty
Logged

Sweden, Malmö
Offline Offline
Full Member
***
Karma: 2
Posts: 200
Rooky
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Bringing a old post to life again.

Can not really figure this code out

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

int main(void)
{
wdt_enable(WDTO_30MS);
while(1) {};
}

It leads my arduino to freeze, flashing the "L" led in a high rate.
Logically it is reseting my arduino every 30ms, but i only want it to reset it once.
What am i doing wrong.
« Last Edit: April 24, 2009, 12:48:42 pm by HULK » Logged

Sweden, Malmö
Offline Offline
Full Member
***
Karma: 2
Posts: 200
Rooky
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Found some more information on this, see text below.
All is pointing at the watchdog, seems as it needs to be disabled otherwise it stays on and continually resets.
Still i can not find a way of making the code working,anybody having time or knowledge to point me the right way?

How do I perform a software reset of the AVR?
The canonical way to perform a software reset of the AVR is to use the watchdog timer. Enable the watchdog timer to the shortest timeout setting, then go into an infinite, do-nothing loop. The watchdog will then reset the processor.
The reason why this is preferable over jumping to the reset vector, is that when the watchdog resets the AVR, the registers will be reset to their known, default settings. Whereas jumping to the reset vector will leave the registers in their previous state, which is generally not a good idea.

CAUTION! Older AVRs will have the watchdog timer disabled on a reset. For these older AVRs, doing a soft reset by enabling the watchdog is easy, as the watchdog will then be disabled after the reset. On newer AVRs, once the watchdog is enabled, then it stays enabled, even after a reset! For these newer AVRs a function needs to be added to the .init3 section (i.e. during the startup code, before main()) to disable the watchdog early enough so it does not continually reset the AVR.

Here is some example code that creates a macro that can be called to perform a soft reset:


Code:
#include <avr/wdt.h>

...

#define soft_reset()        \
do                          \
{                           \
    wdt_enable(WDTO_15MS);  \
    for(;;)                 \
    {                       \
    }                       \
} while(0)

For newer AVRs (such as the ATmega1281) also add this function to your code to then disable the watchdog after a reset (e.g., after a soft reset):

Code:
#include <avr/wdt.h>

...

// Function Pototype
void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3")));

...

// Function Implementation
void wdt_init(void)
{
    MCUSR = 0;
    wdt_disable();

    return;
}
« Last Edit: April 25, 2009, 06:13:49 am by HULK » Logged

Sweden, Malmö
Offline Offline
Full Member
***
Karma: 2
Posts: 200
Rooky
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

After some more searching on the watchdog i found a solution  smiley.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235780325/all

Code:
void(* resetFunc) (void) = 0; //declare reset function @ address 0
...
resetFunc();  //call reset
...
Logged

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

And if you read the rest of that thread you'd see why jumping to address 0 is not really a reset and not recommended.

All that does is start the code over, it doesn't reset the chip - an important distinction.
Logged

Pages: [1] 2   Go Up
Jump to: