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... ;-)
Bookmarks