CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

Watch Dog Timer - delay (setup_wdt) and divisors (Solved)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rajeshkhan808



Joined: 29 Aug 2012
Posts: 17

View user's profile Send private message

Watch Dog Timer - delay (setup_wdt) and divisors (Solved)
PostPosted: Sat Sep 01, 2012 2:01 am     Reply with quote

While going through the code of watch dog timer , I wanted to increase the timeout delay.I am using PIC16F877A.
The code example of CCS uses

Code:
setup_wdt(WDT_2304MS)


However the reference of setup_wdt states
For PCB/PCM parts:
Code:
 WDT_18MS, WDT_36MS, WDT_72MS, WDT_144MS,WDT_288MS, WDT_576MS, WDT_1152MS, WDT_2304MS

For PICĀ®18 parts:
Code:
WDT_ON,  WDT_OFF

For PICĀ®16 parts with software controlled WDT enabled:
Code:
WDT_ON, WDT_OFF, WDT_TIMES_32, WDT_TIMES_64, WDT_TIMES_128, WDT_TIMES_256, WDT_TIMES_512, WDT_TIMES_1024, WDT_TIMES_2048, WDT_TIMES_4096, WDT_TIMES_8192, WDT_TIMES_16384, WDT_TIMES_32768, WDT_TIMES_65536

How can I raise the timeout setting to 4 seconds ? also could anyone explain how the concept of divisors are working here ?


Last edited by rajeshkhan808 on Mon Sep 03, 2012 8:04 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 6230

View user's profile Send private message

PostPosted: Sat Sep 01, 2012 3:20 am     Reply with quote

You can't.

The basic period of the watchdog on your chip is a nominal 18mSec. However you need to understand first, just how 'nominal' this is. Data sheet table 17-5. Max=33mSec, min=7mSec. So the '18', can vary by nearly 5:1....

Then this has eight selectable divisors, of 1,2,4,8,16,32,64 & 128.
Now look at the times offered by the fuses. What is 18*128?. 2304mSec. The eight options you have, correspond to the eight possible divisors. So 2304mSec (896mSec to 4224mSec), is the maximum time available. Now on some chips with some supplies, this will get to 4sec (4224mSec), but on others, it'll be under 1 second....

You can make an effective watchdog at _any_ interval you want, by using a 'tick' interrupt. So something like:
Code:

int8 watchdog;
#define 4SECONDS (200)

#int_timer2
void tick(void) {
    //run this at (say) 50* per second
    if (watchdog) {
       restart_wdt();
       --watchdog;
    }
}


If you then set the watchdog up to use WDT_72MS, and instead of using restart_wdt in your code, use "watchdog=4SECONDS", then the counter will timeout, just over four seconds, and the watchdog will trigger between 52, and 132mSec latter.

Now I selected WDT_72MS, since this is the fastest watchdog setting _guaranteed_ to not timeout in less than the 20mSec between interrupts (worst case 28mSec for it's timeout). Obviously you'd need to adjust this to suit whatever 'tick' frequency you select.

If (for example), you wanted to sleep, and use the watchdog to wake, and give a 4 second time, then you'd need to simply sleep twice, so 2304mSec, becomes 4608mSec. However with the massive tolerance of the wachdog, with some systems you will get under 2 seconds, while with others over 8 seconds....

Best Wishes
Mike Walne



Joined: 19 Feb 2004
Posts: 1345
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Sep 01, 2012 3:29 am     Reply with quote

It's all in the microchip data sheet.

The watch dog timer (WDT) has a nominal 18ms period.

The WDT prescaler is shared with Timer0 on the PIC16F877A

When assigned to the WDT, the nominal WDT period increases in factor of 2 steps from 18ms to 2304ms.

These periods correspond with the CCS setup values.

Mike
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 747
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Sat Sep 01, 2012 3:55 pm     Reply with quote

Posting questions here might seem like a short cut to the poster in that the poster doesn't have to do much ...like read a datasheet , learn C or look up CCS special functions.
Some will choose to spoon feed these questioners others may not but the risk is the board becomes so pedestrian that the experts who have learned to drive will just pass by this board without stopping to answer questions.
Since beginner questions have a high probability of having been asked and answered it is the responsibility of the newcomer to search for these answers. The search button isn't broken.
bkamen



Joined: 07 Jan 2004
Posts: 1472
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sat Sep 01, 2012 5:09 pm     Reply with quote

Douglas Kennedy wrote:
Posting questions here might seem like a short cut to the poster in that the poster doesn't have to do much ...like read a datasheet , learn C or look up CCS special functions.
Some will choose to spoon feed these questioners others may not but the risk is the board becomes so pedestrian that the experts who have learned to drive will just pass by this board without stopping to answer questions.
Since beginner questions have a high probability of having been asked and answered it is the responsibility of the newcomer to search for these answers. The search button isn't broken.


Yep - I would have to admit to suffering from that.

I see so many posts that are so simple to find in the datasheet that they detract from my desire to visit the forum just to see similar questions clogging/obscuring the more interesting ones.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group