Quote Originally Posted by flotulopex View Post
I really need some help on this one. Does anybody have a code sample using Watchdog timer?

I read the "Watchdog Timer Operation" datasheet, but it is still not very clear to me.

Here is my piece of code (that works) when I don't use the WDTCON postscaler:
Code:
' Fuses
@ DEVICE PIC16F88,INTRC_OSC_NOCLKOUT,PROTECT_OFF,WDT_ON,PWRT_ON,MCLR_ON
@ DEVICE PIC16F88,BOD_ON,LVP_OFF,CPD_OFF,DEBUG_OFF,CCPMX_OFF

'-------------------------------------------------------------------------------
' Register settings
OSCCON       = %01100000    'Internal RC set to 4MHZ
ANSEL        = %00000000    'Disable Analogue Inputs
OPTION_REG   = %00000111    'enable PORTB pullups, prescaler to WDT, rate 1:128
'WDTCON       = %00000001    'Prescaler 1:32, WDT ON

'-------------------------------------------------------------------------------
' Init
LED1 var PORTB.0

'-------------------------------------------------------------------------------
' Program
MAIN:
    toggle LED1
    NAP 7
    goto main

end
If I use SLEEP instead of NAP, I can set up the sleeping time up to more than 18 hours.

It looks as the pre- or postscaler don't affect the sleep period... (?)

I'm completely lost....


Then keep it simple and use sleep and nap. They're already there for you to use and they power down the PIC to save battery power. They're totally WDT driven and don't rely on the PIC system clock (i.e. 4mhz, 20mhz, whatever). So you can set your register options for the slowest possible clock speed, wait for the sleep/nap to finish, do some checks or whatever, then when the time is right, crank up the clock speed and go.