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

Determining WDT timeout period

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



Joined: 19 Sep 2018
Posts: 15

View user's profile Send private message

Determining WDT timeout period
PostPosted: Thu Dec 06, 2018 4:05 am     Reply with quote

I'm using the CCS compiler v5.081 with the PIC1857K42.

I use the following instruction:
Code:

setup_wdt(WDT_ON);


How can I determine what the time out period with this specific instruction? What registers does setup_wdt affect?

WDT_ON is defined in this way:
Code:

#define WDT_ON                  0x8000


I also tried the following instruction, instead of WDT_ON:

Code:

setup_wdt(WDT_8S);


But this instruction caused my procesor to restart, at a much faster rate than 8 seconds. That's why I use WDT_ON.

If I print the cause with this line, at the very start of the main method:
Code:

printf("\r\n Restart cause: %x\r\n", restart_cause());

I get 0x1f. I don't know what this value means. I'm not sure if I'm facing faulty behaviour from the compiler and if I should CCS support for this issue.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Dec 06, 2018 4:49 am     Reply with quote

Series of things. setup_wdt(WDT_ON), only works if you have the fuses set
to support software enabling of the WDT. If the WDT is hardware enabled or
disabled, it can't be controlled by this instruction. So WDT_SW, needs to
have been set in the fuses to use this.

If you look at the header file for your chip, there will be another set of #defines for this instruction, where it configures the time. So (for example):
Code:

// Constants used for SETUP_WDT() are:
// Only use one of the following to turn WDT On or Off
#define WDT_ON                  0x8000
#define WDT_OFF                 0x0000

// Or use one of the following to enable WDT and set timeout time
#define WDT_1MS                 0x0001
#define WDT_2MS                 0x0003
#define WDT_4MS                 0x0005
#define WDT_8MS                 0x0007
#define WDT_16MS                0x0009
#define WDT_32MS                0x000B
#define WDT_64MS                0x000D
#define WDT_128MS               0x000F
#define WDT_256MS               0x0011
#define WDT_512MS               0x0013
#define WDT_1S                  0x0015
#define WDT_2S                  0x0017
#define WDT_4S                  0x0019 
#define WDT_8S                  0x001B
#define WDT_16S                 0x001D
#define WDT_32S                 0x001F
#define WDT_64S                 0x0021
#define WDT_128S                0x0023
#define WDT_256S                0x0025

// One of the following may be OR'ed in with the above using |
#define WDT_WINDOW_12_PERCENT   0x0000
#define WDT_WINDOW_25_PERCENT   0x0100
#define WDT_WINDOW_37_PERCENT   0x0200
#define WDT_WINDOW_50_PERCENT   0x0300
#define WDT_WINDOW_62_PERCENT   0x0400
#define WDT_WINDOW_75_PERCENT   0x0500
#define WDT_WINDOW_87_PERCENT   0x0600
#define WDT_WINDOW_100_PERCENT  0x0700

// One of the following may be OR'ed in with the above using |
#define WDT_CLK_31000           0x0000
#define WDT_CLK_31250           0x1000

#bit WDTSTATE = getenv("SFR:WDTTMR").2



So using:

setup_wdt(WDT_4S); will enable the watchdog, and set the nominal time to
4 seconds.

The times available depend on your chip.

The setup_wdt(WDT_ON); instruction just turns on the enable bit, without
changing the time. The time it gives will depend on the default for your
chip (in the data sheet), or if anything else has already set a time (an
earlier setup_wdt, or fuses for example).

Beware though that the 'times' can be very nominal. On some chips the
actual accuracy is very low. So a chip can have a 'nominal' default WDT
period of 18mSec, but this will give times between perhaps 7, and 28mSec
depending on the physical chip, temperature etc.. I think yours is one where
the accuracy reasonable though..
However the times will depend on what clock source you select (31000 or
31250 Hz).

Beware also that your chip supports the windowed WDT. So the window has
to either be disabled, or a restart_wdt will not be accepted unless it is inside
the 'window'. So:

setup_wdt(WDT_ON | WDT_WINDOW_100_PERCENT | WDT_1S);

Gives the watchdog set to use 1 second, without the window, and enables
the watchdog.

You can set the time, and the window, in the fuses.

WDTWIN_100%

In the fuses, the time is as a division factor, so the equivalent of the '1s'
setting would be:

WDT32768
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Thu Dec 06, 2018 7:40 am     Reply with quote

Hmm, in the header file for your PIC:
Code:
#define NORMAL_POWER_UP       0x73C
#define BROWNOUT_RESTART      0x73E
#define MCLR_FROM_SLEEP       0x637
#define WDT_TIMEOUT           0x52F
#define WDT_FROM_SLEEP        0x43F
#define INTERRUPT_FROM_SLEEP  0x63F
#define MCLR_FROM_RUN         0x737
#define RESET_INSTRUCTION     0x73B
#define STACK_OVERFLOW        0x7BF
#define STACK_UNDERFLOW       0x77F
#define WDT_WINDOW_VIOLATION  0x71F
#define MEMORY_VIOLATION      0x33F


There's nothing that has the 0x1F that you say you got, but 0x71F means watchdog window violation, which seems related to what you've got. It could be because you're only using the %x format specifier instead of %lx.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Dec 06, 2018 8:31 am     Reply with quote

Key thing is the window.

If he is enabling the watchdog, it _will_ restart. The window defaults to
it's minimum setting, so 'restart_wdt', won't hit the window, unless he is very
lucky...
Issuing a restart_wdt _outside_ the window, results in an immediate
restart.
This is what he is getting.
He needs to set the window, either in the fuses or in the software (with the
fuse set to allow this).
nickdc



Joined: 19 Sep 2018
Posts: 15

View user's profile Send private message

PostPosted: Thu Dec 06, 2018 1:35 pm     Reply with quote

Thanks for your replies. I'm always very impressed by the level of knowledge on this forum. As a programmer that recently joined the workforce, it makes me wonder how one assimilates that kind of facility with closed-source compilers in combination with some processor(obviously experience is a factor).

CCS offers nice directives, but having intimate knowledge of your processor seems to me necessary. One should be able to code it in XC8, for instance. Otherwise, you're stuck in trial-and-error mode, trying different permutation of the configuration.
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