Pages: [1]   Go Down
Author Topic: Watchdog timer Question???  (Read 4762 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would like to set a Watchdog timer to reset my Arduino Atmega168 microcontroller, if I do not pat the dog( prevent the Watchdog timer from expiring and reseting my Atmega168) every 2 minutes.  However, I am not sure how to do this, all I found is the starting point of code below from a google search:

Example Code (GCC) Resetting the AVR every 30mS:

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

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


Alternatively you can create a macro:

Code:

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

#define Reset_AVR() wdt_enable(WDTO_30MS); while(1) {}

int main(void)
{
Reset_AVR();
}



Thanks for any help
Rico
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you could try it with something like this:

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

void setup(){
  wdt_enable(WDTO_30MS);
}

If you want to have a look, hardware\tools\avr\avr\include\avr\wdt.h has the defines for different watchdog delays. The longest delay defined is 2 seconds.  I think the ATmega168 chip used in the arduino can support up to 8 seconds
« Last Edit: December 15, 2008, 03:13:02 am by mem » Logged

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

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

void setup(){
  wdt_enable(WDTO_30MS);
}

MEM, so the above code takes care of everything meaning I do not need to pat the dog every 30 milliseconds? It is all done by the calling function.
If so, that is great.
Thanks
For the help
Rico
« Last Edit: December 15, 2008, 11:48:23 am by Rico_Bravo » Logged

"The old Europe"
Offline Offline
Edison Member
*
Karma: 1
Posts: 2005
Bootloaders suck!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://linux.die.net/man/3/wdt_enable
http://www.nongnu.org/avr-libc/user-manual/group__avr__watchdog.html

--> wdt_reset()

p.s. google ... and so on
« Last Edit: December 15, 2008, 02:07:37 pm by madworm » Logged

• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I answered rico via pm, this was my response:

the code posted sets the watchtog for the given timeout period, you still need to pat the dog.

To do that, you must call wdt_reset();
When the watchdog timer is enabled, a call to this instruction is required before the timer expires, otherwise a watchdog-initiated device reset will occur.

There is not yet an arduino friendly version of this code so you will need to do a little research, there looks to be quite a good document here: http://www.atmel.com/dyn/resources/prod_documents/doc2551.pdf

I have not used the watchdog on the Arduino so don't have any more info than that.
Logged

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

I tried the following code below, trying to trigger the watchdog timer using a delay of 10 seconds and the microcontroller got stuck in an infinite reset loop. I thought it should reset and turn the LED on for another 10 seconds but not the case?? Not sure why???? Can anyone help?
Thanks
RB smiley-sad

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



int ledPin = 5;


void setup()
{
 wdt_enable(WDTO_8S);
 pinMode(ledPin, OUTPUT);
}

void loop()
{
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(10000);                  // waits for a 10 seconds
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(250);                  // waits
  wdt_reset();
}
« Last Edit: December 15, 2008, 10:24:54 pm by Rico_Bravo » Logged

"The old Europe"
Offline Offline
Edison Member
*
Karma: 1
Posts: 2005
Bootloaders suck!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The dog is impatient !

BTW, if you just want to make the led blink, you don't need the watchdog at all.

ruff ruff
« Last Edit: December 16, 2008, 02:06:23 am by madworm » Logged

• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!

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

I tried adding the MCUSR=0; like the data sheet said and still not working???  smiley-sad

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



int ledPin = 5;


void setup()
{
MCUSR=0;
wdt_enable(WDTO_8S);
pinMode(ledPin, OUTPUT);
}

void loop()
{
 digitalWrite(ledPin, HIGH);   // sets the LED on
 delay(10000);                  // waits for a 10 seconds
 digitalWrite(ledPin, LOW);    // sets the LED off
 delay(250);                  // waits
 wdt_reset();
}
Logged

"The old Europe"
Offline Offline
Edison Member
*
Karma: 1
Posts: 2005
Bootloaders suck!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You set the watchdog timer timeout to 8 seconds, then you wait for more than 10 seconds, and then you pat the dog with wdt_reset().

As the 8 < 10 your code never gets beyond delay(10000).

Logged

• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!

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

Yes, I know this, the problem is the watchdog timer never comes out of the reset loop.  I spoke with another fellow and he said the problem is with the bootloader. However, I think ladyada's bootloader will sovle this problem.  I will post the results next week!
Logged

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

Hey, Just want everybody to know that the watchdog timer works perfect with ladyada's bootloader from adafruit.com
Logged

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

I tried the code up there, and now i can`t upload coz the dog keeps barking. LED 13 keeps blinking all the time. Panic mode: ON.
Any help plz. THX
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1271245150/2#2
Logged

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

I make the watchdog timer 30MS.....Darn it so hard to try what u said.
ANY other option? smiley-cry
Logged

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

Miracles does happens, some delay happened and i can upload blink. fiuh...thx.
Logged

Pages: [1]   Go Up
Jump to: