Go Down

Topic: SOftware RESET for arduino Demilanove (Read 1 time) previous topic - next topic

retrolefty


regarding point (2). I have used this method in several projects and it works fine from what I have seen.

Try this out:
Code: [Select]
#define someIO 2
void setup()
{
 // This code will only run once, after each powerup or reset of board
 pinMode(10,OUTPUT);
 digitalWrite(10,LOW);
 digitalWrite(someIO,HIGH); //enable pullup-resistor
 pinMode(someIO,OUTPUT); //THEN set to output, by doing so, pin is already high when switching to output meaning reset is not tripped.
}

void systemReset(void){
 digitalWrite(someIO,LOW);
 while(1);
}

void loop()
{
 // This code loops consecutively
 delay(1000);
 digitalWrite(10,HIGH);
 delay(1000);
 systemReset();
}


you will see an LED connected to pin10 blink on for a second then go off for a second (and the bootloader LED flashes in between). (This assumes pin 2 is connected to the reset pin).


I am just summarizing what Atmel explicitly stated, that there is a minimum length reset pulse required to guarantee a proper hardware reset process, and that can't be met by wiring an output pin to the reset pin. That fact that it may appear to (or indeed)  work, is no guarantee that it will always work with all AVR chips in all environments in all possible clock speeds. As they have published such a restriction it would seem to me to not be a method to hang one's hat on. You can find the minimum reset pulse length spec in any AVR datasheet. But of course it's just a hobby and it won't create a black hole and suck us all in, so go for it at your own risk.  :D

Lefty

Tom Carpenter

#16
Jan 16, 2013, 05:30 pm Last Edit: Jan 16, 2013, 05:33 pm by Tom Carpenter Reason: 1
It works because there is more in the circuit that just an I/O pin connected from an output to the reset pin.

Consider that there is also the "Auto-Reset" 100nF capacitor connected between the pin and GND (or +5v depending on how the DTR pin of the USB-Serial chip is set).

When the I/O pin goes low, it discharges (or charges if DTR=5v) that capcitor rapidly down to around 0v with respect to the GND at the reset pin end. When the chip then puts the I/O pins into a High-Z state, the 10k pullup has to charge (or discharge) that capacitor back up to +5v at the reset pin end which takes some time - sufficient time to reset the chip. If it wasn't sufficient time, the autoreset function itself wouldn't work.
~Tom~

retrolefty


It works because there is more in the circuit that just an I/O pin connected from an output to the reset pin.

Consider that there is also the "Auto-Reset" 100nF capacitor connected between the pin and GND (or +5v depending on how the DTR pin of the USB-Serial chip is set).

When the I/O pin goes low, it discharges (or charges if DTR=5v) that capcitor rapidly down to around 0v with respect to the GND at the reset pin end. When the chip then puts the I/O pins into a High-Z state, the 10k pullup has to charge (or discharge) that capacitor back up to +5v at the reset pin end which takes some time - sufficient time to reset the chip, else the autoreset function wouldn't work.


Well then just measure the resulting reset pulse (low) duration with a scope and then compare that to the minimum reset pulse (low) width duration specified in the datasheet. If >= then you are gold, if not watch out for black holes.  ;)

Lefty

Tom Carpenter

#18
Jan 16, 2013, 05:49 pm Last Edit: Jan 16, 2013, 05:50 pm by Tom Carpenter Reason: 1
Hmm, its roughly half of the MAX reset period (1us). If you use a diode rather than a wire then the delay becomes 300x the reset period required (800us) - Cathode to digital pin, Anode to reset pin.
~Tom~

retrolefty


Hmm, its roughly half of the MAX reset period (1us). If you use a diode rather than a wire then the delay becomes 300x the reset period required (800us) - Cathode to digital pin, Anode to reset pin.


Cool, a diode is simpler then an external 555 one-shot pulse generator.

Lefty


zarobhr

correct me if i am wrong please

pressing the reset button resets the hardware as well as software
a WDT reset only resets the software and therefor if you have other devices such as ethernet, LCD etc those will not reset

I personally use the watchdog reset method to reset for the following purposes, these are some ways you can do a software reset but you must write your application to handle it.
1. i have a configuration change to a device attached to the UNO ie... a user had to change the card reader and the new reader reads track 2 instead of track 1. I send a command to the UNO through my software the uno recognize my command in the sketch , i then write that option change to the eeprom, and then force a WDT reset, the program restarts and now the new reader will work
2. i have many of the UNO in remote locations, i also have the TFTP bootloader installed, I do not want to go to each location to change the sketch. with the software on my PC with is constantly talking to the many UNO's I press a firmware update button. It sends a command to the uno to force WDT SOFTWARE reset, as uno is resetting bootloader will wait 5 seconds for a TFTP connection, once it recieves the connection the program on my pc tftp uploads a new sketch, resets uno again and then uno is running the new sketch

these are 2 examples i use, but you must write your sketch to do it, and write your pc based program or web site or whatever to take advantage of it
there is no specific way  that a software reset should be done. a software rest is not a hard reset, in fact even when uploading from the ide even though the reset is driven through the software it is still a hardware reset since it has the same effect as pushing the reset button

hope this helps explain

retrolefty

Quote
pressing the reset button resets the hardware as well as software
a WDT reset only resets the software and therefor if you have other devices such as ethernet, LCD etc those will not reset


The WDT resets the software and all the hardware registers on the AVR chip to their default condition, just as if you hit the reset switch or powered the chip down then on. But you are correct that the WDT does not do anything automatically to external stuff wired to the arduio, unless the arduino sketch performs some kind of 'reset' or start-up configuration stuff for the external stuff in the setup() function.

Lefty

Nick Gammon


i tried to debug the program. It worked fined for few days , again same issue has been raised.


Sounds like a bug. One worth fixing. Do you want it to be reliable or not? I have a program that opens my front door. It runs for something like a year at a time without needing resetting.

We have had the issue before of needing to reset all hardware including attached boards. My suggestion was to use the watchdog timer to reset the Arduino, and then have the Arduino bring an output pin low, which is attached to the reset lines of other things (like Ethernet boards) to reset them as well.

However if you were to post your code, we might spot the thing that is causing these problems.

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

AMPS-N

Here problem i found is this will keep on reseting the mcu every time.
I wanted to RESET when watch dog timer cant take care of software RESET  or program get struck @ particular point.



regarding point (2). I have used this method in several projects and it works fine from what I have seen.

Try this out:
Code: [Select]
#define someIO 2
void setup()
{
 // This code will only run once, after each powerup or reset of board
 pinMode(10,OUTPUT);
 digitalWrite(10,LOW);
 digitalWrite(someIO,HIGH); //enable pullup-resistor
 pinMode(someIO,OUTPUT); //THEN set to output, by doing so, pin is already high when switching to output meaning reset is not tripped.
}

void systemReset(void){
 digitalWrite(someIO,LOW);
 while(1);
}

void loop()
{
 // This code loops consecutively
 delay(1000);
 digitalWrite(10,HIGH);
 delay(1000);
 systemReset();
}


you will see an LED connected to pin10 blink on for a second then go off for a second (and the bootloader LED flashes in between). (This assumes pin 2 is connected to the reset pin).
AMPS

Tom Carpenter

That was just an example. You would call the systemReset() function at any point in the program you want. Wrap it in an if statement, for example:

Code: [Select]
#define someIO 2
void setup()
{
  // This code will only run once, after each powerup or reset of board
  pinMode(10,OUTPUT);
  digitalWrite(10,LOW);
  digitalWrite(someIO,HIGH); //enable pullup-resistor
  pinMode(someIO,OUTPUT); //THEN set to output, by doing so, pin is already high when switching to output meaning reset is not tripped.

  Serial.begin(115200);
}

void systemReset(void){
  digitalWrite(someIO,LOW);
  while(1);
}

void loop()
{
  static unsigned long nextMillis = millis() + 1000;
  // This code loops consecutively
  if (millis() > nextMillis){
    digitalWrite(10,!digitalRead(10));
    nextMillis += 1000;
  }
  if (Serial.available() && (Serial.read() == 'K')){
     systemReset(); //reset only when you send the uppercase letter 'K' (for kill?) through the serial port
  }
}
~Tom~

Go Up