View previous topic :: View next topic |
Author |
Message |
Tagge
Joined: 23 Aug 2005 Posts: 93
|
WDT on a PIC12F635 |
Posted: Tue Oct 11, 2011 5:57 am |
|
|
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? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19536
|
|
Posted: Tue Oct 11, 2011 7:03 am |
|
|
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
|
|
Posted: Tue Oct 11, 2011 7:58 am |
|
|
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 |
|
|
|