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 support@ccsinfo.com

weird switch problem

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







weird switch problem
PostPosted: Wed Jul 20, 2005 9:12 am     Reply with quote

im using the pcml compiler on a PIC16f877 and get a strange error when i try to add code for a barometer to existing code. before i had a switch statement

Code:

switch(input) {
case GET_FORCE:
....
break;
case HEARTBEAT:
...
break;
case DEINIT:
...
break;
default:
....
break;


which worked fine. when i added the barometer code, i found the old components did not work anymore. ive narrowed it down to the fact that just inserting

Code:

case GET_BAROM:
break;


without any acutal barometer code is enough to make the program fail. it seems the compiler cannot handle a switch statement with 5 cases, even though with a previous (windows) compiler we got other identical pics with many more cases than that. Does anyone know a workaround for this? Ive already tried if else's and nesting/multiple switch statements with no results.
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Wed Jul 20, 2005 9:20 am     Reply with quote

How much code is there in the function where your case statement is? If there is a lot of code in that function, AND since your'e using a 16F part, looks like you'll have to start breaking code down into smaller functions and try using the #separate directive and #device *=16 for 16-bit pointers.

I'd start by using the #separate directive first in front of many functions. If that still doesn't work, then start breaking down functions into smaller ones.

So, in the past with growing 16F code, i've done the following in this order:
1. #device *=16 for 16 bit pointers. See if this takes care of your problem.
2. If (1) is not enough, then use #separate
3. If (1) and (2) is not enough, then start breaking down functions into smaller ones.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 20, 2005 10:15 am     Reply with quote

Quote:
im using the pcml compiler on a PIC16f877.
before i had a switch statement

PCML implies that you're using version 2.xxx of the compiler.
What's your exact version ?

You can find the version at the top of the .LST file, which will be in
your project directory.
Guest
Guest







PostPosted: Wed Jul 20, 2005 10:22 am     Reply with quote

Mike, the function the case statement is in is about 50 lines. The code is fairly simple so there are no pointers. Ive tried adding #separate directives to the code, but im not really familiar with them and what they actually do. Could you explain this or point me to a site that does?

PCM, im using 3.227, the latest linux compiler i believe.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 20, 2005 10:55 am     Reply with quote

Quote:
Ive tried adding #separate directives to the code, but im not really familiar with them

See this thread for a warning about using #separate:
http://www.ccsinfo.com/forum/viewtopic.php?t=23243&highlight=separate+stack


Problems with switch-case with regard to the default statement:
http://www.ccsinfo.com/forum/viewtopic.php?t=17868&highlight=switch

Controlling switch-case code generation:
http://www.ccsinfo.com/forum/viewtopic.php?t=20721&highlight=switch
http://www.ccsinfo.com/forum/viewtopic.php?t=18585&highlight=switch

Comments on Linux version. These may not apply to the current version.
http://www.ccsinfo.com/forum/viewtopic.php?t=18884
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Wed Jul 20, 2005 11:12 am     Reply with quote

Actually 3.228 is the latest, which is about 1-2 weeks old (?) New versions sometimes come in faster than you can blink!

You should read the precautions that PCM showed you.

In general, i've used #separate like this:

Code:

...
#separate
void my_fxn(void);  // #separate before the function prototype
...
...
#separate
void my_fxn(void)
{
...
}


You said PIC16F877, right?
I can guarantee you that if you plug in the drop-in equivalent PIC18F442 or PIC18F452, assuming you have PCH, then all your function length woes will disappear, and you won't need any #separate nor #device *=16 directives.

From what I hear in seminars and FAEs, the 16-series is not so C-compiler friendly as the 18F. And the DsPICC is ultimately the most C-compiler friendliest of all the PICs.
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Wed Jul 20, 2005 11:17 am     Reply with quote

I was thinking of going over to Linux to do PIC development.
Okay, so if I buy PCHL from CCS, I can compile and stuff under the Linux environment.

But then what software do you use to program the chips?
Guest
Guest







PostPosted: Wed Jul 20, 2005 12:23 pm     Reply with quote

Sadly i cannot switch to another PIC, we are using a board from Botrics called the Cerebellum. As for how i program it, some of this is most likely cerebellum specific, but here goes.

I have the cerebellum connected to a serial port on my computer, and use ser2net to convert the serial to an network port. Then i can do "telnet localhost <port#>" and enter the passcode to program and then exit (that was all cerebellum specific). Now i havent dealt with PICs that werent on a cerebellum before, so im not sure how you program it. If you use something like tera term then you should be able to use minicom in linux. In minicom i change the settings for ascii-xfr to upload with a certain line delay, and change the settings for minicom for bit parity baud rate etc. Then i upload in minicom using the ascii protocal.

i would suggest trying to upload a windows compiled HEX file from linux before buying pchl.

Also i thought the latest windows compiler was 3.228, but for linux its only up to 3.227, in the update compiler page i only see 3.227 for linux.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Jul 20, 2005 5:52 pm     Reply with quote

I am using PCH 3.228 and I have come across a bug similar to the one you describe. When developing and application I often use stubs for procedures and functions yet to be implemented. Stubs of the form:

Code:

void dummy ()
    {
    }


However with this compiler I found that invoking dummy() may or may not lead to the procedure ever returning. I could not determine how to make it consistently fail (and hence did not file a bug report). If I added more, totally unrelated code elsewhere, then the stub might return. I am working on a similar problem of the form:

Code:

printf("I am here before resetting the CPU\r\n");
reset_cpu();
printf("I should never get here\r\n");


and.... you guessed it - the processor would not reset and instead the second print statement was executed. In order for the processor to reset I had to add a second reset_cpu(); instruction immediately following the first. As with the stub problem I found that adding totally unrelated code elsewhere in the program would change the behaviour and a single reset would then work.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
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