Loading...
Pages: 1 [2]   Go Down
Author Topic: Watchdog Trouble  (Read 942 times)
0 Members and 1 Guest are viewing this topic.
United Kingdom
Offline Offline
Faraday Member
**
Karma: 131
Posts: 4681
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried disabling the watchdog at the start of setup(), using the code I gave in the thread I linked to in an earlier post?
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com

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

Yes, I do (see the code below).
 smiley-eek I must confess you that there is something that escapes me. Indifferently of boot, if I write in the watchdog registers the good values, the µP must be done a reset. Why doesn't it done ?

Code:
#include <avr/wdt.h>

void setup()
{
   Serial.begin(9600);

  // Turn off watchdog timer  <--- recopy to your post
  cli();
  wdt_reset();
  MCUSR = 0;    // clear watchdog reset flag
  WDTCSR |= (1 << WDCE) | (1 << WDE);
  WDTCSR = 0x00;
  sei();
   // set the watchdog to 8s
   wdt_reset();  
  // disable all interrupts
  cli();
  wdt_reset();
  MCUSR &= ~(1<<WDRF);
  WDTCSR |= (1 << WDCE) | (1 << WDE);
  WDTCSR = (1 << WDE) | (1 << WDP3) | (1 << WDP2) | (1 << WDP1) | (1 << WDP0);  // 8s
  // enable all interrupts
  sei();
}
void loop()
{
    Serial.println("I am in the loop");
    while(1) {
       // to have the reset !!!
       Serial.println(millis());
    }
}
Logged

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

Sorry for my insistence, but I am always blocking  smiley-cry
Is there any body who arrive to do worked a reset watchog on arduino mega ? If yes, please could you give me a simple example.
Thanks in advance.
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 219
Posts: 13896
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What's all the mucking around with registers? Here is an example that works on a Uno:

Code:
#include <avr/wdt.h>

void setup ()
{
  Serial.begin (115200);
  wdt_enable(WDTO_1S);  // reset after one second, if no "pat the dog" received
 }  // end of setup

void loop ()
  {
   
  Serial.println ("Entered loop ...");
 
  Serial.println ("Point A");
  delay (500);
  Serial.println ("Point B");
  delay (400);
 
  wdt_reset();  // give me another second to do stuff (pat the dog)
 
  Serial.println ("Point C");
  delay (500);
  Serial.println ("Point D");
  delay (400);
 
  while (true) ;   // ohno!, went into a loop
     
  }  // end of loop

I tested that on my Mega and it didn't work. I suspect there is a problem with the bootloader and then watchdog timer. There are some known problems with the watchdog timer and the bootloader.
Logged


Global Moderator
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 219
Posts: 13896
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That sketch bricks my Mega in a rather annoying way. You can recover by re-uploading the bootloader but there is clearly something wrong.

You can also recover by:

  • Open a sketch that doesn't use the watchdog (eg. Blink)
  • Unplug the USB (so the board is powered off)
  • Hold down the reset button with one hand
  • Keeping it held down, plug in the USB
  • Start uploading
  • Release the reset button a moment or two after it says "uploading"
  • With luck, the new sketch will be uploaded
Logged


Global Moderator
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 219
Posts: 13896
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I uploaded the above sketch to my Mega and unset the BOOTRST fuse (so it skips the bootloader). With the sketch starting directly, I see:

Code:
Entered setup ...
Entered loop ...
Point A
Point B
Point C
Point D
Entered setup ...
Entered loop ...
Point A
Point B
Point C
Point D
Entered setup ...
Entered loop ...
Point A
Point B
Point C
Point D
Entered setup ...
Entered loop ...
Point A
Point B
Point C
Point D
Entered setup ...
Entered loop ...
Point A
Point B
Point C
Point D
Entered setup ...
Entered loop ...
Point A
Point B
Point C
Point D
Entered setup ...
Entered loop ...
Point A
Point B
Point C
Point D

So the watchdog works then. smiley
Logged


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

 smiley I am happy to see that the watchdog can work with mega board.
I followed each step that you said but the program stops after "Point D".
I think that my problem is with BOOTRST fuse.
Quote
I uploaded the above sketch to my Mega and unset the BOOTRST fuse (so it skips the bootloader). With the sketch starting directly, I see:
I didn't find where I can unset the BOOTRST fuse. How do you do that ?
Thanks very much for your help.
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 219
Posts: 13896
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I uploaded the .hex file with my "hex file uploader" described here:

http://www.gammon.com.au/forum/?id=11638

A side-effect is it clears the BOOTRST fuse if it is uploading a "normal" program (not a bootloader).

However if you have a programmer (such as USBISP or similar) you can use avrdude to change fuses.

Something like this:

Code:
avrdude -c usbtiny -p m2560 -U hfuse:w:0xD9:m

Better check with http://www.engbedded.com/fusecalc before changing fuses. Get that wrong and you might not be able to program it again without using a high-voltage programmer (next to impossible with a surface-mounted chip).

The alternative is to ask around for a bootloader that doesn't have this problem. I thought mine didn't but was wrong. You still need a programmer to install the new bootloader, but you can use a spare Uno for that. (See the posts about Arduino as ISP).
Logged


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

Thank you very much for your answer and a big cheer for your project, it is very interesting.
Actually, I haven't the equipment to work the reset watchdog on arduino mega.
I keep this post and I will buy the programmer or a SD card reader to use your project with my uno.

 smiley-roll A last idea comes me, does it exist an other board with equivalent ATMEL as mega, which the reset watchdog  works with the default bootloader ?
Logged

United Kingdom
Offline Offline
Faraday Member
**
Karma: 131
Posts: 4681
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A quick google for 'arduino mega bootloader watchdog' came up with some alternative bootloaders.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com

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

yes, I already saw that, but I don't have equipment to flash my board. So, I will buy the programmer and as well as placing an order, I want to know, if it exists a board equivalent to arduino mega which the reset watchdog works by default (with factory parameters). Do you know if is it exist ?
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 219
Posts: 13896
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The bootloader is software. It's easy enough to replace it. Personally I don't know of a Mega-equivalent with the correct bootloader on it.

Quote
A quick google for 'arduino mega bootloader watchdog' came up with some alternative bootloaders.

Yes, well I downloaded one that claimed to have fixed the watchdog problem, but it didn't.
Logged


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

Thanks for your answer, I bought the programmer and I hate to receive it to flash the bootloader.
Logged

Pages: 1 [2]   Go Up
Print
 
Jump to: