Go Down

Topic: using watchdog without any bootloader (Read 1 time) previous topic - next topic

sadat007

Dear, After struggling since few days, I am asking for solution, Using watchdog without any bootloader!

I am using latest arduino compiler, board is mini pro. Tried included library, Adafruit Watchdog Library and nadavmatalon library. None of the example worked for me  :smiley-confuse: results stuck in infinite loop after triggering watchdog.

I need urgent please!

jremington

Please read the "How to use this forum" post and follow the directions carefully.

Post your code, using code tags.

sadat007

Excuse me! well I thought its a simple issue and some one here may have already experienced.
Well I solved it and like to share

Code: [Select]
//https://github.com/nadavmatalon/WatchDog

#include "WatchDog.h"
byte WDTcounts;
void(* resetFunc) (void) = 0;//declare reset function at address 0

void setup() {
WDTcounts=0;
    WatchDog::init(WDTint_, 500);

}

void loop() {
WDTcounts=0; // if you remove it your system will RESET

}

void WDTint_() {                                         // watchdog timer interrupt service routine   
WDTcounts=WDTcounts+1;
if(WDTcounts>2){
    WDTcounts=0;
    resetFunc();}


pert

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

I don't understand the purpose of that code. It looks like you are using the library to reproduce the standard behavior of the watchdog but with a half-assed jump to zero style of reset? The intent of the library is to make it easier (debatable) to use the watchdog ISR. If you only want to reset the Arduino if your program hangs then use the standard avr-libc avr/wdt.h library
http://www.atmel.com/webdoc/avrlibcreferencemanual/group__avr__watchdog.html
This is much less complex and will give you a proper reset. Note that the standard bootloader used on the Pro Mini has a bug that causes an endless reset loop after a watchdog reset but since you're not using a bootloader that's not a problem and even if you wanted to use a bootloader you just have to burn the optiboot bootloader (can use Uno bootloader if using 16 MHz Pro Mini).

The following code will accomplish much the same thing as your code. The only difference is it's a 2 second timeout instead of 1.5 seconds and it does a real reset:
Code: [Select]
#include <avr/wdt.h>

void setup() {
  wdt_enable(WDTO_2S);  //enable the watchdog timer with a 2 second timeout duration
}

void loop() {
  wdt_reset();  //reset the watchdog timer
}

Much more simple and saves memory too!

sadat007

Dear Pert,
I already tried same as you suggested but result was endless reset loop after a watchdog reset. spends hours! >:(
finally the code suggested by me worked fine.
Thanks

pert

It must have been the bootloader bug I mentioned causing the reset loop. It's very easy to solve.

sadat007

Dear Pert! Please read the title of the topic...using watchdog without any bootloader....I have no bootloader on my arduino.

jremington

#7
Apr 23, 2017, 11:31 pm Last Edit: Apr 23, 2017, 11:34 pm by jremington
Are you sure that you have no bootloader? What code is in the bootloader area of program memory? What code is in the region starting at zero in program memory?

So far, there is no explanation for why you experienced the "endless reset loop" OR why your code fixed the problem.

sadat007

Dear, Yes no bootloader, using "Export compiled binary", and then using USBASP and generated HEX file (without bootloader).....
Please ready this article for memory map and other infos.
https://www.iot-experiments.com/arduino-pro-mini-1mhz-1-8v/

Go Up