Quote Originally Posted by flotulopex View Post
Well, after some readings today, I thought I would have won this challenge easely on my own, but... still searching my way in the myst after hours.

Here is my simple test code:
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
OPTION_REG   = %00001111    'enable PORTB pullups, prescaler to WDT, rate 1:128 
WDTCON       = %00010111    'Prescaler 1:65536, WDT ON

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

'-------------------------------------------------------------------------------
' Program
MAIN:
    if STATUS.4 = 0 then    'a WDT Time-Out occured
        CLEARWDT            'clear Watchdog Timer
        toggle LED1
    endif
    goto main

end
On the top of this, pre- & postscalers are not clear to me, even after reading the datasheet 3 times (must be my poor english... and my math too).

A.- The prescaler rate is set in the OPTION_REG bits 2-0. Am I right to say that this prescaler becomes the postscaler when affected to WDT (OPTION_REG.3=1)?

B.- At 4MHz, 1 Tosc is about 1µs. Shall I understand that, if my program would work, my LED should toggle every 128x65536=8'388'608µs=8,388...seconds? I feel this is wrong, but I don't know why.

C.- Should I handle the WDT as an interrupt and make a routine for this (reading the datasheet it looks not to be the case, but...)?

D.- In several block diagrams, I noticed that the WDT uses the 31,25kHz osc freq. Does this mean I have to set my oscillator to 31,25kHz (I tried this - doesn't make it better working)?

My brain needs a break; going for some dishwashing... ;-)
A) Yes, that particular divider unit is a prescaler for TMR0 and a postscaler for WDT, assignable to either TMR0 or WDT, not both (actually, it can be, but that's beside the point for now).

B) WDT is driven by internal (nominal) 31.25Khz clock source. 1/31250 = 32us... 32us * 128 * 65536 = 268.435456 seconds, 4minutes+28.36992seconds.

C) A WDT timeout does one of two things: Either it wakes a PIC up from SLEEP (section 15.13.1) in which case it will start execution at the instruction following the SLEEP, or it'll do a PIC RESET (Table 15-2, 15-3 and 15-4).

D) WDT clock is an independant clock source (section 15.12.1