Pages: [1]   Go Down
Author Topic: WDT code does not run on duemilenova and mega but runs fine on leonardo  (Read 513 times)
0 Members and 1 Guest are viewing this topic.
Belgium
Offline Offline
Edison Member
*
Karma: 58
Posts: 1731
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a problem which seems to be board specific.

I tried to run the code copied below on my duemilenova. The code runs a loop that goes slower and slower till the watchdog resets the board.
The code runs fine till the first reset triggered by the watchdog. Then led L starts blinking really fast and never stops doing so.
Pressing the reset button does not help. Taking away power and plugging it back in repeats the scenario as described above.
As the code was taken from the forum and the watchdog flag needs to be reset in the startup code, I thought this may be bootloader related so I burned the bootloader with version 1.0.2 of the Arduino IDE.
This did not solve the problem.

Then I tried with a mega and a leonardo. The mega behaves the same but the leonardo works fine.

So I'm wondering what is wrong here.

Anyone can help?
Best regards
Jantje

Code:
// Do not remove the include below
#include "test.h"

//  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
  ToggleDelay=0;
}

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

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which bootloader did you burn, exactly?
Logged

Belgium
Offline Offline
Edison Member
*
Karma: 58
Posts: 1731
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick
I was not aware that you can select a bootloader when burning a bootloader with the Arduino IDE.
So I guess I did the default one for duemilenove.
If there is a better one: can you point me to it? Can you point me to documentation how I can burn it?
Best regards
Jantje
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using the Uno bootloader on my Duemilanove - it works fine (it's the same processor) and I don't have any issues with the WDT.
Logged

Belgium
Offline Offline
Edison Member
*
Karma: 58
Posts: 1731
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I hadn't thought of that one.
I'll give it a try tonight
Best regards
Jantje
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16514
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I hadn't thought of that one.
I'll give it a try tonight
Best regards
Jantje

That should fix your issue with the WDT. 328 based boards prior to the Uno (and still to this day mega boards of all flavors) used bootloaders that do not handle WDT interrupts correctly. In the old days one could get a copy of a modified bootloader from the Adafruit (and other 3rd parties?) that would correct the problem with 328 based boards.

 But today for any of the older arduino 16Mhz 328p based boards you can just burn them with the Uno bootloader by selecting the Uno board prior to performing the burn bootloader operations. Just keep in mind that after that you must always select the Uno board when uploading sketches to the board, as in effect for uploading purposes your older board has become a Uno board.

Lefty
Logged

Belgium
Offline Offline
Edison Member
*
Karma: 58
Posts: 1731
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just keep in mind that after that you must always select the Uno board when uploading sketches to the board, as in effect for uploading purposes your older board has become a Uno board.
retrolefty
Thanks for this alert. I'm sure I would have used the name of the lord when experiencing this behavior

Best regards
Jantje
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Belgium
Offline Offline
Edison Member
*
Karma: 58
Posts: 1731
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

nick & retrolefty
this works like a charm.
Thanks for helping me out.
Best regards
Jantje
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Pages: [1]   Go Up
Jump to: