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

PIC18F6722 getting reset intermittently

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



Joined: 05 Oct 2007
Posts: 31

View user's profile Send private message

PIC18F6722 getting reset intermittently
PostPosted: Mon Jul 06, 2009 5:54 pm     Reply with quote

Hi All,

I have a a very weird and frustrating problem happening. I am using a PIC18F6722. The problem is that sometimes the PIC gets reset for some unknown reason.

The nature of the reset taking place is when I get an interrupt on RB4-RB7 pins.

So far the things I'm considering that could cause a hardware reset are:
1. Watchdog timer
2. Brownout

Here are my fuses:
Code:
#fuses NOBROWNOUT,FCMEN,IESO,PUT,INTRC_IO,NODEBUG,NOWDT,NOLVP


1. So, for the watchdog timer, i'm using setup_wdt(WDT_OFF) to start with at the beginning of the program. I only turn the setup_wdt(WDT_ON) in a while loop and call the restart_wdt() command inside the loop to prevent a reset from taking place.

Code:
while (1)
         {
       setup_wdt(WDT_ON);
            if(one_second_timer)
               {
              read_reg_sr();
               }
         }


I call restart_wdt() inside read_reg_sr()...

2. To prevent a brownout happening, I have the NOBROWNOUT fuse.

Could someone please tell me what I might be doing wrong and what else could be causing the reset. Could it be something to do with the interrupt that causes the reset?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 06, 2009 7:13 pm     Reply with quote

Quote:
I only turn the setup_wdt(WDT_ON) in a while loop.

Don't do that. Just leave it off. Your purpose is to find out the reason
for the random resets. Disable the Watchdog in the #fuses and don't
re-enable it in software.

Thread on random resets:
http://www.ccsinfo.com/forum/viewtopic.php?t=27638&start=4
cypher



Joined: 05 Oct 2007
Posts: 31

View user's profile Send private message

PostPosted: Mon Jul 06, 2009 7:35 pm     Reply with quote

Ok thanks, I will try your suggestion....also the links are very helpful, I will try a few things soon
cypher



Joined: 05 Oct 2007
Posts: 31

View user's profile Send private message

PostPosted: Tue Jul 07, 2009 1:18 pm     Reply with quote

So I read thru all those previous posts and used the restart_cause() function to find out exactly why my reset it happening. And interestingly enough, its because of a RESET_INSTRUCTION.

So, first of all, the reset_cpu() function in the code should never be called, however, I have commented out everywhere in my code where I use the reset_cpu() just to make sure it never gets executed. But the problem still exists, the intermittent resets I am getting are due to RESET_INSTRUCTION.

What else could be causing a RESET_INSTRUCTION reset other than the reset_cpu() command being executed?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 07, 2009 1:24 pm     Reply with quote

Make a short test program that calls restart_cause(), displays the result
on a terminal window on your PC, and then sits in a while(1) loop forever.
If you are getting random resets, the terminal window will fill up with
additional lines of "Restart cause = xxxx" reports, besides the first one.
Because this will be such a minimal program, if you do get problems,
the cause will probably be in hardware.
cypher



Joined: 05 Oct 2007
Posts: 31

View user's profile Send private message

PostPosted: Tue Jul 07, 2009 3:14 pm     Reply with quote

Also, interestingly enough, I do not see this intermittent problem if I just keep the program running forever. The problem only occurs when I introduce a hardware interrupt on the RB4-RB7 pins (interrupt on change). Is there something related to this interrupt that could cause a RESET_INSTRUCTION?

Also, for the while(1) infinite loop, I should put the printf statement displaying the result of restart_cause() inside the while loop right? If I just sit in a while loop forever, the terminal window would not display if the printf is not inside the loop.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 07, 2009 3:23 pm     Reply with quote

No. Just do this:

- call restart_cause().
- printf the result.
- wait in a while(1) loop forever. Don't do anything in the loop.

Restart_cause() is usually only valid if you read it at the very beginning
of main(). There are several posts on this in the archives.

The purpose of this test is to see if you are getting random resets just
while sitting in a loop, doing nothing. If you get a reset, you will get
another printf of the restart_cause() result. If you don't get a reset,
you'll get nothing.
cypher



Joined: 05 Oct 2007
Posts: 31

View user's profile Send private message

PostPosted: Tue Jul 07, 2009 4:04 pm     Reply with quote

Ok so tried doing that and I haven't seen any resets while just sitting in a loop....I only read a NORMAL_POWER_UP once and thats it. I've been running it for more than 30 mins and haven't seen a reset yet, so I think it's definitely something in my code that causes intermittenty resets.

I have another thought, don't know if it makes any sense though. So, like I said I have interrupts firing continuously on the RB4-RB7 pins and during these interrupts I have some printf statements I make to the terminal (not inside the interrupt sr but interrupt sr calls these printf). Now could it be possible that these intermittent resets are being caused since the printf are not executed all the time (I mean if an interrupt is called before all printing to the screen is done)?

I also do disable my int_rb manually in my isr and enable & clear it only when I'm done doing the actions (printf etc)....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 07, 2009 4:18 pm     Reply with quote

Are you enabling Global interrupts inside the isr ? If so, that could
definitely cause the problem. Delete that code, if you're doing it.
cypher



Joined: 05 Oct 2007
Posts: 31

View user's profile Send private message

PostPosted: Tue Jul 07, 2009 4:50 pm     Reply with quote

Yes, I :

Code:
enable_interrupts(int_rb);
      enable_interrupts(global);


inside the isr. Shall I just get rid of the global and keep the int_rb inside the isr, or should I delete both?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 07, 2009 4:57 pm     Reply with quote

Quote:
Yes, I [have]:

enable_interrupts(int_rb);
enable_interrupts(global);

inside the isr

Remove the line for the global interrupts (in bold).

I'm not sure why you need the other one. You shouldn't need to
disable and then re-enable the INT_RB interrupts inside the isr.
You could post the isr.
cypher



Joined: 05 Oct 2007
Posts: 31

View user's profile Send private message

PostPosted: Tue Jul 07, 2009 6:11 pm     Reply with quote

Thanks a lot for your help, it seems to be fairly robust now. So, removing the enable global from the isr definitely did it!
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