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

Compiler skipping calls to functions??

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



Joined: 17 Jan 2006
Posts: 66

View user's profile Send private message

Compiler skipping calls to functions??
PostPosted: Mon Nov 06, 2006 6:32 am     Reply with quote

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??? Sad

I'm using 3.242 version on a PIC16F877.

Thanks a lot,

Juanma
Neckruin



Joined: 17 Jan 2006
Posts: 66

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 3:08 am     Reply with quote

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 Confused
Any ideas????
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 3:17 am     Reply with quote

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.
Neckruin



Joined: 17 Jan 2006
Posts: 66

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 3:23 am     Reply with quote

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)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 3:27 am     Reply with quote

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.
Neckruin



Joined: 17 Jan 2006
Posts: 66

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 3:39 am     Reply with quote

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...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 3:45 am     Reply with quote

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.
Neckruin



Joined: 17 Jan 2006
Posts: 66

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 3:54 am     Reply with quote

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
Neckruin



Joined: 17 Jan 2006
Posts: 66

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 5:37 am     Reply with quote

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 Embarassed

Thanks in advance

Juanma
Neckruin



Joined: 17 Jan 2006
Posts: 66

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 6:16 am     Reply with quote

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...
Ttelmah
Guest







PostPosted: Tue Nov 07, 2006 8:04 am     Reply with quote

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
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