Today 18:44
Forum: Proton Plus Compiler v3
Starter: Henk57
Views: 0
Replies: 0
Go to last post By: Lester
Today 17:48
Forum: Website / Forum Issues
Starter: Lester
Views: 0
Replies: 7
Today 02:26
Forum: New devices and techniques
Starter: normnet
Views: 861
Replies: 1
Yesterday 22:04
Forum: USB
Starter: See_Mos
Views: 0
Replies: 3
+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Watchdog example1380 days old

  1. #1
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    212
    Thumbs Up
    Received: 6
    Given: 1
    Total Downloaded
    2.23 GB

    0 Not allowed!

    Default Watchdog example

    Hey all
    How can I use the watchdog?
    Where can I find an example in proton?
    Thanks in advance
    Teo

  2. #2
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    212
    Thumbs Up
    Received: 6
    Given: 1
    Total Downloaded
    2.23 GB

    0 Not allowed!

    Default Re: Watchdog example

    No one can help me with an example?
    Thanks in advance
    Teo

  3. #3
    Fanatical Contributor pic-ignorant's Avatar
    Join Date
    Oct 2007
    Posts
    3,055
    Thumbs Up
    Received: 29
    Given: 30
    Total Downloaded
    834.62 MB

    0 Not allowed!

    Default Re: Watchdog example

    Hi Teo,

    The Proton command is Declare Watchdog = On. (See Proton help file)

    The watchdog can also be enabled in the config fuses. With most of the devices I use, it is possible to disable the watchdog in the config fuses then enable it when required in the software using the SWTDEN command or similar in the WDTCON reg. (see your device datasheet). The name of this reg may vary for different devices. You can also select the rollover period using the WDTCON reg.

    Example below for a 16F887.
    'WATCHDOG SETTINGS
    WDTCON.0 = 1 ' Watchdog enable(1)/disable(0) '01011 = 4.5 secs
    WDTCON.1 = 1 ' WDTCON 1-4 are WDT prescaler settings
    WDTCON.2 = 0 ' 11111 = 1 secs
    WDTCON.3 = 1 ' 0000= 1:32..0010= 1:128...0100 = 1:512(reset value)..'01001 = 2.3 secs.
    WDTCON.4 = 0 ' 1011= 65536(max value) see DS p227

    In your code you need to consider where you want the watchdog to rollover in the event of a problem. Where you don't want it to rollover, you issue a CLRWDT (clear watchdog) command.

    You can test the watchdog by using it to flash a led.

    low Led
    delayms 1000
    High Led

    If you set the watchdog to rollover at approx. 2 second intervals,(modify WDTCON reg to suit) the led will be off for 1 second then turn on. After 2 seconds, the watchdog will reset the pic, and go to the first line of code which is led off.

    If you disable the watchdog, the led will be off for 1 second, then stay on permanently.

    Regards
    John

    Regards
    Last edited by pic-ignorant; 4th March 2014 at 23:22. Reason: typos as usual

  4. #4
    Senior Member barak's Avatar
    Join Date
    Apr 2008
    Posts
    743
    Thumbs Up
    Received: 48
    Given: 11
    Total Downloaded
    783.11 MB

    0 Not allowed!

    Default Re: Watchdog example

    There are many ways to use the WD. I mainly use it to periodically wake from sleep. This is very reliable and simple.
    During system development, I will also use it to reset the micro if it is stuck (in a loop).
    You need to be very careful about using it like that in a real world system as it can present many issues but if you know what you are doing a WD in the right place can save you.
    Code:
    'example for sleep loop where you wakeup on watchdog timer every 1 Sec
    ' check something and go back to sleep
    Device = 18Fxxxxx   
    Config_Start
      '
      WDTEN = OFF    ;WDT is controlled by SWDTEN bit of the WDTCON register
      WDTPS = 256    ; every 256 * 4 = ~1Sec
      '
    Config_End
    '
    Symbol SWDTEN = WDTCON.0 ' SW controlled watchdog timer Enable/Disable
    Symbol WD_TO  = RCON.3 ' flag is cleared when WDT times out and set by CLRWDT or SLEEP
    
    
    DreamLand:
        ' power down anything you don't need
        SWDTEN = 1  ' watchdog on
        While 1 = 1
            Sleep
            If INT1IF = 1 Then Break ' wakeup on external intterupt
            '
            If WD_TO = 0 Then ' wakeup on WDT
                GoSub CheckSensor ' check a sensor       
                If sensorval > threshold Than Break
            EndIf
        Wend
        SWDTEN = 0 ' watchdog off
        Return
    '------------------------------------------------
    ' Example using WDT to reset the system if stuck more than 16 Sec in a loop:
    Config_Start
      '
      WDTEN = OFF    ;WDT is controlled by SWDTEN bit of the WDTCON register
      WDTPS = 4096 ; 1:4096 * 4 mS =~16Sec
    Config_End
    '
    TrickyLoop:        
        SWDTEN = 1  ' watchdog on to rest after 16Sec
        Clrwdt ' clears the wdt
        While bytevar > 0
        ' do something in the loop that suposed 
        ' To Result in bytevar = 0
        ' but it is possible that it will be stuck
        ' if after 16 sec. you are still in the loop
        ' there will be a rest
        ' you can use the RCON to determin if the reset was from the WD    
        Wend
        SWDTEN = 0  ' disable watchdog
        Return

  5. #5
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    212
    Thumbs Up
    Received: 6
    Given: 1
    Total Downloaded
    2.23 GB

    0 Not allowed!

    Default Re: Watchdog example

    Thank you very much
    Teo

  6. #6
    Administrator John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,924
    Thumbs Up
    Received: 81
    Given: 25
    Total Downloaded
    1.37 GB

    0 Not allowed!

    Default Re: Watchdog example

    Teo, the enhanced series of 16F chips can have quite long WDT periods - minutes- this can be a real advantage because it doesn't need lots of clrwdt scattered around in the code.
    In one of my projects there are multiple loops and some of them may operate for some seconds but all I need is one clrwdt in the main loop.
    A timeout means a lockup is avoided as is a long excursion up a mountain too. My application is not time critical but it is access critical.
    John

  7. #7
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    212
    Thumbs Up
    Received: 6
    Given: 1
    Total Downloaded
    2.23 GB

    0 Not allowed!

    Default Re: Watchdog example

    Thank you, John
    I have a project that works in a noisy environment.
    I was thinking that if the processor jumps from the program,
    WDT resets the processor and everything starts from the beginning.
    Without WDT processor blocks.

    Can you help me with an example of a SLEEP instruction.
    I have a remote control and if you do not act any key in n sec
    processor to enter sleep.
    If I perform any key, the CPU resets and can use the remote control.
    In this way battery life will increase

    Thanks in advance
    Teo

  8. #8
    Administrator John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,924
    Thumbs Up
    Received: 81
    Given: 25
    Total Downloaded
    1.37 GB

    0 Not allowed!

    Default Re: Watchdog example

    Hi Teo
    I haven't used sleep so can't be of any help yet. I say yet because I'm about to play with sleep for a PIC24HJ project so I can keep a clock alive when power is off. It could be a while before I have it working as there are other projects on the go. When finished I'll share the code but don't hold your breath while you're waiting.
    John

  9. #9
    Prolific Poster hadv215's Avatar
    Join Date
    Sep 2009
    Posts
    1,037
    Thumbs Up
    Received: 85
    Given: 19
    Total Downloaded
    927.31 MB

    0 Not allowed!

    Default Re: Watchdog example

    I have used Sleep, but it was in a program written in assembler.
    With a button connected to an INT pin I could put the device to sleep or wake it up again. Just add an ISR to handle the INT interrupt.
    The program would continue from where it was when being put to sleep, so no restart.
    Of course it's possible to restart the program adding some code.

    Harm

  10. #10
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    212
    Thumbs Up
    Received: 6
    Given: 1
    Total Downloaded
    2.23 GB

    0 Not allowed!

    Default Re: Watchdog example

    Thanks to all
    Teo

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Watchdog timer
    By grahamg in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 15th June 2012, 12:16
  2. WatchDog Timer
    By Peter D in forum Proton Plus Compiler v3
    Replies: 24
    Last Post: 14th February 2012, 12:54
  3. Watchdog Timer
    By geoff_c in forum Proton Plus Compiler v3
    Replies: 0
    Last Post: 19th August 2010, 23:01
  4. Software Watchdog
    By shunt010 in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 26th November 2005, 17:09
  5. Watchdog problem.
    By avpro in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 14th June 2005, 13:00

Members who have read this thread since 4th November 2017, 16:47 : 2

Actions :  (Set Date)  (Clear Date)

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts