CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

WDT never restarting

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
fasteddye



Joined: 13 Apr 2005
Posts: 6

View user's profile Send private message

WDT never restarting
PostPosted: Mon Nov 07, 2005 9:13 am     Reply with quote

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

View user's profile Send private message

I think I know why
PostPosted: Mon Nov 07, 2005 9:43 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 07, 2005 12:41 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 07, 2005 1:40 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 07, 2005 2:00 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 07, 2005 2:03 pm     Reply with quote

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. Wink
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 07, 2005 2:23 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 07, 2005 2:32 pm     Reply with quote

You might be gettn old but you haven't diminished yet.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group