The watchdog timer runs on the internal 31kHz oscillator so it doesn't matter what oscillator speed the CPU runs at.
This PIC also has a WDTCON register you use to set the WDT period with. Take 1/31kHz (0.000032258) and multiply this times the prescaler value in WDTCON for the WDT time period.
If you insert WDTCON = %00010101 this sets bit 0, which enables the WDT, and loads a prescale vaule of 1:32768. This gives you 32768 * 0.000032258 for about a 1.057 second wakeup period.
This PIC allows you to set WDT to off in config, and turn it on/off using bit 0 in WDTCON, so you get even better power savings. I.E. you can enable the WDT only when you need it, then disable it when you don't to save power.
This gives you much better power savings than using the PBP SLEEP command since it sleeps for the whole period, it doesn't wakeup & loop until the timeout period expires, and you only need to enable WDT just before you enter sleep mode.
Here's an example:
Code:
@ __CONFIG _FCMEN_OFF & _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _BOR_OFF & _PWRTE_OFF
DEFINE OSC 8
DEFINE NO_CLRWDT 1 ' PBP doesn't clear WDT automatically
LED VAR PORTB.6 ' LED on RB6
LED = 0 ' LED off at POR
TRISB.6 = 0 ' Make pin an output
OPTION_REG = %10001000 ' Pull-ups off, 1:1 prescaler to WDT
OSCCON = %01110000 ' 8MHz internal osc
Main:
HIGH LED ' Turn on LED
PAUSE 50 ' LED on for ~50mS
LOW LED ' LED off
CLEARWDT
WDTCON = %00010101 ' WDT enabled with a period of 32768 * (1/31kHz)
@ SLEEP ' for a sleep period of about 1.057 seconds
@ NOP ' Execute a NOP on WDT or interrupt wakeup
WDTCON = 0 ' Disable WDT when not needed for power savings.
' WDT is only turned on just before entering sleep
GOTO Main ' Loop forever
END
With brown-out reset and power-up timer disabled you save even more power, but check to make sure your application works properly with both these disabled.
Bookmarks