Pages: [1]   Go Down
Author Topic: Restart Arduino Mega 2560 without Watchdog Timer  (Read 1915 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
 
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8855
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can try this little sketch on your Mega to see if the WDT is working properly.  It works on my UNO R2.
Code:
//  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.
}
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 47
Posts: 2270
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi smiley

use in the setup:

Code:
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 smiley

Code:
void reboot(){

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

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

HTH smiley
« Last Edit: June 05, 2013, 12:39:17 am by Galaktika » Logged

Pages: [1]   Go Up
Jump to: