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

WDT on a PIC12F635

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



Joined: 23 Aug 2005
Posts: 93

View user's profile Send private message Visit poster's website

WDT on a PIC12F635
PostPosted: Tue Oct 11, 2011 5:57 am     Reply with quote

Hi, I'm having trouble to get the WDT to work on a 12F635. What am I doing wrong?
Code:

#FUSES WDT                        //WDT on
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPD                    //No EE protection
#FUSES MCLR                     //Master Clear pin enabled
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES PUT                      //Power Up Timer
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOWURE                   //Wake-up and continue
#FUSES BROWNOUT                 //Reset when brownout detected
#use delay(clock=31000, restart_wdt)


void init(void){
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32); 
   setup_wdt(WDT_2304MS);
   setup_timer_1(T1_DISABLED);
   setup_comparator(NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_31KHZ);
   }
then in main
while(1){   
      restart_wdt();
      do my thing..
}

Where's the stupidity of mine? Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19536

View user's profile Send private message

PostPosted: Tue Oct 11, 2011 7:03 am     Reply with quote

It might help if you told us what is wrong....

However, key thing with most of the smaller PIC's, is that parts of the prescaler are _shared_ between Timer0, and the WDT. So changing one affects the other. So selecting WDT_2304MS, will set the RTCC prescaler to RTCC_DIV_256. Use the watchdog _postscaler_ instead, which can be independently set.

Best Wishes
Tagge



Joined: 23 Aug 2005
Posts: 93

View user's profile Send private message Visit poster's website

PostPosted: Tue Oct 11, 2011 7:58 am     Reply with quote

Thanks, its just the problem.. you nailed it exactly. It seems that the timer 0 is depending on the WDT scaler.
This seems to get it working better.
Code:

void init(void){
   setup_wdt(WDT_18MS|WDT_TIMES_1);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);   
   setup_timer_1(T1_DISABLED);
   setup_comparator(NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_31KHZ);
   output_low(air_valve);//renblĂ„sning off 
   output_high(air_led);
}

/Tagge
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