Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Watchdog timer


  • Please log in to reply
10 replies to this topic

#1 Robert L.

Robert L.

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts

Posted 20 September 2011 - 12:47 PM

My application uses sockets to connect to a web server and exchange data. I find I can lock up the Netduino at times by disconnecting the Ethernet cable. Other times it locks up by itself while creating the socket, resolving DNS, or even in DHCP. On the other hand, usually the application will run for hours and hours without a problem. A manual (pushing the reset button) reset works to start up the application again.

To overcome these lockups, I have tried to use the built-in watchdog, but cannot get it to work. Perhaps I do not understand how to use it. Has anyone had success using it?

So I wrote the following thread:

public class WDT  {
    private int myDelay;

    public  WDT() {
        myDelay = 60;
        (new Thread(Run)).Start();
        }
    public void Set(int d ) {
        myDelay = d;
        }

    private void Run() {
        while( myDelay > 0 ) {
            Thread.Sleep(1000);        // sleep for one second
            myDelay -= 1;
            }
        Debug.Print("Rebooting the machine");
        PowerState.RebootDevice(false);
        }

Which works most of the time, but not always. I am starting to think I need to built an external, off board, circuit to drive the reset pin. Naturally I would prefer not to do this if there is a better way.

I am looking for a solution such that the Netduino will always restart itself when ever it locks up, for what ever reason.

Any ideas would be appreciated.

#2 Robert L.

Robert L.

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts

Posted 21 September 2011 - 10:51 AM

In additional tests, it has become apparent that when the Netduino thread that acts as a web client locks up, it stops all other threads from running. The upshot of this is that the WDT code I wrote above never gets a chance to issue the reset. So clearly code that uses an output pin to pull down the reset line would also not be functional, even though there are posts in these forums suggesting that would work. So it's either the arm's built in watchdog logic, as supported by NETMF or external logic to pull down the reset line. In searching the web, I find many references to ghielectronic.com who claims that the MS support for watchdog is inadequate in some way, without detailing how. It would also seem that support for the watchdog was updated in 4.1, but again the details are lacking. Chris has posted on here that there was a desire to add support in 4.1, but I can find no further references to whether that was done or not. I have also not been able to find any posted examples of using the arm's watchdog. Has anyone been able to successfully use the watchdog timer on the netduino, and if so could you please post sample code? I plan to give this another try myself today, and if I can get it to work, will post the results.

#3 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 21 September 2011 - 11:31 AM

I have also not been able to find any posted examples of using the arm's watchdog. Has anyone been able to successfully use the watchdog timer on the netduino, and if so could you please post sample code? I plan to give this another try myself today, and if I can get it to work, will post the results.

I have not used it myself, but the watchdog can be manipulated via Watchdog class, see Enabled and Timeout properties. Please be aware of the fact that the CLR engine enables and disables it during execution too, which may conflict with your use - theoretically, in the worst case Netduino could lock up just after watchdog was disabled by the execution engine (CLR_RT_ExecutionEngine::WaitSystemEvents() function, Execution.cpp).

Note: Default watchdog timeout is 60 s.

#4 Robert L.

Robert L.

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts

Posted 21 September 2011 - 12:48 PM

I have not used it myself, but the watchdog can be manipulated via Watchdog class, see Enabled and Timeout properties. Please be aware of the fact that the CLR engine enables and disables it during execution too, which may conflict with your use - theoretically, in the worst case Netduino could lock up just after watchdog was disabled by the execution engine (CLR_RT_ExecutionEngine::WaitSystemEvents() function, Execution.cpp).

Note: Default watchdog timeout is 60 s.



Hmmm, I wrote a bit of code to try out the built in watchdog:

            Microsoft.SPOT.Hardware.Watchdog.Enabled = true;
            System.TimeSpan ts = new TimeSpan(0,0,45);
            Microsoft.SPOT.Hardware.Watchdog.Timeout = ts;
            bool wdt2 = Microsoft.SPOT.Hardware.Watchdog.Enabled;
            System.TimeSpan  wdt3 = Microsoft.SPOT.Hardware.Watchdog.Timeout;
            Debug.Print("wdt2 = " + wdt2.ToString() + "   wdt3=" + wdt3.ToString() );

The output from that is:

wdt2 = False   wdt3=00:00:00

It looks like this approach is dead in the water until/unless watchdog support is added. This is a very important feature that was discussed in detail back in Jan 2011, in this thread:

http://forums.netdui...software-reset/

I was hoping that it was now done, but apparently not. Are there any plans or schedules regarding this feature? If it's not going to be available for months from now (or never), I would like to know, since the workaround is to design an external circuit to drive the reset line.

#5 Robert L.

Robert L.

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts

Posted 22 September 2011 - 01:41 PM

OK, so I need to move ahead on my project, this is my solution: I am adding a MAX6751 chip to my design. This chip, along with just two external capacitors will pulse the reset line low if its input is not toggled often enough. In my case, I am setting the watchdog timeout interval rather long, around two minutes. This way I can be sure the Netduino is truly locked up hard before I reset it. I do not want to go through a reset unless it's really necessary.

#6 rob nelson

rob nelson

    New Member

  • Members
  • Pip
  • 2 posts
  • LocationEdwardsville, IL USA

Posted 23 September 2011 - 12:53 PM

AN interesting solution to be sure. Please post the results of your external reset as I have a similar need for a bullet-proof WDT.

#7 Sharktear

Sharktear

    Member

  • Members
  • PipPip
  • 11 posts

Posted 04 October 2011 - 01:23 PM

OK, so I need to move ahead on my project, this is my solution: I am adding a MAX6751 chip to my design. This chip, along with just two external capacitors will pulse the reset line low if its input is not toggled often enough. In my case, I am setting the watchdog timeout interval rather long, around two minutes. This way I can be sure the Netduino is truly locked up hard before I reset it. I do not want to go through a reset unless it's really necessary.


Hi, I'm really interested in your solution.. can you submit a schema of your circuit? Does the Netduino Plus have a dedicated reset line that work also when the program freeze and all the threads stop responding?
In negative case the WDT circuit should be projected in a kind of way that it force the reboot of the Netduino board (removing and restoring the power to the board)?? Or the software reset work even when all threads hangs? (sorry for my bad english..)

#8 Robert L.

Robert L.

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts

Posted 07 October 2011 - 04:24 PM

Hi, I'm really interested in your solution.. can you submit a schema of your circuit? Does the Netduino Plus have a dedicated reset line that work also when the program freeze and all the threads stop responding?
In negative case the WDT circuit should be projected in a kind of way that it force the reboot of the Netduino board (removing and restoring the power to the board)?? Or the software reset work even when all threads hangs? (sorry for my bad english..)


I finally got my watchdog circuit to work reliably. Whenever the program hangs, it reboots the N+ board. To make this work, I added an external chip whose output drives the N+ reset line with a negative pulse when needed. This circuit needs a periodic pulse to tell it that the software is still running, the absence of a pulse for more than a certain time, will then reset the N+; In my case, I set the timeout interval to about 30 seconds. This gives the N+ software time to do very lengthy tasks without the need to sprinkle pulse generating code everywhere.

Here is the class I wrote to generate the pulses which prevent reset.

public class WDT  {
    static OutputPort WDTO = new OutputPort(Pins.GPIO_PIN_A3, false);
    Int32 delay = 60;
    bool last = true;

    public  WDT() {
        (new Thread(Run)).Start();
        }
    public void Set( int dly ) {
        delay = dly;
        }

    private void Run() 
    {
        while (delay > 0)   // just let the task die if delay runs out
        {
            delay--;
            WDTO.Write(last);          // pulse the MAX6751 chip
            last = true ^ last;        // toggle the value to create a square wave
            Thread.Sleep(1000);        // sleep for one second
        }
    }
}

When the N+ locks up, this code, which runs as a separate thread, will stop executing, and therefore it will no longer generate pulses, after the 30 seconds expire, the external chip will reset the N+ board. This code will also stop if the Set() method is not called often enough. I wanted to be able to set different timeout at different places in the code. So this technique let's me cause a reset even if no full machine lockup occurs.

Question: Is that any interest in such a shield, or would people just like to make their own? The circuit is not complicated, although the chip is a tiny surface mount one.

#9 pugtech

pugtech

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationScotts Valley, CA

Posted 09 October 2011 - 05:18 AM

I'm still unclear why the built-in WDT isn't supported. If it can't be enabled reliably, I hope they'll consider adding an external chip to a future version of the controller boards.

#10 Stavros Tekes

Stavros Tekes

    Member

  • Members
  • PipPip
  • 17 posts
  • LocationThessaloniki, Greece

Posted 10 October 2011 - 07:33 AM

I finally got my watchdog circuit to work reliably. Whenever the program hangs, it reboots the N+ board. To make this work, I added an external chip whose output drives the N+ reset line with a negative pulse when needed. This circuit needs a periodic pulse to tell it that the software is still running, the absence of a pulse for more than a certain time, will then reset the N+; In my case, I set the timeout interval to about 30 seconds. This gives the N+ software time to do very lengthy tasks without the need to sprinkle pulse generating code everywhere.

Question: Is that any interest in such a shield, or would people just like to make their own? The circuit is not complicated, although the chip is a tiny surface mount one.


Hi Robert, could you give us printout of the schematic you used? I am curious if I can run a quick test to see if it can fit my needs too

Cheers,

Stavros
Stavros

#11 Robert L.

Robert L.

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts

Posted 11 October 2011 - 03:56 AM

Hi Robert, could you give us printout of the schematic you used? I am curious if I can run a quick test to see if it can fit my needs too

Cheers,

Stavros


Sure thing, here is a PDF of the circuit I am using. A couple of things of note, I used A3 as my watchdog reset line, any digital output would do, even one that is used for some other purpose, IE it does not have to be dedicated as long as the line toggles regularly, but stops switching if the machine locks up. The other point I would make, is adding the 100uF caps is not strictly part of the watchdog, but they do help the N+ board's power supplies to run more quietly. Note that the values for the duration of the reset pulse and the watchdog timeout are easily adjusted with changing the values of C4 and C5.

Attached Files






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.