|
|
View previous topic :: View next topic |
Author |
Message |
palyancodr
Joined: 06 Jan 2014 Posts: 31
|
16F877A getting stack overflow, why? *** Locked |
Posted: Wed Feb 26, 2014 10:55 pm |
|
|
++++++++++++++++++++++
Locked.
Reason: Thread going nowhere. No info from O.P.
Suggestion: Search forum archives.
- Forum Moderator
++++++++++++++++++++++
Hi pcm_programmer and telmah:)
i am having stack overflow at pic 16f877A here what is written at top of my .lst file:
Code: |
ROM used: 4320 words (53%)
Largest free fragment is 2048
RAM used: 70 (19%) at main() level
90 (24%) worst case
Stack: 2 locations |
As you can see my rom and ram usages are ok. Why am i getting stack overflow? _________________ Hardware-Software Developer
Physics Engineer
Ceo airVision Aerial Video and Photography
Ceo Massive Robotics
ccs c ide version: 4.110
Pic: 16F877 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 26, 2014 10:59 pm |
|
|
You are only using 2 stack locations. Why do you think you're getting
stack overflow ? |
|
|
palyancodr
Joined: 06 Jan 2014 Posts: 31
|
|
Posted: Wed Feb 26, 2014 11:06 pm |
|
|
sorry, what do you mean by only using two stack locations? _________________ Hardware-Software Developer
Physics Engineer
Ceo airVision Aerial Video and Photography
Ceo Massive Robotics
ccs c ide version: 4.110
Pic: 16F877 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 26, 2014 11:12 pm |
|
|
From your first post:
Quote: |
ROM used: 4320 words (53%)
Largest free fragment is 2048
RAM used: 70 (19%) at main() level
90 (24%) worst case
Stack: 2 locations
|
What device or program is reporting to you that you have stack overflow ? |
|
|
palyancodr
Joined: 06 Jan 2014 Posts: 31
|
|
Posted: Wed Feb 26, 2014 11:15 pm |
|
|
ok, so how to increase the stack location? _________________ Hardware-Software Developer
Physics Engineer
Ceo airVision Aerial Video and Photography
Ceo Massive Robotics
ccs c ide version: 4.110
Pic: 16F877 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 26, 2014 11:22 pm |
|
|
I don't want to continue this because you're ignoring my requests for
more information and not co-operating with the trouble-shooting process.
I'm going to quit for the night. Someone else may want to work on it later. |
|
|
palyancodr
Joined: 06 Jan 2014 Posts: 31
|
|
Posted: Wed Feb 26, 2014 11:25 pm |
|
|
my apologies, i did not see your questions at the end of your message. I am simulating my .hex at proteus so it is giving me this error. _________________ Hardware-Software Developer
Physics Engineer
Ceo airVision Aerial Video and Photography
Ceo Massive Robotics
ccs c ide version: 4.110
Pic: 16F877 |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
|
palyancodr
Joined: 06 Jan 2014 Posts: 31
|
|
Posted: Thu Feb 27, 2014 12:11 am |
|
|
Hi newguy,
this is not a proteus question. The proteus only provides me the simulation results.
As you can see from the previous posts, i am getting stack overflow. I don't really know the reason why? according to .lst files there are 2 stack locations. As far as i know compiler manages the stack location size. My rom and ram usages are fair so why i am getting this error?
If you be much more educative than posting a link to no more proteus questions because my post includes the word "proteus", i will be glad:) _________________ Hardware-Software Developer
Physics Engineer
Ceo airVision Aerial Video and Photography
Ceo Massive Robotics
ccs c ide version: 4.110
Pic: 16F877 |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu Feb 27, 2014 2:58 am |
|
|
palyancodr wrote: | this is not a proteus question. The proteus only provides me the simulation results.
As you can see from the previous posts, i am getting stack overflow. I don't really know the reason why? according to .lst files there are 2 stack locations. As far as i know compiler manages the stack location size. My rom and ram usages are fair so why i am getting this error?
If you be much more educative than posting a link to no more proteus questions because my post includes the word "proteus", i will be glad:) |
As you should know had you read the datasheet carefully, this PIC, like most has a fixed hardware stack. You can't "manage" it. It simply "is".
The question remains and is pertinent: how do you *know* you are seeing stack overflow? What is reporting it? Where does that information come from? The stack usage of reported by the compiler is based on static analysis of the code, its what the code could do, under worst case: its the level of nesting of routines. RAM and ROM usage have nothing to do with stack usage. The stack is not even in RAM.
If its the simulation, i.e. Proteus/ISIS, that's saying there's stack overflow, then that clearly is a simulation issue. As the hardware cannot tell you - many PICs wont even restart/trap/whatever when the stack overflows as there's no hardware stack check - then it suggest very strongly that it is simulation that's alerting you to the "overflow".
There are stack overflow issues with some PICs. That is primarily on 24 series PICs which do have a more conventional RAM based stack, and for which the default allocation is often insufficient. ON 24s its common to have to increase, in code, the stack allocation, on anything but the simplest code. This does not affect 18s, 16s, 12s or 10 series PICS which all have fixed, hardware stacks of various sizes. The datasheet, in several places, but most clearly in the memory map diagrams on page 15, shows PIC16F877A has an eight level stack, of which you are using two.
The Proteus simulator, ISIS, while being good for many things, has a lot of serious problems simulating PICs. That's a fact. Its so much a fact that we've grown averse to answering any Proteus related questions. It shows configurations working that cannot work on real hardware, and it fails with things that work in hardware. Simple things that is, stuff it really ought to get right. A lot of developers' and our time is regularly wasted by Proteus issues. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Thu Feb 27, 2014 7:14 am |
|
|
re: 'simulation'. The major problem with 'simulators' is they do NOT simulate the real world.Instead they 'interpret' your code based upon what some programmer 'thinks' should happen NOT what actually happens.
Since YOU have NO control over what the 'simulator' thinks is right or wrong you're led into believing ISIS is alway right.
Case in point. ISIS doesn't care IF there's NO crystal attached to the 877 in the shcematic, yet will 'simulate' that the PIC is running at 20 MHz! Fine, program works you(ISIS) say, you make 1000 PCBs for production,install all the parts but NO crystal(it's NOT in the schematic, ISIS says not needed),go to test before product is shipped.....oops they do NOT work! 'But it did in the simulation'.....Now you've got thousands of dollars in scrap PCBs, angry clients and an empty bank account.
I've been in this field since 1974 and there isn't any simulator I've met or used that 100% correctly simulates the PIC.99% is NOT good enough!
The point is do NOT trust simulators, always test in the real world,with
real PICs and parts.
hth
jay |
|
|
palyancodr
Joined: 06 Jan 2014 Posts: 31
|
|
Posted: Thu Feb 27, 2014 7:29 am |
|
|
Quote: | As you should know had you read the datasheet carefully, this PIC, like most has a fixed hardware stack. You can't "manage" it. It simply "is". |
That is what i know.
Quote: | The question remains and is pertinent: how do you *know* you are seeing stack overflow? What is reporting it? Where does that information come from? The stack usage of reported by the compiler is based on static analysis of the code, its what the code could do, under worst case: its the level of nesting of routines. RAM and ROM usage have nothing to do with stack usage. The stack is not even in RAM.
|
I was suspected when i saw pic restarts it self on hardware, then i check the proteus results than it is clearly stack issue for me. On the other hand, when i delete some pice of code, code works. If i add let's say one line it does not work and goes to restart loop. Why this can happen?
Quote: | If its the simulation, i.e. Proteus/ISIS, that's saying there's stack overflow, then that clearly is a simulation issue. As the hardware cannot tell you - many PICs wont even restart/trap/whatever when the stack overflows as there's no hardware stack check - then it suggest very strongly that it is simulation that's alerting you to the "overflow". |
i don't understand why you suspicious from the proteus from the first hand. I got same results from proteus every single time what i got from real tests. What do you use for simulation? And yes the pic i am using 16f877A going into restart loop i think its because it is having stack overflow.
Quote: | There are stack overflow issues with some PICs. That is primarily on 24 series PICs which do have a more conventional RAM based stack, and for which the default allocation is often insufficient. ON 24s its common to have to increase, in code, the stack allocation, on anything but the simplest code. This does not affect 18s, 16s, 12s or 10 series PICS which all have fixed, hardware stacks of various sizes. The datasheet, in several places, but most clearly in the memory map diagrams on page 15, shows PIC16F877A has an eight level stack, of which you are using two. |
I agree in this point that pic 24 series having that issue and yes 16f877 has fixed stack and i am using only 2 of 8.
Quote: | The Proteus simulator, ISIS, while being good for many things, has a lot of serious problems simulating PICs. That's a fact. Its so much a fact that we've grown averse to answering any Proteus related questions. It shows configurations working that cannot work on real hardware, and it fails with things that work in hardware. Simple things that is, stuff it really ought to get right. A lot of developers' and our time is regularly wasted by Proteus issues. |
Again this is not a proteus issue. I have the hardware the hardware does the same with proteus, i got true results all the time from proteus. And along the way i learned not to trust the proteus %100 percent.
All the symptoms show that problem is with PIC. Just help me to understand why on earth when i add just a simple line to code, code does not work and why it starts working when i delete it. _________________ Hardware-Software Developer
Physics Engineer
Ceo airVision Aerial Video and Photography
Ceo Massive Robotics
ccs c ide version: 4.110
Pic: 16F877 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Thu Feb 27, 2014 8:17 am |
|
|
hmm...
Quote: | All the symptoms show that problem is with PIC. Just help me to understand why on earth when i add just a simple line to code, code does not work and why it starts working when i delete it.
|
It could easily be what I call a 'page violation'. Adding a line of code, increases the program size and a function may have split over the 'page boundry'. The compiler might have tried to 'refit' into available codespace, but can't. Without seeing your code, I don't know how it's arranged in memory,however 'functions' MUST be continuous the same page,Same holds true for RAM, you can't 'split' say a 16bit variable(word) over 2 pages(unless a preproceesor directive is issued, I think).
I haven't used the 877 for a decade or so though it was my favorite PIC for 10+ years. Using the 18F46k22 was a quantum jump, lots of RAM, codespace, 2 UARTS, etc.
We need to see a small, compilable program from you to see what's really going on.
hth
jay |
|
|
palyancodr
Joined: 06 Jan 2014 Posts: 31
|
|
Posted: Thu Feb 27, 2014 8:40 am |
|
|
I would like to share the code however it requires so many knowledge to understand and it will be inappropriate since we have competitors trying to copy what we do.
I would like to assist you with your question. One interesting fact, if i switch to 18f4550 the same code works if i switch back to 16f877 it does not. I don't wanna switch to 18f4550 because 16f877 must be sufficient for this job and my code is not that big. _________________ Hardware-Software Developer
Physics Engineer
Ceo airVision Aerial Video and Photography
Ceo Massive Robotics
ccs c ide version: 4.110
Pic: 16F877 |
|
|
palyancodr
Joined: 06 Jan 2014 Posts: 31
|
|
Posted: Thu Feb 27, 2014 8:58 am |
|
|
Another strange fact, I am using 2x16 lcd. At that lcd i show some real time readings that i get from timer1 as timer. _________________ Hardware-Software Developer
Physics Engineer
Ceo airVision Aerial Video and Photography
Ceo Massive Robotics
ccs c ide version: 4.110
Pic: 16F877 |
|
|
|
|
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
|