Things have gotten a bit tricky with the WDT over time... devices use different config settings and names.
Depending on how you want things to work, setting the config settings ON and OFF isn't so simple anymore,
You can thank Microchip for that. See my post
hints for using '#const _wdt_type', option WDT, and system for more details... the info here is a rehash of that.
The device files generated by SystemConvert v1.2 try to help with this. I'd recommend rebuilding the device include files with it,
but I've included a converted file for the 18F87J93 in the zip file.
The attached zip file also has replacements for System.bas and wdt.bas. You'll want these as well. It corrects
some of the following limitations:
- There's a hard-coded check in the SF system library System.bas that needs to change
Right now, it only looks for one device
Code: Select all
#if WDT
#if _device in (18F66J16)
Config WDTEN = on
#else
Config WDT = on
#endif
#endif
- The wdt.bas module from
http://www.sfcompiler.co.uk/wiki/pmwiki ... oftwareWDT
needs some adjusting for different devices, so see the attached. Be VERY careful if you want
to change the timeout value in code... you'll have to match the module code/settings to your device.
Here's a test program that you can use to verify the modules with
main_wdt.bas:
Code: Select all
// watchdog test for module wdt.bas
device = 18F87J93
{
// _wdt_type was introduced in device files generated by SystemConvert v1.2
// to help set proper config settings for the WDT, which can vary by device
'#const _wdt_type' can be used to identify the watchdog config type
0 WDT(WDT) = [OFF, ON]
1 WDTEN(WDTEN) = [OFF, ON]
2 WDTEN(WDTEN) = [OFF, NOSLP, SWON, ON]
3 WDTEN(WDTEN) = [OFF, NOSLP, ON, SWDTDIS]
for _wdt_type = 0 (18F4520 SF default device):
config WDT: Watchdog Timer Enable bit
1 = WDT enabled
0 = WDT disabled (control is placed on the SWDTEN bit)
for _wdt_type = 1 (18F14K50):
config WDTEN: Watchdog Timer Enable bit
1 = WDT is always enabled. SWDTEN bit has no effect
0 = WDT is controlled by SWDTEN bit of the WDTCON register
for _wdt_type = 2 (18F2xK22):
config WDTEN<1:0>: Watchdog Timer Enable bits
11 (ON) = WDT enabled in hardware (SWDTEN ignored)
10 (SWON) = WDT controlled by firmware (SWDTEN enabled)
01 (NOSLP) = WDT enabled in hardware, disabled in Sleep mode (SWDTEN ignored)
00 (OFF) = WDT disabled in hardware (SWDTEN ignored)
for _wdt_type = 3 (18F2xK80):
WDTEN<1:0>: Watchdog Timer Enable bits
11 (SWDTDIS)= WDT is enabled in hardware; SWDTEN bit is disabled
10 (ON) = WDT is controlled by the SWDTEN bit setting
01 (NOSLP) = WDT is enabled only while the device is active and is disabled in Sleep mode; SWDTEN bit is disabled
00 (OFF) = WDT is disabled in hardware; SWDTEN bit is disabled
most devices have a register bit SWDTEN somewhere that allows for software control of the wdt...
usually found in WDTCON.bits(0) except for the J94/J99 family where it's RCON2.bits(5)
_wdt_types 0 and 1 are similar, except that the config bit changes names from WDT to WDTEN.
likewise, _wdt_types 2 and 3 are similar except the settings change meanings slightly, esp ON
}
include "wdt.bas" // automatically sets '#option WDT = true for you
// check to see if ClrWDT() produces a 'clrwdt' instruction
// after compiling press F2 to open an asm code window. scroll down to where the code begins
// (or use menu 'Edit | Find' MAIN). Verify that there's a 'clrwdt' instruction generated
// MAIN
// ?I000020_F000_000063_M000000 ; L#MK CLRWDT()
// CLRWDT
ClrWDT()
// check system SBDLYUS16 for clrwdt
// in the asm code window use menu 'Edit | Find' SBDLYUS16
// verify that there's a 'clrwdt' instruction a few instructions before the return
// SBDLYUS16
// <snip>...
// ADDWF 0,1,0
// CLRWDT << verify this is here
// INCFSZ 1,1,0
// BRA $ - 16
// RETURN 0
delayus(100)
// this should call SBDLYUS16 (so it'll include a clrwdt)
delayms(100)
// set register bit SWDTEN wdt enable
// this may not have any effect depending on the config setting
watchdog.enabled = true
// tickle the watchdog
watchdog.reset
// this routine is no longer required... you can use normal DelayMS() calls
watchdog.delay(100)
// change wdog config timeout value
// **IMPORTANT** see the notes in wdt.bas before using this...
// it likely needs changing to match your device
watchdog.postscale(ps1024)