View previous topic :: View next topic |
Author |
Message |
fasteddye
Joined: 13 Apr 2005 Posts: 6
|
WDT never restarting |
Posted: Mon Nov 07, 2005 9:13 am |
|
|
I am trying to add a WDT to my code, but for some reason, the restart_WDT is not getting executed and the PIC resets every 2 seconds. Does anyone have a solution?? Here is a sample my code.
Code: |
// CPU and Receiver
//
#include <16F818.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#fuses HS,WDT,NOPROTECT,PUT,NOBROWNOUT,NODEBUG,NOLVP
#use delay(clock=20000000)
#use rs232(baud=1200, parity=N, rcv=PIN_B1, INVERT, ERRORS) //took out: xmit=PIN_B0,
void main() {
char datar,ddl,ddh,datadecode;
int1 status;
int1 foundCharYet;
setup_wdt(WDT_2304MS);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
set_tris_a(0x00); //0000 0000
set_tris_b(0x02); //0000 0010
disable_interrupts(INT_EXT);
disable_interrupts(GLOBAL);
output_high(PIN_B3); //status led initial set
output_high(PIN_B4); //status led initial set
output_high(PIN_B5); //status led initial set
output_high(PIN_B6); //status led initial set
output_high(PIN_B7); //status led initial set
status=0; //lsb part
datadecode=0;
foundCharYet=0;
while(1) {
restart_wdt();
if (!kbhit()) {
datar = getc();
// DO STUFF
}
}
|
|
|
|
neil
Joined: 08 Sep 2003 Posts: 128
|
I think I know why |
Posted: Mon Nov 07, 2005 9:43 am |
|
|
Hi, your test if(!kbhit() ) is true when no data is ready in the receive buffer, so every time there is no data available (the majority of the time) the getc() is encountered and this waits indefinitely or until a byte is received! There is no reset WDT in here, ther theres your problem.
This would be OK if you tested for kbhit() instead. Eg:
Code: | while(1) {
restart_wdt();
if (kbhit()) datar = getc();
// Now do other stuff outside here
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 07, 2005 12:41 pm |
|
|
Also, look in the CCS manual. You'll see that many of the #use
statements have an optional "restart_wdt" parameter. This configures
the CCS library code to do a CLRWDT instruction whenever it's waiting
in a loop that could cause the Watchdog to time out. In your case,
you could add restart_wdt to the #use rs232 statement and it would
fix your problem. Also, it wouldn't hurt to add it to the #use delay()
statement. |
|
|
fasteddye
Joined: 13 Apr 2005 Posts: 6
|
|
Posted: Mon Nov 07, 2005 1:40 pm |
|
|
Thanks for all the help! I took neil's advice and changed the kbhit if statement so that if there is nothing in the buffer, the PIC will keep looping. PCM programmer, where would I place another #use delay statement?? I already have one at the beginning of the code setting my clock to 20 MHz. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 07, 2005 2:00 pm |
|
|
Quote: | where would I place another #use delay statement |
No, not another statement. Add the restart_wdt parameter to your
existing statement. Please download the CCS manual and read the
sections on #use rs232 and #use delay which show how to do this.
http://www.ccsinfo.com/ccscmanual.zip |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Mon Nov 07, 2005 2:03 pm |
|
|
Just leave your #used delay() statement where it is. PCM Programmer is apparently getting older and didn't see it because he needs new glasses. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 07, 2005 2:23 pm |
|
|
Quote: | PCM Programmer is apparently getting older and didn't see it |
That's not at all what I said. I said:
Quote: | Also, it wouldn't hurt to add it to the #use delay() statement. |
That means do this:
Code: | #use delay(clock=20000000, restart_wdt) |
I have a basic assumption that people will actually read the manual
about anything they don't understand, once they have been told that
the feature exists. That assumption was wrong. |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Mon Nov 07, 2005 2:32 pm |
|
|
You might be gettn old but you haven't diminished yet. |
|
|
|