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 CCS Technical Support

16F887 watchdog timer problem

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



Joined: 15 Dec 2006
Posts: 109

View user's profile Send private message

16F887 watchdog timer problem
PostPosted: Mon Aug 19, 2013 6:26 am     Reply with quote

Hi All,

Controller: 16F887
CCS version: 4.140

Having trouble with the code below, Watchdog timer setting is a problem,
watchdog timer works only if i just use fuse WDT and no other setting in the code.
If i use the code setup_wdt(WDT_2304MS); watchdog timer does not work.
Please can somebody help.

Thanks and Regards,
jai.

MAIN.H
Code:

#include <16F887.h>
#device ADC=16

#FUSES INTRC_IO
#FUSES WDT                      //Watch Dog Timer
#FUSES BROWNOUT               //No brownout reset
#FUSES BORV40
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(internal=4000000, restart_wdt)


MAIN.C
Code:

void main()
{
   int8 rCause;
   
   rCause = 0;
   tsec = 0;
   tmin = 0;
   thrs = 0;
   sTick = 0;
   setup_oscillator(OSC_4MHZ);
   //setup_wdt(WDT_2304MS);  //ONLY WORKS IF COMMENTED OUT
   setup_timer_1(T1_EXTERNAL|T1_CLK_OUT|T1_DIV_BY_1);
   set_timer2(16);
   setup_timer_2 (T2_DIV_BY_4, 1, 1);
   rCause = restart_cause();
   enable_interrupts(INT_TIMER2);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);

   while(TRUE)
   {
    if (input(PIN_D0) == 1) {restart_wdt();}
    if (tmin == 1) {tmin = 0; output_toggle(PIN_D1);}
    if (rCause == WDT_TIMEOUT) {output_high(PIN_D3);}
      //TODO: User Code
   }

}
jaikumar



Joined: 15 Dec 2006
Posts: 109

View user's profile Send private message

PostPosted: Mon Aug 19, 2013 6:46 am     Reply with quote

Hi All,

It works only when you use setup_wdt(WDT_TIMES_64);
with the constants below:

#define WDT_TIMES_1 0x900 // Default
#define WDT_TIMES_2 0xB00
#define WDT_TIMES_4 0xD00
#define WDT_TIMES_8 0xF00
#define WDT_TIMES_16 0x1100
#define WDT_TIMES_32 0x1300
#define WDT_TIMES_64 0x1500
#define WDT_TIMES_128 0x1700

Can some one please explain.

regards,
Jai.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Aug 19, 2013 6:55 am     Reply with quote

From the header file:
Code:
// Watch Dog Timer Functions: SETUP_WDT() or SETUP_COUNTERS() (see above)
//                            RESTART_WDT()
// WDT base is 18ms
//

#define WDT_18MS        8   
#define WDT_36MS        9   
#define WDT_72MS       10   
#define WDT_144MS      11   
#define WDT_288MS      12   
#define WDT_576MS      13   
#define WDT_1152MS     14   
#define WDT_2304MS     15   

// One of the following may be OR'ed in with the above:

#define WDT_ON             0x4000   
#define WDT_OFF            0       
so, your line for configuring the watchdog
Code:
setup_wdt(WDT_2304MS);
is the same as:
Code:
setup_wdt(WDT_2304MS | WDT_OFF);
Makes sense that the WD isn't working then.

Not tested, but try:
Code:
setup_wdt(WDT_2304MS | WDT_ON);
jaikumar



Joined: 15 Dec 2006
Posts: 109

View user's profile Send private message

PostPosted: Mon Aug 19, 2013 7:02 am     Reply with quote

Thanks for the help.

But that does not work.

Does not work - setup_wdt(WDT_2304MS | WDT_ON);

Works - setup_wdt(WDT_ON | WDT_TIMES_128);

regards,
Jai.
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Mon Aug 19, 2013 7:54 am     Reply with quote

Get rid of your interrupt code.

You are potentially interrupting every eight instructions. The effect on overall behaviour will make it difficult to find out what is really happening.

You are setting timer2, to clock off the (FOSC/4)/4. One clock every four instructions, and then setting it to reset on a count of '1', and interrupt every time.

Start with just the watchdog code.

I've just tested:
setup_wdt(WDT_2304MS | WDT_ON);

and it is correctly watch-dogging, with your compiler version, and chip.

I'd suspect something like you have a delay in the interrupt handler, and this is preventing the watchdog from triggering with most settings....

Best Wishes
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