I'll try this one.
But what is the Watchdog exactly ment for? I thought it is some kind of internal controlling timer.
Why wouldn't I use a "timer" to do this job? There are 3 available timers in 16F88...
I'll try this one.
But what is the Watchdog exactly ment for? I thought it is some kind of internal controlling timer.
Why wouldn't I use a "timer" to do this job? There are 3 available timers in 16F88...
Roger
A watchdog timer is used when the program running 'goes nuts'. When it's running, you have to periodically reset the WDT. If you don't reset it, the WDT will execute a processor reset.
There is 3 timers available, but they all use power to run them. The WDT uses a lot less power, even though it's not quite as accurate.
Check your PBP and/or PIC manual for the CLRWDT instruction. It should become clear as mud to ya.![]()
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: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).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
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... ;-)
Roger
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:If I use SLEEP instead of NAP, I can set up the sleeping time up to more than 18 hours.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
It looks as the pre- or postscaler don't affect the sleep period... (?)
I'm completely lost....
Last edited by flotulopex; - 4th January 2007 at 17:35.
Roger
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.
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
Thank you Skimask,
I have now put a "SLEEP 10" command in my main loop to make some tests.
When I change the prescaler values in OPTION_REG, nothing changes; the SLEEP time stays around 10 seconds.
When I now activate the WDTCON register (with OPTION_REG) and put the prescaler to 1:32, my LED blinks almost every half second. Setting the rate at 1:64 doubles the 'pause' delay.
A.- Why is the prescaler in OPTION_REG not affecting the SLEEP time?
B.- According to all datasheets, it is not reliable to use WDT since the time may vary in an important scale. What is then the best way to make long delays with the PIC?
Roger
a) not sure, my best guess is that PBP handles it for you behind the scenes. Check your .lst file to see what's really happening.
b) WDT has about +/- 15% tolerance on the clock. If you want 15 minutes, you'll get between 12m45s to 17m15s, generally you'll usually be a lot closer than that. See Section 15.13.1, use Timer1 with an external crystal (2 crystals total, one for PIC, one for Timer1), but that option uses a bit more power.
Thanks a lot Skimask for your support.
I'm going to try with TMR1.
A little more power is maybe worth the precision gain.
Thank you.
Roger
Bookmarks