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

restart_cause ALWAYS NORMAL POWER UP

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



Joined: 05 Mar 2009
Posts: 15

View user's profile Send private message Send e-mail

restart_cause ALWAYS NORMAL POWER UP
PostPosted: Thu Mar 19, 2009 7:52 am     Reply with quote

Trying for first time to get a wdt working on an 16F876. Used the standard methods of enabling the watch dog timer and setting a switch statement after main () to see what the cause of the reboot was and as several other folk on the discussion board have found I am only getting a normal power up despite the wdt timing out or reset during sleep being forced in some cases. But no matter what the actual cause I only get normal power up. The previous discussion on this problem has led some one to supply an answer in saying to the person with the problem to look up some posted code that was on the old board but the link to this example is now broken. So can some one please shed light on this problem which I am sure has been explained by experts before but the answer eludes me at present !

AM USING COMPILER VERSION 3.181
STANDARD PIC 16F876 H AND INC FILES

many thanks Dara Hayes
Ttelmah
Guest







PostPosted: Thu Mar 19, 2009 9:28 am     Reply with quote

Restart_cause, _must_ be read very early in the code. Basically, there are some changes made to the internal registers during configuration, that always reset it. So your layout needs to be:
Code:

int8 reason;

void main(void) {
    reason=restart_cause();

    //initialisation code here
   



//Then wherever you want:

switch(reason) {
case WDT_FROM_SLEEP:

    break;
case WDT_TIMEOUT:

    break;
case MCLR_FROM_SLEEP:

    break;
case MCLR_FROM_RUN:

    break;
case NORMAL_POWER_UP:

    break; 
case BROWNOUT_RESTART:

    break;
}

Basically, if you call several of the initialisation routines, before reading it, the flags will be reset.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 19, 2009 11:16 am     Reply with quote

Your compiler has an example program for WDT:
Quote:
c:\program files\picc\examples\ex_wdt.c
darahayes



Joined: 05 Mar 2009
Posts: 15

View user's profile Send private message Send e-mail

restart_cause allways gives power up
PostPosted: Fri Mar 20, 2009 3:47 am     Reply with quote

Ok thanks I have seen that the setup wdt statement must be after the restart cause function read as this also destroys the status bits i have now got the program more or less working but my problem was that the variables were being zeroed I had a zero ram just prior to main so have also taken that out and now I have all variables saved only on normal power up do I manually zero and initialise all variables thanks for your help
dara
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