Hi all, I am using a 16F88 in an application. Every once in a while it freezes up for no apparent reason. I think that this condition can be detected and a reset can be initiated by the watchdog timer. I do not have a clue as how to do this, can some one give me an idea how? Thanks, in advance. Ed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You need to enable the WDT. On the PIC not 100% sure (without reading the docs) , but I would think you can set a max time for the WDT (not sure might be fixed and type of reset), if not, either way you have so much time to hit the WDT. If you do not hit it in said time, the chip restarts in some way. So you need hits to WDT all over your code before it times out otherwise a restart.
To try to avoid all the hits to the WDT in your code, maybe you can use an "on interrupt" with a timer maybe and hit it, but I would make sure the PC (program counter) does not match each time in the event you code locks in a loop somewhere but the "on interrupt" part is still running fine.
I would have to do some googleing and reading to give you a better answer, but this should help you get started. Or spark your threads interest by others. Google for "WDT pic microcontroller example" maybe.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ihatch,
Thank you for the reply. Here is what I have learned:
First enable the WDT with #Config WDT = On.
The WDT runs on the internal 31Khz Oscillator.
Set the WDT delay time by setting WDTPS<3.0>.
Maximum delay is 1:65536 when WDTPS is <1011>.
This results in a delay of about 2.11 seconds.
This can be extended to about 270 seconds by using the Postscaler.
Set PSA = On and set PS<2.0> to 111.
Using the WDT can cause problems if you are using long delays, I have delays of 15 minutes to 1 hour in my code. You have to “kick the dog” by issuing a CLRWDT command before the WDT times out. Here is how I handled the long delays:
Sub LongDelay ’15 min delay
Repeat 900
DelayCount = +=1
wait 1 sec
CLRWDT
End Repeat
Return
I have not tested the code yet, I will report back when I have. I am out of town for a few days.
Best regards, Ed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all, I am using a 16F88 in an application. Every once in a while it freezes up for no apparent reason. I think that this condition can be detected and a reset can be initiated by the watchdog timer. I do not have a clue as how to do this, can some one give me an idea how? Thanks, in advance. Ed.
ED,
WDT in general from my old memory..
You need to enable the WDT. On the PIC not 100% sure (without reading the docs) , but I would think you can set a max time for the WDT (not sure might be fixed and type of reset), if not, either way you have so much time to hit the WDT. If you do not hit it in said time, the chip restarts in some way. So you need hits to WDT all over your code before it times out otherwise a restart.
To try to avoid all the hits to the WDT in your code, maybe you can use an "on interrupt" with a timer maybe and hit it, but I would make sure the PC (program counter) does not match each time in the event you code locks in a loop somewhere but the "on interrupt" part is still running fine.
I would have to do some googleing and reading to give you a better answer, but this should help you get started. Or spark your threads interest by others. Google for "WDT pic microcontroller example" maybe.
Ihatch,
Thank you for the reply. Here is what I have learned:
First enable the WDT with #Config WDT = On.
The WDT runs on the internal 31Khz Oscillator.
Set the WDT delay time by setting WDTPS<3.0>.
Maximum delay is 1:65536 when WDTPS is <1011>.
This results in a delay of about 2.11 seconds.
This can be extended to about 270 seconds by using the Postscaler.
Set PSA = On and set PS<2.0> to 111.
Using the WDT can cause problems if you are using long delays, I have delays of 15 minutes to 1 hour in my code. You have to “kick the dog” by issuing a CLRWDT command before the WDT times out. Here is how I handled the long delays:
Sub LongDelay ’15 min delay
Repeat 900
DelayCount = +=1
wait 1 sec
CLRWDT
End Repeat
Return
I have not tested the code yet, I will report back when I have. I am out of town for a few days.
Best regards, Ed.
Hi all, Checked out the above code and it seems to work as advertised. Here is the long delay code I used
Regards, Ed