View previous topic :: View next topic |
Author |
Message |
jamesjl
Joined: 22 Sep 2003 Posts: 52 Location: UK
|
Where is my procedure called from? |
Posted: Fri Sep 23, 2005 1:17 am |
|
|
Hi all,
I have a sizeable program that is misbehaving. A subroutine within the program is explicitly called from 5 locations throughout the code, however, certain (apparently random) conditions appear that call this routine from an undetermined location. I have used printf statements to try and see where the routine is being erroneously called from, but with no luck. Is there any way of determining where this routine is being called from, e.g. looking at the stack, etc?
Any help would be much appreciated.
Regards,
Jason |
|
|
Ttelmah Guest
|
|
Posted: Fri Sep 23, 2005 3:23 am |
|
|
The stack will only help if the routine is 'called'. If it is jumped to, then there will be no record.
Now the compiler is now pretty good at not generating this sort of problem, so one has to ask what is causing it?. What is the chip?. There have been a number of faults in the past with particular processor variants, which have problems with a call/jump, if it crosses a page boundary. One 'classic' example, was the 18Fxx2 chips, which for about the first two years, did this. CCS has the ability to insert the 'fix' for this error (it can be enabled in the device editor if you have this), and till a few months ago, did this by default. However since the latest couple of chip versions, don't have this problem, the default is now to disable this fix.
I'd start by looking at the errata sheets for the chip concerned, and see if there is anything of this sort. If not, then you either need to be using an ICE, with a 'track back' ability (most hardware ICE systems can do this), or are going to have to find the error by searching the list file. If you think the program is getting to the start of the routine, a simple search of the listing, for the address of this point, will find every location that references it.
Best Wishes |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Sep 23, 2005 7:13 am |
|
|
If you are using a PIC16 and const arrays, then this sort of behaviour will happen if you exceed the array limits. There are no bounds checks and the method for "returning" values could cause the program to jump to a location that is expectiing a retlw but instead jumps into other parts of the code.
The 'track back' ability that RJ refers to is also known as 'trace'. An ICE would be great for this but not everyone has one. Another option is to make your code run on the MPLAB simulator and use its trace ability. I have done this in the past when I didn't want to get out the ICE. If your program relies on external events, you might have to fudge them with a bit of code to make your application run. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 23, 2005 11:12 am |
|
|
Quote: | certain (apparently random) conditions appear that call this routine from an undetermined location |
If you're using the PCM compiler, then look at stack usage report,
which is given at the top of the .LST file for your project.
The stack usage should be no more than 8 locations, because
that's the limit of the hardware stack inside the 16-series PICs.
Example:
Quote: | ROM used: 1437 words (70%)
Largest free fragment is 611
RAM used: 26 (15%) at main() level
67 (38%) worst case
Stack: 3 locations |
|
|
|
jamesjl
Joined: 22 Sep 2003 Posts: 52 Location: UK
|
|
Posted: Mon Sep 26, 2005 12:55 am |
|
|
HI All,
I think I found it. Whilst I thought that the routine was being called in error, I was wrong. I found another location that could call it and things are now starting to behave.
I am using an 18F4585 and an 18F6680 in my project and I need interrupt driven CAN capability. Could someone tell me what the maximum stack depth is for an 18F series PIC?
Can anyone recommend an good mid-range ICE? The project I am working on is starting to be large enough to warrant one now. Do they work with the CCS IDE or do I have to use MPLAB. I have CCS PCWH and am about to download the latest version. Does anyone have a paper on how to convert my project to compile using MPLAB?
Many thanks,
Jason |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Sep 26, 2005 6:43 am |
|
|
I'd get the ICE4000
The stack depth is in the datasheet but it should be 32.
There is no paper needed to convert. Just start a project in MPLAB. It will ask you the PIC, the tool suite. Then you just add your main C file to the IDE and you are done. Do not add all the C files under source. It will try to compile each of them. You can add them under the other files though. Make sure that you have downloaded the CCS plugin and installed that. You can find it on their website. |
|
|
jamesjl
Joined: 22 Sep 2003 Posts: 52 Location: UK
|
|
Posted: Mon Sep 26, 2005 10:55 am |
|
|
Mark,
will the ICE 4K work with the C compiler IDE or just MPLAB? Does it work with C code? Does anyone else have an opinion on getting an ICE?
Thanks,
Jason. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Sep 26, 2005 11:00 am |
|
|
Chances are, the ICE that you use will have an IDE that goes with it. I don't have the CCS IDE so if it is not listed as a debug device, then it probably will not work. That's why I like the Microchip stuff. I can use the ICD2, Promate, ICE2000, ICE4000, simulator, compiler all within MPLAB. C code is compiled and eventually converted to asm code. This is really what goes into the ICE. Machine instructions and not a high level language. But from your point of view. Yes you can write C language, compile and then run with the ICE. |
|
|
jamesjl
Joined: 22 Sep 2003 Posts: 52 Location: UK
|
|
Posted: Mon Sep 26, 2005 12:51 pm |
|
|
Mark,
many thanks for the information. I'm sure to find it useful when I get around to getting an ICE. It's budget time at the office, so I'll be sure to put in a request for one. One final thing; can I use the CCS ICD with MPLAB?
Regards,
Jason |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Sep 26, 2005 1:30 pm |
|
|
jamesjl wrote: | Mark,
many thanks for the information. I'm sure to find it useful when I get around to getting an ICE. It's budget time at the office, so I'll be sure to put in a request for one. One final thing; can I use the CCS ICD with MPLAB?
Regards,
Jason |
Not sure on that one. Only if it is compatiable with the Microchip unit. Probably not is my guess but that is an easy test to try. |
|
|
|