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 support@ccsinfo.com

WDT on PIC18F47K40

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



Joined: 19 Dec 2014
Posts: 23

View user's profile Send private message

WDT on PIC18F47K40
PostPosted: Thu Aug 19, 2021 7:25 am     Reply with quote

Hi all,
I can't seem to find any explanation on how to use the various fuses and functions associated with e WDT on the PIC1847K40.
None of the CCS WDT examples shows the use of these.

Fuses:
WDT64.... ,WDTSW,NOWDT,WDT_SW,WDT_NOSL,WDT,WDTWIN_12%....
WDTWIN_SW,WDTCLK_LFINTRC,WDTCLK_HFINTRC
,WDTCLK_SW

Function:
void setup_wdt(int16 mode) with the following parameters:
WDT_ON
WDT_OFF

WDT_2S
WDT_WINDOW_100_PERCENT

WDT_CLK_31000
WDT_CLK_31250


If I wanted, for example to enable the WDT with a reset time of 2 seconds.
Do I use the fuses like:
#fuses WDT,WDT1024,WDTWIN_100%
or do I set this up using the setup_wdt function like:
setup_wdt(WDT_2S | WDT_WINDOW_100_PERCENT);

I tried all sort of combinations, but none of them seems to work for me...


Any help would be greatly appreciated.
Laurent
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Aug 19, 2021 8:00 am     Reply with quote

The first key document is the data sheet. This chip has a 'windowed'
watchdog timer. With this if the widow is enabled. the restart_wdt will
only work if it is inside the window. Generally it will behave like the
traditional watchdog if you use WDTWIN_100%.

Then look in the file fuses.txt. This tells you how the CCS fuse names
relate to the actual settings.

Now some things can't happen. If you enable the watchdog in the fuses,
then WDT_ON and WDT_OFF won't work. If it is enabled in the fuses there
is no software control.
So if you want software control, the fuses have to select just WDT_SW.

If you are setting up with the fuses, then you have to specify the division
ratio you want.

What can be used in the fuses are only the values given in the fuses
section of the include file. Not the settings for the software setup.

With the software setup, you can setup the watchdog with a time, and
the compiler will then automatically set the division ratio to give this time
_in the fuses_.

Now for your fuses one. wdt1024, will give you a timeout at 32mSec. For
2 seconds, you need wdt65536. Remembering that if this is setup in
the fuses, it starts straight away, your chip will probably reset before
your boot is finished.

For the software setup, you can just use:
setup_wdt(WDT_2S | WDT_WINDOW_100_PERCENT);

as you show. However remember at this point the watchdog is not enabled.
You then need:

setup_wdt(WDT_ON);
To actually start the watchdog.
RNR107



Joined: 19 Dec 2014
Posts: 23

View user's profile Send private message

PostPosted: Thu Aug 19, 2021 8:54 am     Reply with quote

Hi Ttelmah,
Thank you very much for your explanation!

Now, I tryed this simple piece of code:

//#########################################
#INCLUDE "18f47K40.h"
#FUSES HS,WDT_SW,WDTWIN_SW,NOPROTECT,NOPUT,BROWNOUT,NOLVP,MCLR,NOPPS1WAY

#USE delay(clock=64MHz,crystal=16MHz)

#PIN_SELECT U1RX = PIN_C7
#PIN_SELECT U1TX = PIN_C6
#USE rs232(baud=57600, UART1, errors, RESTART_WDT, stream=to_Screen) // xmit=PIN_C6,rcv=PIN_C7


void main(void)
{

setup_wdt(WDT_2S | WDT_WINDOW_100_PERCENT);
setup_wdt(WDT_ON);

fprintf(to_Screen," Start ");

while(TRUE)
{
fprintf(to_Screen,"M");
delay_ms(500);
}
}

//##########################################

I was expecting the WTD to reset the PIC, but it doesn't...
alan



Joined: 12 Nov 2012
Posts: 349
Location: South Africa

View user's profile Send private message

PostPosted: Thu Aug 19, 2021 12:51 pm     Reply with quote

I suspect that this
Code:
RESTART_WDT
in your RS232 declaration restarts the watchdog when you use printf
temtronic



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

View user's profile Send private message

PostPosted: Thu Aug 19, 2021 7:05 pm     Reply with quote

also don't expect the WDT to be exactly 2.000000 seconds.
Historically the WDT has been a 'rough' value. Had a quik look at the datasheet and couldn't find real numbers, just a 'typical' 31KHZ without +- range......the spec, is at 3.oo Vdd though.

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 19, 2021 7:29 pm     Reply with quote

RNR107 wrote:

void main(void)
{
setup_wdt(WDT_2S | WDT_WINDOW_100_PERCENT);
setup_wdt(WDT_ON);


In your code above, the 2nd line cancels the parameters in the 1st line.
The setup_wdt() function does not operate sequentially. All parameters
must be in one function call.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Aug 20, 2021 12:21 am     Reply with quote

It doesn't on the code I have, for WDT_ON and WDT_OFF.

It does for all the setting parameters. These work to actually setup the
fuses for the timing required, but WDT_ON and WDT_OFF work separately
from the timing parameters. I have code that starts and stops the watchdog
with these in multiple places and they have always worked perfectly.
RNR107



Joined: 19 Dec 2014
Posts: 23

View user's profile Send private message

PostPosted: Fri Aug 20, 2021 12:30 am     Reply with quote

Thanks Alan!
Well spotted mate! 👌
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Aug 20, 2021 12:53 am     Reply with quote

Have just checked, and can confirm that WDT_ON, and WDT_OFF do work
independently of the timing parameters. All these do is set and clear the
software WDT bit.
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