View previous topic :: View next topic |
Author |
Message |
jpts
Joined: 08 Mar 2017 Posts: 40
|
Reset watchdog not |
Posted: Wed Jul 19, 2017 10:44 am |
|
|
Why function restart_wdt() its not working...the program below print "START" instead print "running". CCS:5.071
Code: | #include <16F18857.h>
#device ADC=10
#use delay(crystal=20000000)
#FUSES NOBROWNOUT
#FUSES NOLVP
#FUSES WDT
#FUSES NOPPS1WAY
#FUSES STVREN
#FUSES NOMCLR
#PIN_SELECT U1RX=PIN_C7
#PIN_SELECT U1TX=PIN_C6
#use rs232(baud=9600,parity=N,UART1,bits=8,stream=PORT1,errors)
void main()
{
setup_wdt(WDT_4S);
printf ("START\r\n");
while(TRUE)
{
restart_wdt();
delay_ms(1000);
printf ("running\r\n ");
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Wed Jul 19, 2017 11:46 am |
|
|
This device has a windowed watchdog timer. You need to set the window to 100% or it'll only accept a reset that occurs inside the window. The default is 25%, so the reset will only work in the last 25% of the time. A restart_wdt before this, will trigger a watchdog reset!....
Also, have not checked the data sheet, but on many chips you cannot reprogram the watchdog, if it is enabled in hardware. It has to be in software mode to be re-configured. If you want it hardware enabled, the time should also be setup in the fuses. |
|
|
jpts
Joined: 08 Mar 2017 Posts: 40
|
|
Posted: Thu Jul 20, 2017 7:00 am |
|
|
Included " #FUSES WDTWIN_100%, but still same. reset the pic....
if i take out the function restart_wdt(); the program works as expected...its print " Start" after four print running....but when insert funcion restart_wdt(), its only print start directly (not print running)...means that program reset ...
Thanks for any suggestion...Jpts |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Thu Jul 20, 2017 7:06 am |
|
|
Quote: |
the time should also be setup in the fuses
|
Otherwise the default time is only a few mSec. |
|
|
jpts
Joined: 08 Mar 2017 Posts: 40
|
|
Posted: Thu Jul 20, 2017 7:38 am |
|
|
Included, #FUSES WDT4096 but still same....printing only "Start"
My FUSES setup:
#FUSES NOBROWNOUT
#FUSES NOLVP
#FUSES WDT
#FUSES WDT4096
#FUSES NOPPS1WAY
#FUSES STVREN
#FUSES NOMCLR
#FUSES WDTWIN_100% |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Thu Jul 20, 2017 8:17 am |
|
|
4096, will only give a 128mSec timeout. For 4 seconds you need WDT131072.... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Jul 20, 2017 8:54 am |
|
|
He might have misread wdt4096 to be a little over 4 seconds ( 4.096) as opposed to four thousand and ninty six milliseconds... |
|
|
jpts
Joined: 08 Mar 2017 Posts: 40
|
|
Posted: Thu Jul 20, 2017 9:13 am |
|
|
Same result...not working...
Testing, I noticed that function restart_wdt() reset the PIC...if change position in program like below its print "start" followed "running".
Code: |
#FUSES NOBROWNOUT
#FUSES NOLVP
#FUSES WDT
#FUSES WDT131072
#FUSES NOPPS1WAY
#FUSES STVREN
#FUSES NOMCLR
#FUSES WDTWIN_100%
void main()
{
setup_wdt(WDT_4S);
printf ("START\r\n");
delay_ms(100);
while(TRUE)
{
delay_ms(1000);
printf ("running\r\n ");
delay_ms(100);
restart_wdt(); // in this point seems the PIC reset, printing "start" then print "running" ..after 1 sec...repeat print "start" then "running"
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Thu Jul 20, 2017 10:56 am |
|
|
It'll reset the PIC, if you are not inside the window. Suggest the window is not being setup correctly
Try with the fuses set to WDT_SW, and WDTWIN_SW, which then leaves the watchdog software configurable, and with the setup_wdt line:
setup_wdt(WDT_4S | WDT_WINDOW_100_PERCENT ! WDT_ON); |
|
|
jpts
Joined: 08 Mar 2017 Posts: 40
|
|
Posted: Fri Jul 21, 2017 6:02 am |
|
|
Worked..tks.
included the fuses WDT_SW and WDTWIN_SW .
and in main setup_wdt(WDT_4S | WDT_WINDOW_100_PERCENT | WDT_ON);
Regards in my fuses I tooked out #FUSES WDT
Regards, Jpts |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Fri Jul 21, 2017 6:07 am |
|
|
OK. That implies that there must be something wrong in the fuse settings.
Basically the way it works is if the watchdog is configured in the fuses, it is then 'fixed', and can't be changed. Designed for systems that must boot up with the watchdog enabled.
Alternatively you can set the fuses to the software mode, and the watchdog can then be controlled in software (which is what is now working).
So when you selected the window at 100%, and WDT131072, it should have worked. One would have to look in the list file and see what bit is not being set right when this setting is used.
Have just tried, and it is not setting the window, or the division ratio from the fuses, so setting it up in the software is currently the only way to do it.... |
|
|
|