View previous topic :: View next topic |
Author |
Message |
Neckruin
Joined: 17 Jan 2006 Posts: 66
|
Compiler skipping calls to functions?? |
Posted: Mon Nov 06, 2006 6:32 am |
|
|
Hi all,
I have found, looking at the .LST file of my project, this strange behaviour:
Code: | .................... while(TRUE)
.................... {
.................... ShowStatus();
0BE8: BCF 0A.3
0BE9: GOTO 554
0BEA: BSF 0A.3
.................... UpdateLamps();
0BEB: BCF 0A.3
0BEC: GOTO 6E3
0BED: BSF 0A.3
.................... TurnOffOut();
0BEE: BCF 0A.3
0BEF: GOTO 733
0BF0: BSF 0A.3
.................... ReadPCF8574();
0BF1: BCF 0A.3
0BF2: GOTO 78D
0BF3: BSF 0A.3
.................... MsgProcess();
0BF4: BCF 0A.3
0BF5: GOTO 7B9
0BF6: BSF 0A.3
.................... ProcCmdBtn(); // <---------- HERE !!!!!!!!!!!!!!!
.................... ErrorHandler();
*
0C71: BCF 0A.3
0C72: GOTO 7CB
0C73: BSF 0A.3
.................... }
0C74: GOTO 3E8
.................... } |
As you can see, the compiler is skipping a function (the one I thought didn't work). Why can this be happening???
I'm using 3.242 version on a PIC16F877.
Thanks a lot,
Juanma |
|
![](templates/subSilver/images/spacer.gif) |
Neckruin
Joined: 17 Jan 2006 Posts: 66
|
|
Posted: Tue Nov 07, 2006 3:08 am |
|
|
I have noticed the code for that function is quite big and has several calls to subroutines... could this be the reason? Maybe the stack is overflowing and the compiler just avoids the problem by deactivating that function
Any ideas???? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 07, 2006 3:17 am |
|
|
Read this FAQ topic:
http://www.ccsinfo.com/faq.php?page=lst_out_of_order
Carefully check the .LST file. See if the compiler has stuck the
code for that function somewhere else in the file.
With regard to your stack question, look at the top of the .LST file.
The stack usage is listed there. Post that number, and also post
the percentage usage of RAM and ROM. |
|
![](templates/subSilver/images/spacer.gif) |
Neckruin
Joined: 17 Jan 2006 Posts: 66
|
|
Posted: Tue Nov 07, 2006 3:23 am |
|
|
The requested info:
Code: | CCS PCM C Compiler, Version 3.242, 16465 06-nov-06 18:16
Filename: cod00.lst
ROM used: 3139 words (40%)
Largest free fragment is 2048
RAM used: 34 (10%) at main() level
71 (20%) worst case
Stack: 7 worst case (6 in main + 1 for interrupts) |
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 07, 2006 3:27 am |
|
|
Do a search of the .LST file for 0BF7. Press Ctrl-F and drop that number
into the Find box and see what it finds. I'll bet that it finds your missing
code. |
|
![](templates/subSilver/images/spacer.gif) |
Neckruin
Joined: 17 Jan 2006 Posts: 66
|
|
Posted: Tue Nov 07, 2006 3:39 am |
|
|
Yes, you are right. If I do a search with the next address just before the call to the function it appears the code for the function.
Does this mean the function is actually executing? In that case the problem must be another one... |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 07, 2006 3:45 am |
|
|
It should execute, provided that the program isn't hanging somewhere.
Put a printf() statement at the end of each one of those functions,
MsgProcess() and ProcCmdBtn(), and see if it displays the messages.
That should tell you if the program flow is getting to those functions. |
|
![](templates/subSilver/images/spacer.gif) |
Neckruin
Joined: 17 Jan 2006 Posts: 66
|
|
Posted: Tue Nov 07, 2006 3:54 am |
|
|
Ok, thanks a lot PCM. I'll try what you say and I hope to guess what's happening with that function.
THANKS
![Very Happy](images/smiles/icon_biggrin.gif) |
|
![](templates/subSilver/images/spacer.gif) |
Neckruin
Joined: 17 Jan 2006 Posts: 66
|
|
Posted: Tue Nov 07, 2006 5:37 am |
|
|
Mmmm, I have found the problem: The Timer 1 interrupt only executes once!!!
I have no idea what can be going on.
Here is my Timer1 ISR code:
Code: | #int_TIMER1
void TIMER1_isr() {
clear_interrupt(INT_TIMER1);
disable_interrupts(INT_TIMER1);
ButInputNow = ((PORTA & 0b00100000)>>5) | ((PORTE & 0b00000111)<<1);
if(ButInputNow != 0x0F && ButInputPrev == 0x0F)
ButPushedFlag = TRUE;
ButInputPrev = ButInputNow;
set_timer1(T125MS);
enable_interrupts(INT_TIMER1);
} |
It is supposed to take place every 25ms as far as the timer is configured as DIV_BY_4 with a 20MHz clock.
Any help or suggestion will be welcome... again
Thanks in advance
Juanma |
|
![](templates/subSilver/images/spacer.gif) |
Neckruin
Joined: 17 Jan 2006 Posts: 66
|
|
Posted: Tue Nov 07, 2006 6:16 am |
|
|
Forget about that, I have found the problem:
In the timer0 interrupt, I was seting up the timer 1 instead of the timer 0 by mistake. So, the timer 1 was reset at a higher rate than it overflows...
very stupidly simple... |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Tue Nov 07, 2006 8:04 am |
|
|
Lots of comments.
You don't need to clear the interrupt in the function. Unless you add the keyword 'noclear' to the definition, the compiler does this for you. Then, don't disable the interrupt in the function. This does nothing, since the hardware of the chip, disables the global interrupts as soon as the interupt handler is called. Now, the logic of your button test function is complex, and potentially may well not do what you expect. In C, operators of the same 'precendence' evaluate in different orders, according to the operator involved. With the rules of precedence applied before this. As written, it ought to probably do what you expect (&& has lower precedence than == or !=), but I'd not want to rely on it. Generally, much better to bracket the sections, to force the evaluation order to be what you expect.
You don't post what you are putting into the value 'T125MS'. As you describe it, should be 34285.
However none of these should stop it working.
The obvious question then becomes, "what happens in the main code, when 'ButPushedFlag' is true"?.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|