Two watchdod timers enabled?

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Post Reply
yllis
Posts: 10
Joined: Wed Feb 23, 2011 10:18 am
Location: Finland

Two watchdod timers enabled?

Post by yllis » Sun May 25, 2014 9:04 am

I am building a device that is supposed to work on its own for a couple of a months in a row. I mean that I can not over see its operation. I am a bit worried that my program should run for such a long time without getting stuck somewhere. Now I know that watchdog timer (WDT) can be used to ensure that the code will not get stuck, but my problem is that I am already using one WDT. I am not sure if there can be two WDTs used at the same time.
If it is possible, how would the code loo like if there was two WDTs enabled?

My very simple program code is below. I would like to know if you think that the second WDT would be useful in this case.

Code: Select all

Device = 18F13k22
Clock = 2
Config FOSC = Irc                      'tells the chip to use its internal oscillator
 
'---Set-up Watchdog timer
Config WDTPS = 32768               'WDT period = 4ms x 32768 = 131.072 s
Config WDTEN = ON                      

Dim LoopNumber As Integer

'---Enable sleep mode etc.
OSCCON = %01001100

Low(PORTA.2)
Low(PORTA.5)
LoopNumber = 0
  
'---Main Program Loop
 
While True                  
    LoopNumber = LoopNumber + 1

    If LoopNumber <= 330 Then	        '330 x 131.072s  = 12h 0min 53.76s
	    Asm                                       'Put PIC to sleep for 2.18 mins
	        sleep
	    End Asm
    EndIf

    If LoopNumber > 330 Then   
        High(PORTA.5)
        DelayMS(5000)
	Low(PORTA.5)
        LoopNumber = 0
    End If
Wend

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Two watchdod timers enabled?

Post by Jerry Messina » Sun May 25, 2014 5:49 pm

There's only a single WDT in the pic hardware, so you don't really have a choice of using two.

If you get a timeout during the SLEEP instruction, the pic will wake up and continue operation.
If the WDT timeout occurs anywhere else, the device will reset and the program will restart.

Post Reply