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 CCS Technical Support

Watchdog interrupt

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



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

Watchdog interrupt
PostPosted: Mon Aug 23, 2010 3:08 pm     Reply with quote

Hi there, im using a PIC18F4620 with a watchdog at 4s, my problem is that i need to know when the wdt reset occurs to save some variables in the eeprom. Is there any interrupt or any other way that allows me to know that?

Thanks in advance...
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Aug 23, 2010 11:23 pm     Reply with quote

The WDT can perform a wakeup from sleep or a reset, not an interrupt. The WDT reset can be identified however
at the main() entry by querying restart_cause(). If #zero_ram isn't in effect, you can still save data at this time.
Audi80



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

PostPosted: Tue Aug 24, 2010 5:52 am     Reply with quote

Hi there FvM, i don't know what #zero_ram is but if i restart my application all variables like an int go to zero? For example:

Code:


   int a = 0;
   
   int main(){

   printf("Value: %d\r\n",a);
   // After wdt reset a goes to 0 or stays at 1????
   a = 1;

   return 0;
}



Thanks in advance.
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Tue Aug 24, 2010 10:07 am     Reply with quote

First, you are setting a to zero, so 'of course' it'll go to zero.
#zero_ram is a directive to tell the compiler to completely 'wipe' the RAM memory on boot.

However, if you change your code to:
Code:

void main(void){ //In CCS, the 'main' function is the code, and cannot
    //return anything....
    int a; //Declare, but don't initialise the variable
    if (restart_cause() == WDT_TIMEOUT) {
       printf("Watchdog restart - a=%d\n\r",a);
    }
    else {
       a=0; //Initialise the variable
       printf("Booted\n\r");
    }
    a++; //Increment a
    while (TRUE) ; //Wait here for a watchdog
    //Main cannot 'return' anything
}

This will tell you that the watchdog has timed out, and print the value, which will increment each time it restarts.

However, in your 'write the EEPROM, on a watchdog, be aware of the limited write life of the EEPROM. If you are doing this every 4 seconds, depending on the chip involved, you could kill the EEPROM in under 12 hours.
Also, be aware of the inaccuracy of the watchdog. Typically there is a 3:1 variation in the 'real' time involved in a watchdog timeout...

Best Wishes
Audi80



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

PostPosted: Tue Aug 24, 2010 10:24 am     Reply with quote

Hi there Ttelmah first let me thank you for your reply.

I have developed a project that controls IO's a temperature sensor and also a RTCC and it communicates by RS485 and I have a server pooling every controller (10 by the way). Each controller is pooled every 2 sec and it restarts the wdt. Now what I want to do is that if the communication stops the wdt will reset. I want to save the data from the rtcc and the temperature sensor only if the last read data differs by 1 month.

So I don't think I will blow up the eeprom. I will try it later and see if it works.

Once again thanks...
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