View previous topic :: View next topic |
Author |
Message |
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
Weird 16F648A mcu operation when ROM=63 % |
Posted: Mon Jul 24, 2006 11:35 pm |
|
|
Hi,
PCM: 3.169
MCU: 16F648A
I have noticed that whenever ROM used is more than 63% the mcu operation becomes un-predictable and random...
For example in the code I am developing , the mcu starts transmitting some pulses on the USART. But when I remove some code from the main duty cycle it runs well.
I have noticed these problems in other mcus as well , 16F877 etc. When ROM used is less (say 30 %) they work well.
Kindly advise what's wrong here... I could post the code if required.
thanks
arunb |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
RE: |
Posted: Tue Jul 25, 2006 1:28 am |
|
|
Hi,
Here is an extract from the LST file...
CCS PCM C Compiler, Version 3.169, 16542
Filename: SLA7062-Controller.LST
ROM used: 1762 (43%)
Largest free fragment is 2048
RAM used: 74 (42%) at main() level
109 (62%) worst case
Stack: 9 worst case (4 in main + 5 for interrupts)
Does 'worst case' mean I am using 9 stack locations or is it just a warning ???
thanks
arunb |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 25, 2006 1:49 am |
|
|
It is a prediction that you program will crash at some point.
The 16F648A only has 8 stack levels. If you use more than that,
expect the program to crash.
Because the .LST file shows more than 8 levels are used, this
tells me that you are using the #separate directive.
Also, you have 5 stack levels for interrupts. This tells me that
you don't have simple interrupt code. You are calling functions
that call other functions, and they call functions, and so on.
You have to get the stack levels down to 8 or less.
Ideally, you should completely remove all usage of #separate
from your program. However, it may not compile in that case.
You could try to change the size of your functions and the structure
of your program. Or, you could try to remove #separate from
certain functions, and then re-compile and watch the .LST file
until it gets to 8 or less stack levels.
Once you start using #separate, the compiler will not automatically
limit the number of stack levels to 8. It will just use however many
are required, even if the amount used will exceed 8 and cause the
program to crash. That's why I said it's ideal if you can remove
all the #separate statements from your program. |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
RE: |
Posted: Tue Jul 25, 2006 2:05 am |
|
|
Hi,
Thank you for the help.
I remove the extra code from the interrupts. So now the stack shows 5 Worst case (4 in main+1 in interrupt).
How are function calls within a function made ??? Is this OK ??
Code: |
void funcB()
{
}
void funcC()
{
}
void funcA()
{
funcB();
funcC();
}
void main()
{
do
{
funcA();
}while(TRUE);
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 25, 2006 4:29 am |
|
|
Yes, that's OK. |
|
|
|