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

Reset watchdog not

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



Joined: 08 Mar 2017
Posts: 40

View user's profile Send private message

Reset watchdog not
PostPosted: Wed Jul 19, 2017 10:44 am     Reply with quote

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: 19539

View user's profile Send private message

PostPosted: Wed Jul 19, 2017 11:46 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 20, 2017 7:00 am     Reply with quote

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: 19539

View user's profile Send private message

PostPosted: Thu Jul 20, 2017 7:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 20, 2017 7:38 am     Reply with quote

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: 19539

View user's profile Send private message

PostPosted: Thu Jul 20, 2017 8:17 am     Reply with quote

4096, will only give a 128mSec timeout. For 4 seconds you need WDT131072....
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jul 20, 2017 8:54 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 20, 2017 9:13 am     Reply with quote

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: 19539

View user's profile Send private message

PostPosted: Thu Jul 20, 2017 10:56 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jul 21, 2017 6:02 am     Reply with quote

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: 19539

View user's profile Send private message

PostPosted: Fri Jul 21, 2017 6:07 am     Reply with quote

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....
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