View previous topic :: View next topic |
Author |
Message |
RNR107
Joined: 19 Dec 2014 Posts: 23
|
WDT on PIC18F47K40 |
Posted: Thu Aug 19, 2021 7:25 am |
|
|
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: 19495
|
|
Posted: Thu Aug 19, 2021 8:00 am |
|
|
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
|
|
Posted: Thu Aug 19, 2021 8:54 am |
|
|
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: 357 Location: South Africa
|
|
Posted: Thu Aug 19, 2021 12:51 pm |
|
|
I suspect that this in your RS232 declaration restarts the watchdog when you use printf |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Thu Aug 19, 2021 7:05 pm |
|
|
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
|
|
Posted: Thu Aug 19, 2021 7:29 pm |
|
|
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: 19495
|
|
Posted: Fri Aug 20, 2021 12:21 am |
|
|
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
|
|
Posted: Fri Aug 20, 2021 12:30 am |
|
|
Thanks Alan!
Well spotted mate! 👌 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19495
|
|
Posted: Fri Aug 20, 2021 12:53 am |
|
|
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. |
|
|
|