View previous topic :: View next topic |
Author |
Message |
pilar
Joined: 30 Jan 2008 Posts: 197
|
WDT in PIC18 it's not working |
Posted: Thu Apr 05, 2018 8:04 pm |
|
|
Hi, I am use a PIC18F4620 at 20Mhz and the CCS version 4.074 to I am using the WDT.
As you can see in my code, the WDT is working, the problem is that it does not stop when the setup_wdt(WDT_OFF) command, there are parts of my code that I need to disable and in others enable the WDT but it is not disabled and the WDT keeps running, can someone tell me what my error is?
Code: | #include <18F4620.h>
#fuses HS,WDT32768,PROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)// RS232 Estándar
main() {
switch ( restart_cause() )
{
case WDT_TIMEOUT:
{
printf("\r\nRestarted processor because of watchdog timeout!\r\n");
break;
}
case NORMAL_POWER_UP:
{
printf("\r\nNormal power up!\r\n");
break;
}
}
//setup_wdt(WDT_ON)
setup_wdt(WDT_OFF);
while(TRUE)
{
restart_wdt();
printf("Hit any key to avoid a watchdog timeout.\r\n");
getc();
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 05, 2018 8:25 pm |
|
|
Add NOWDT to your #fuses line. Then you can turn the WDT on and off
by software control. This is in the PIC data sheet. |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Fri Apr 06, 2018 4:12 am |
|
|
If you are having to turn the watchdog on and off then you've got a big design/architecture problem. If you use the watchdog at all, and most people who are using it/having trouble using it on PICs don't need it at all and would be better off without it, then you should turn it on and leave it on. If you keep turning it on and off then you pretty much lose any protection against errant code that it provides. |
|
|
|