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 problem on 16f877a

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



Joined: 13 Oct 2010
Posts: 16

View user's profile Send private message

Wdt problem on 16f877a
PostPosted: Fri Mar 04, 2011 9:59 am     Reply with quote

I searched lots of example codes, but I couldn't add watchdog timer to my code. What is the problem with this? (PCWHD 4.114 )

Code:
#include <16F877A.h>
#fuses HS, WDT, PROTECT, NOLVP, NOBROWNOUT, PUT
#use delay(clock=20000000,restart_wdt)

#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xC0)

#include <em4095.c>
#include <em4102.c>

#INCLUDE <stdlib.h>

int8 msg[7];

int address=12;


#INT_SSP
void ssp_interupt ()
{
   restart_wdt();
   BYTE incoming, state;
   
   state = i2c_isr_state();
   
   if(state < 0x80)                     //Master is sending data
   {
      incoming = i2c_read();
      if(state == 1)                     //First received byte is address
         address = incoming;
      if(state == 2)                     //Second received byte is data
         msg[address] = incoming;
   }
   if(state == 0x80)                     //Master is requesting data
   {

      i2c_write(msg[address]);
     
      //i2c_stop();
     
   }
   

}

void main()
   {
   int8 customerCode;
   int32 tagNum;
   
   output_float(PIN_C3);
   output_float(PIN_C4);
   
   enable_interrupts(INT_SSP);
   enable_interrupts(GLOBAL);
   restart_wdt();
   rf_init();
   rf_powerUp();
   restart_wdt();
   
   
   output_bit(PIN_A0,0);
   msg[5]=0;
   msg[6]=0;
   setup_wdt(WDT_2304MS);
   //msg[1]=32;
   for(;;)
   {
       
     
         restart_wdt();
         if(msg[5])
         {
            disable_interrupts(INT_SSP);
           
            msg[0]=0;msg[1]=0;msg[2]=0;msg[3]=0;msg[4]=0;msg[6]=0;
           
            if(read_4102(msg))
            {
                restart_wdt();
                msg[6]=1;
               
            }
            enable_interrupts(INT_SSP);
            msg[5]=0;
         }
   
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 04, 2011 1:13 pm     Reply with quote

Don't compile the program in "Debug" mode. If you do, the Watchdog
will be disabled. Compile and test it in "Release" mode.
muiratinas



Joined: 13 Oct 2010
Posts: 16

View user's profile Send private message

PostPosted: Sat Mar 05, 2011 1:00 am     Reply with quote

At compile, I press the build all button then program the chip button.
Also I am making tests at a real circuit. Without wdt settings, it's working so good.
I just added "#fuses WDT","setup_wdt(WDT_2304MS);" and "restart_wdt" to working code. And now its not working :/

Circuit is communicating with a RFID board and my circuits' crystal is 20mhz.
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Sat Mar 05, 2011 7:34 am     Reply with quote

Realistically, as written, the WDT, would do you little good anyway....
The point about a watchdog, is that it should be only kept clear if the real code is running, and running correctly. In your code, just about everything would clear it, even if nothing was working.

There are several things about the code that are 'worrying' (no limit check on the address, relative to the buffer size for example).
However, one possibility obviously, is that the code is staying too long in 'read_4102', and hence there is a problem. Similarly, how long will 'rf_init', and 'rf_powerUp' take?. Unless I2C data is arriving and keeping the watchdog reset, if either of these takes significant time you could have a problem.
Be aware that the watchdog times are _very_ nominal. With the 18mSec option selected for example, the trigger can be as short as 7mSec, and as long as 27mSec. Since you haven't set the watchdog prescaler when these initialisation routines are called, you could have as little as 7mSec before a timeout.....

Best Wishes
muiratinas



Joined: 13 Oct 2010
Posts: 16

View user's profile Send private message

PostPosted: Mon Mar 07, 2011 1:18 am     Reply with quote

thanks for your reply Ttelmah,
Code:
There are several things about the code that are 'worrying' (no limit check on the address, relative to the buffer size for example).

This code is a modified example, so I think that reliability of the code is enough.

This code reads RFID number of the cards and holds it. On I2C, data are got by another pic. Thus, I just want pic not to be stucked. setup_wdt(WDT_2304MS); is added to achieve 2.3 sec reset time. Do I need to add also a prescaler?
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