Refresh all registers often
I was getting random resets and crashes like you describe but now I always refresh all TRIS, PORT and ADCON, CMCON, etc every time through the main loop or at least once per second.
As processors get smaller, run at lower voltages and faster, the impact of nearby static, lightning, fluoroescent light and electrical motor transients, cosmic rays, etc, etc all get worse.
My code runs over a year now without any hangs after I refreshed as above. The WDT approach is also helpful and can be used to increment a value in EEROM at each hard reset so you can analyse later if you got any WDT events but don't rely just on the WDT to save your code.
HTH
BrianT
Good code & schmitt trigger pins
Thanks for the advice to date.
I'm not clear what use should be made of the Watch Dog timer?
Assume that no activity after X Seconds means something is wrong and re-start? Or is there more to this?
On a new additional subject: ST input pins. Recently I wanted to use the hysterisis of the ST pins and did a test to check the thresholds.
Found that PORTB.0 (used as an interrupt INT0) was way off spec for the chip PIC18F8722:
Go off at 1.6 V
Go on at 2.7 V
The spec gives:
Go off at 1.5 to 1.3 V
Go on at 3.0 to 3.4 V
Test voltages supplied via a 10k pot and measured with a good meter - my new FLUKE! The differences are considerably outside spec. Anyone else had difficulties with the ST pins?
Regards Bill Legge