Go Down

Topic: Restart Arduino Mega 2560 without Watchdog Timer (Read 2074 times) previous topic - next topic

bosstweed1

I am currently using the Arduino Mega 2560 in conjunction with the  LSM303DLM ( http://www.pololu.com/catalog/product/1273 ).  Sometimes the device craps out and hangs the operation of my program. 

I have tried to use the watch dog timer but it doesn't work fully, it never resets the board.  I have also looked into burning a new bootloader to my mega so that it would support the watch dog timer, but when I burned the burned the new bootloader just bricked my arduino( or at least I think i did).

Is there another way of "restarting" the arduino when it hangs up?

Or is there a board out there that fully supports the watch dog timer?

This is for a school project, any help would be much appreciated by myself and classmates!

johnwasser

You can try this little sketch on your Mega to see if the WDT is working properly.  It works on my UNO R2.
Code: [Select]

//  Watchdog Timer Example
#include <avr/wdt.h>

unsigned long ToggleDelay;  //  When this delay grows to longer than the WDT interval the WDT resets the Arduino

const int LEDpin = 13;

void toggle_led()
{
  digitalWrite(LEDpin, !digitalRead(LEDpin));
}

void setup()
{
  wdt_disable();
  ToggleDelay = 1;   // Start with a very short delay
  pinMode(LEDpin, OUTPUT);
  wdt_enable(WDTO_250MS);  // Set watchdog to 1/4 second
}

void loop()
{
  wdt_reset();
  toggle_led();   // Blinking goes slower and slower until the WDT causes reset, then starts over.
  delay(ToggleDelay);
  ToggleDelay += 5;   // Increase the delay by 5 milliseconds.
}
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

blackbolek

I tried your code on my Mega 2560 and it doesn't seems to work. The LED slows down with blinking until it stops (is lit up constantly). It doesn't seems to reset at all. Are you sure it should work on Mega?

Nick_Pyner


It doesn't seems to reset at all.


While I don't know why there would be a distinction between Uno and Mega, you seem to be talking about hardware reset anyway. There has been recent discussion here.

http://forum.freetronics.com/viewtopic.php?f=4&t=4940&sid=fd6f923659847b2e638054a19888ec36

blackbolek

After 2 hours of reading on Arduino software reset (using watchdog), it seems to me that the watchdog reset does not work. Is anybody there who has software reset working on Mega board?
Or do I need to employ some hardware reset technique?

Galaktika

#5
Jun 05, 2013, 07:28 am Last Edit: Jun 05, 2013, 07:39 am by Galaktika Reason: 1
hi :)

use in the setup:

Code: [Select]
void setup(){
// Arduino Reset Hack http://weblog.jos.ph/development/arduino-reset-hack/
// digitalPin 7 is connected to the RESET pin on Arduino
// NOTE: you CANNOT program the board while they are connected
// by default digitalPin 13 will blink upon reset, so stick an LED in there
digitalWrite(7, HIGH); //We need to set it HIGH immediately on boot
pinMode(7,OUTPUT);     //We can declare it an output ONLY AFTER it's HIGH
}


then write the pin HIGH to reset your arduino :)

Code: [Select]
void reboot(){

// do somthing useful before shutdown...
// ....
// ....

digitalWrite(7, LOW); //Pulling the RESET pin LOW triggers the reset.
}


HTH :)

Go Up