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

Help with interrupts

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



Joined: 06 Sep 2004
Posts: 5
Location: Southampton, UK

View user's profile Send private message

Help with interrupts
PostPosted: Mon Sep 06, 2004 4:24 am     Reply with quote

I need to run a fairly long section of code on an interrupt. I know this is bad practice but i do not need to observe anything else once this interrupt is activated.

Just trying to call my 'longish' function from within the interrupt causes an 'out of rom' message. I'm using a 16f877 which is only 20% full.

Any help would be much appreciated
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Sep 06, 2004 5:27 am     Reply with quote

Which compiler version are you using? The release notes for v3.209 mention a fix for large ROM chips.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Mon Sep 06, 2004 5:44 am     Reply with quote

Meanwhile, try putting the big code in a separate function, and call that function from inside your ISR. Don't forget to put the line

#SEPARATE

Before your function so it won't get implemented inline.
huwemajor



Joined: 06 Sep 2004
Posts: 5
Location: Southampton, UK

View user's profile Send private message

PostPosted: Mon Sep 06, 2004 10:15 am     Reply with quote

Right i have tried using #separate to no avail. The code i am calling is a function anyway, like you suggested.

The problem is due to having a delay in the function, again i realise this is bad practice. Any further ideas would be much appreciated, I'll also update my compiler and see if that helps.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Mon Sep 06, 2004 2:23 pm     Reply with quote

Set a flag and handle it in the main loop. If the function is too big then break it up. printf's are a hog.
huwemajor



Joined: 06 Sep 2004
Posts: 5
Location: Southampton, UK

View user's profile Send private message

PostPosted: Mon Sep 06, 2004 3:19 pm     Reply with quote

Ok i have tried using the downloaded demo software which says it works with my PIC, the 16F877. This didn't help the matter.

But one thing that confuses me is that the ROM usage is on 81% without the interrupt, but is then full with the interrupt. I am obviously being stupid but, why does it take over 19% of the ROM to store the program counter value and jump to a section of code that gets used elsewhere and jump back again after that.

I would have thought that would be a simple task for a PIC.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 06, 2004 4:01 pm     Reply with quote

Quote:

I have tried using the downloaded demo software which says it works with my PIC, the 16F877

On the CCS Demo page, it says: There is a 2K program size limit.
http://www.ccsinfo.com/demo.shtml
Quote:

But one thing that confuses me is that the ROM usage is on 81% without
the interrupt, but is then full with the interrupt


19% of 2048 = 389 ROM words (approx.) remaining.

When you put in the isr, the compiler will add 50+ lines of ASM code
just to create the interrupt dispatcher. I suspect that you have some
lengthy code in the isr, which uses up the rest of the ROM words.
huwemajor



Joined: 06 Sep 2004
Posts: 5
Location: Southampton, UK

View user's profile Send private message

PostPosted: Mon Sep 06, 2004 4:45 pm     Reply with quote

Sorry i don't think its that. I have also tried compiling with the full version of CCs and the exact same thing happens.

And anyway its at 81% if i leave in the interrupt routine but just remove the function call within the ISR
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 06, 2004 5:29 pm     Reply with quote

Post the C source code for the isr. If some of the variables used
in the isr are globals, then show the declarations for them too.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Mon Sep 06, 2004 7:22 pm     Reply with quote

If you don't call the function then the compiler will not include it! I am pretty sure that it is because of the demo software.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Mon Sep 06, 2004 7:46 pm     Reply with quote

One thing comes to mind: As PCM Programmer calculated, you probably have about 390 words free. The ISR overhead is about 60 words, so that leaves you with 330 words.
Since you are using PIC16F877, you must be getting the error message "Out of ROM, a segment is too large". You may have 330 words free, but it is probably broken down between different segments. CCS can't implement a function across two segments, so if you have a big function, you'll need to have at least one segment with big enough free space to hold that function. You can see the amount of free memory in each segment in the .STA (statistics) file. Here is an example:

Quote:

Segment Used Free
--------- ---- ----
00000-00003 4 ����0
00004-00034 49 0
00035-007FF 1994 1
00800-00FFF 2030 18
01000-017FF 2006 42
01800-01826 39 0
01827-0182F 0 9
01830-01890 92 5
01891-01BFE 674 204
01BFF-01C08 2 8
01C09-01FFF 605 410


As you can see this program has more than 650 words available, but any functions bigger than 410 bytes will cause 'Out of ROM error'. That is probably the culprit in your case.
To work around this problem, use #separate to manually place all (or at least enough of) the functions in your code until you get a segment with free space big enough. It is doable, just takes a bit of time. The information in the .SYM and .STA file are very handy in doing this.

And one more thing, if you are using ICD, the compiler adds a little program at the end of the program memory. In this case you will not have 390 words free, even if the compiler reports so.
bdavis



Joined: 31 May 2004
Posts: 86
Location: Colorado Springs, CO

View user's profile Send private message

PostPosted: Mon Sep 06, 2004 10:30 pm     Reply with quote

If you don't need to do/observe anything else once in the interrupt, then you may want to consider polling for the interrupt and eliminating the interrupt handler altogether...
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Tue Sep 07, 2004 4:35 am     Reply with quote

Correction to my previous post: What I meant was use #separate and #org to manually place the functions in the memory. If you look at the example I posted, I had done the same to fit a big code in PIC16F877 memory. That is why there are so many segments in it.
huwemajor



Joined: 06 Sep 2004
Posts: 5
Location: Southampton, UK

View user's profile Send private message

PostPosted: Tue Sep 07, 2004 5:08 am     Reply with quote

Thanks Haplo, PCM Programmer suggested that last night and fixed it for me.

It now all works.

Thanks to everyone else as well.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 07, 2004 12:07 pm     Reply with quote

The solution that I suggested in response to a PM, was to take 3 lines
of floating point calculations that were in main(), and move them into
a function of their own. Then call that function from main().

His main() function was large, and by putting the floating point code
in its own function, this allowed the compiler to partition the functions
into the 4 ROM segments successfully.

I recommended against using #separate because then you have to
watch the .LST file to see if you have exceeded the 8 stack levels
available in the 16F877.

To demonstrate this, the test program shown below uses #separate in
several chained function calls, and it uses 9 stack levels. No compiler
warning is given. This is stated in the manual.

Code:
CCS PCM C Compiler, Version 3.209, xxxxx    07-Sep-04 11:04

               Filename: C:\PICC\TEST\test.LST

               ROM used: 53 words (1%)
                         Largest free fragment is 2048
               RAM used: 5 (3%) at main() level
                         6 (3%) worst case
               Stack:    9 locations


Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
//=======================

#separate
void func9(void)
{
char c;
c = 0x55;
}
//----------------------
#separate
void func8(void)
{
func9();
}
//----------------------
#separate
void func7(void)
{
func8();
}
//----------------------
#separate
void func6(void)
{
func7();
}
//----------------------
#separate
void func5(void)
{
func6();
}
//----------------------
#separate
void func4(void)
{
func5();
}
//----------------------
#separate
void func3(void)
{
func4();
}
//----------------------
#separate
void func2(void)
{
func3();
}
//----------------------
#separate
void func1(void)
{
func2();
}

//==================
void main()
{
func1();

while(1);
}
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