View previous topic :: View next topic |
Author |
Message |
darahayes
Joined: 05 Mar 2009 Posts: 15
|
restart_cause ALWAYS NORMAL POWER UP |
Posted: Thu Mar 19, 2009 7:52 am |
|
|
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
|
|
Posted: Thu Mar 19, 2009 9:28 am |
|
|
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
|
|
Posted: Thu Mar 19, 2009 11:16 am |
|
|
Your compiler has an example program for WDT:
Quote: | c:\program files\picc\examples\ex_wdt.c |
|
|
|
darahayes
Joined: 05 Mar 2009 Posts: 15
|
restart_cause allways gives power up |
Posted: Fri Mar 20, 2009 3:47 am |
|
|
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 |
|
|
|