Does Swordfish over-ride the configuration settings for the Watchdog timer? I'm trying to run my processor with the watchdog under software control so I set WDTEN = SWON. From the datasheet (PIC18F46K22) this means the watchdog is controlled by the SWDTEN bit which defaults to zero = WDT turned off.
However, I'm finding that I have to use CLRWDT in my start-up code to avoid the processor resetting.
Looking at the fuses in the hex file it does appear that the watchdog is on permanently.
If I try not using #option WDT=true then I get loads of errors for the CLRWDT instructions I've added.
Any ideas?
Use of Watchdog with Swordfish
Moderators: David Barker, Jerry Messina
-
- Posts: 219
- Joined: Wed Sep 11, 2013 1:27 pm
- Location: Chesterfield
-
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Re: Use of Watchdog with Swordfish
The code for handling the WDT is in the module library\system.bas
Once upon a time, the PIC wdt operation was controlled via a 'CONFIG WDT = xxx' fuse setting, and if you look in system.bas you'll see code dealing with a matching '#option WDT' that was used to automatically control it.
Now, Microchip has changed things and depending on the device you may need to use 'config WDT' or 'config WDTEN', so the #option WDT doesn't work for all devices anymore. There is conditional code there for one device showing WDTEN, so you could either add yours to it or just comment out all the code, manage the config yourself, and replace clrwdt() with:
One downside to doing this is the ClrWDT() used to be optimized away if the #option WDT was false, and it won't be anymore. In most places the extra instruction matters little... it's spinning waiting for some hardware event to occur.
Once upon a time, the PIC wdt operation was controlled via a 'CONFIG WDT = xxx' fuse setting, and if you look in system.bas you'll see code dealing with a matching '#option WDT' that was used to automatically control it.
Now, Microchip has changed things and depending on the device you may need to use 'config WDT' or 'config WDTEN', so the #option WDT doesn't work for all devices anymore. There is conditional code there for one device showing WDTEN, so you could either add yours to it or just comment out all the code, manage the config yourself, and replace clrwdt() with:
Code: Select all
Public Inline Sub ClrWDT()
Asm-
ClrWDT
End Asm
End Sub
-
- Posts: 219
- Joined: Wed Sep 11, 2013 1:27 pm
- Location: Chesterfield
Re: Use of Watchdog with Swordfish
Hi Jerry,
Thanks, I can see what is happening now. System.bas is changing the setting I'd put in my main program. I'll explore to see if I can adapt the existing mechanism to support the extra options with the newer watchdog timer, would be better than bypassing the Swordfish mechanism I think.
Thanks, I can see what is happening now. System.bas is changing the setting I'd put in my main program. I'll explore to see if I can adapt the existing mechanism to support the extra options with the newer watchdog timer, would be better than bypassing the Swordfish mechanism I think.
-
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Re: Use of Watchdog with Swordfish
If it helps any, here's how I've modified my system.bas:
Code: Select all
{
****************************************************************************
* Name : ClrWDT *
* Purpose : Clear the watch dog timer *
****************************************************************************
}
//
// Setting this option true will enable blocking routines like delayus() and
// delayms() to include a CLRWDT instruction in the loop. Setting it false
// (which is the default setting if left unspecifed) will result in the routines
// not including a CLRWDT, so long delay calls may result in a watchdog reset
// depending on the wdt timeout settings.
//
#option WDT = false
#if IsOption(WDT) and not (WDT in (true, false))
#error WDT, "Invalid option. WDT must be true or false."
#endif
// v1.3
// This option controls the handling of the previous 'option WDT'.
// The default handling of 'option WDT' is to:
// - enable the config WDT/WDTEN setting if WDT=true,
// - the ClrWDT() sub performs a 'clrwdt' instruction only if WDT=true.
// If you disable the default handling (#option SYSTEM_ENABLE_DEFAULT_WDT = false),
// then the config setting is not touched, and ClrWDT() will always perform a 'clrwdt'
// instruction. This allows for situations where you may not want the config setting
// changed, or you always want to force blocking function to tickle the wdog
//
#option SYSTEM_ENABLE_DEFAULT_WDT = true
// v1.2 WDT vs WDTEN setting
// assume the device uses 'config WDT'
#variable _USE_WDTEN = false
// these 127 devices use WDTEN instead of WDT (MPLAB 8.92)
#if _device in ( _
18F13K22, 18F13K50, 18F14K22, 18F14K50, 18F2331, 18F23K20, 18F23K22, 18F2431, 18F24J10, 18F24J11, _
18F24J50, 18F24K20, 18F24K22, 18F24K50, 18F25J10, 18F25J11, 18F25J50, 18F25K20, 18F25K22, 18F25K50, _
18F25K80, 18F26J11, 18F26J13, 18F26J50, 18F26J53, 18F26K20, 18F26K22, 18F26K80, 18F27J13, 18F27J53, _
18F4331, 18F43K20, 18F43K22, 18F4431, 18F44J10, 18F44J11, 18F44J50, 18F44K20, 18F44K22, 18F45J10, _
18F45J11, 18F45J50, 18F45K20, 18F45K22, 18F45K50, 18F45K80, 18F46J11, 18F46J13, 18F46J50, 18F46J53, _
18F46K20, 18F46K22, 18F46K80, 18F47J13, 18F47J53, 18F63J11, 18F63J90, 18F64J11, 18F64J90, 18F65J10, _
18F65J11, 18F65J15, 18F65J50, 18F65J90, 18F65J94, 18F65K22, 18F65K80, 18F65K90, 18F66J10, 18F66J11, _
18F66J15, 18F66J16, 18F66J50, 18F66J55, 18F66J90, 18F66J93, 18F66J94, 18F66J99, 18F66K22, 18F66K80, _
18F66K90, 18F67J10, 18F67J11, 18F67J50, 18F67J90, 18F67J93, 18F67J94, 18F67K22, 18F67K90, 18F83J11, _
18F83J90, 18F84J11, 18F84J90, 18F85J10, 18F85J11, 18F85J15, 18F85J50, 18F85J90, 18F85J94, 18F85K22, _
18F85K90, 18F86J10, 18F86J11, 18F86J15, 18F86J16, 18F86J50, 18F86J55, 18F86J72, 18F86J90, 18F86J93, _
18F86J94, 18F86J99, 18F86K22, 18F86K90, 18F87J10, 18F87J11, 18F87J50, 18F87J72, 18F87J90, 18F87J93, _
18F87J94, 18F87K22, 18F87K90, 18F95J94, 18F96J94, 18F96J99, 18F97J94 )
#variable _USE_WDTEN = true
#endif // _device
// define macros that use the appropriate config statement for the current device
// these can be used in place of 'config WDT' or 'config WDTEN'
#if (_USE_WDTEN)
public macro CONFIG_WDT_ON()
config WDTEN = on
end macro
public macro CONFIG_WDT_OFF()
config WDTEN = off
end macro
public macro CONFIG_WDT(x)
config WDTEN = x
end macro
#else
public macro CONFIG_WDT_ON()
config WDT = on
end macro
public macro CONFIG_WDT_OFF()
config WDT = off
end macro
public macro CONFIG_WDT(x)
config WDT = x
end macro
#endif
// WDT option
#if (SYSTEM_ENABLE_DEFAULT_WDT)
// default handling
// if WDT option is set, then enable the wdt configuration setting
#if (WDT)
CONFIG_WDT_ON()
#endif
// ClrWDT() execution is based on WDT option
public inline sub ClrWDT()
#if (WDT)
asm
clrwdt
end asm
#endif
end sub
#else // default handling disabled
// don't change configuration setting (may have to change 'config' manually)
// ClrWDT() always executes 'clrwdt'
public inline sub ClrWDT()
asm
clrwdt
end asm
end sub
#endif