Hi, please see if you can help me out.
Ive got an arduino mega controlling power consumption and several other things. However, since i added an additional onewire instance my arduino is much less stable (at least i think its because of this)
to the point...
When the arduino freezes the watchdog should kick in, however nor the watchdog or the reset button restart the arduino at all. I must unpower the device and power it again and everything starts to work as normal.
Is the watchdog in the arduino mega 2560 free of the bug that the deumillove had?
Any reason for the reset button not working? it works fine when the arduino is not freezed.
please please any help is really appreciated.
thanks
Well you haven't posted any code so it is a bit of a shot in the dark.
Any reason for the reset button not working?
You can't stop the reset button from working even if you wanted to, so it is still working. However, I suspect it is not having any effect because of the watchdog timing out before the boot loader can kick out and begin running your code again. So check the watch dog time.
since i added an additional onewire instance my arduino is much less stable (at least i think its because of this)
This could be the result of your watch dog timer being too short as well. Where do you do the dog kicking? If it is in the main loop then it might be spending too long in this routine for the time you have set.
Most projects I have been involved with have normally turned off the watch dog until everything is developed and in place and you can assess the real time you need.
I have not posted the code as its very very long program and i wouldnt expect noone to read it to find any kind of error.
So lets see if i get some things understud and maybe locate the problem.
What does the reset button really do? does it perform a full reset as if i disconnected the power? If not, maybe there is something about the watchdog wrong.
does the arduino mega have the problem if kicking in and then reseting the preestablished watchdog timer. I have it setup at 8 seconds.
I have added some more watchdog resets around the code and seems to be more stable now. So maybe it was indeed the watchdog kicking in and then staying blocked. I had seen this in the deumillanove (sp) but thought that the mega didnt had this problem. does the bootloader have the same problem of watchdog?
What does the reset button really do? does it perform a full reset as if i disconnected the power? If not, maybe there is something about the watchdog wrong.
No, it toggles the RESET pin, which is not the same as a power cycle.
Sergegsx:
I had seen this in the deumillanove (sp) but thought that the mega didnt had this problem. does the bootloader have the same problem of watchdog?
What lead you to believe the behavior would be different? I wouldn't call it a "problem." The watchdog is doing exactly what is suppose to be doing. It's just that the bootloader doesn't kick it, allowing it to be activated before you get a chance to kick it. If this is an issue, don't use the bootloader.
Note that for newer devices (ATmega88 and newer, effectively any AVR that has the option to also generate interrupts), the watchdog timer remains active even after a system reset (except a power-on condition), using the fastest prescaler value (approximately 15 ms). It is therefore required to turn off the watchdog early during program startup, the datasheet recommends a sequence like the following
However, this still doesn't solve the WD not being kicked in the bootloader.
I find it really strange that you seem to need a watchdog to get your code "working" more or less. If everything were right, you shouldn't need it at all. And a watchdog timer is definitely not meant to "fix" code that hangs on a regular basis. Fix your code first.
madworm:
However, this still doesn't solve the WD not being kicked in the bootloader.
I find it really strange that you seem to need a watchdog to get your code "working" more or less. If everything were right, you shouldn't need it at all. And a watchdog timer is definitely not meant to "fix" code that hangs on a regular basis. Fix your code first.
My project works pretty well, there is actually no major need for the watchdog. However, this is going to be running unattended therefore a watchdog should be the best solution in case of something weird happening.
So its actually true that the arduino bootloader is not compatible with the watchdog?? I belive that in the Arduino UNO it works correctely but in the deuminove it did not work. There is no solution to the arduino mega then? Does this mean that noone is using watchdog in arduino mega in their projects?
From what i had read in the internet, there was a bug in the Arduino duemillanove bootloader that even if the reset was set to 8 seconds, when it kicked in, it was reset to 15ms and therefore the arduino remained in a endless loop. However, I think arduino UNO had a bootloader that did not suffered from this problem. there was even a modified bootloader for the duemillanove which fixed the issue.
Therefore, I thought that the arduino MEGA did not have such a "bug" or however is called, and that watchdog timer setting was preserved after it kicking in.
so, no luck with arduino mega working with watchdog?
i have it set to 8seconds, but I believe there is a problem with the bootloader that when watchdog kicks in, the watchdog timer is set to its minimum value so it ends up in an endless loop.
Is this correct in the arduino mega 2560?
can it be fixed?
madworm:
The short watchdog timeout is not a bootloader bug. The WD timeout is changed on reset. Please read the manual. The link is above.
The arduino bootloader simply wasn't made to deal with a watchdog timer. Use an ISP.
By "use an ISP"...you mean reprogram the bootloader? remove it? (I would really like to avoid removing it)
use what bootloader then? Ive seen that optiboot solves the issue in the arduino deuminove but dont know what bootloader i should program for the MEGA, if there is any at all.
Sergegsx:
Would that completely solve the issue? Then why there is no official bootloader release?
As you could probably tell by this thread, the watchdog is something that isn't used very much. There are no Arduino APIs for it.
As with all features, it takes sometime time to implement a fix and it seems nobody has done that yet. The Arduino team doesn't have infinite resources, but they have open sourced their work so that others can build on it...
I'll see if I decide to test it, although it is true that my project is very stable, but want it to have it just in case.
its interesting to see that not so many people use it, i really thought it was a MUST when doing projects which will work unattended.
That doesn't seem right, if the timeout was caused by a watchdog. I find the datasheet ambiguous on the topic.
In any case, I think that the MEGA bootloader timeout is longer than 8 seconds, and it does NOT include code to turn off the watchdog. So if the main sketch enables the watchdog, and allows a timeout to occur, you WILL get stuck in a bootloader loop.
The Uno has an entirely different bootloader, where this problem has been fixed.
I think that upon reset the prescaler bits of the WD timer are reset to their default values (16ms timeout). The only thing that remains unchanged seems to be the WDE bit. At least that could explain the issue and the comment on the avr-libc website on how to turn the WD timer off early.