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

Not enough RAM for variables

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



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

Not enough RAM for variables
PostPosted: Tue Apr 04, 2006 1:32 am     Reply with quote

Hi,

I 'm using a PIC16LF877A. Declaration of an array of bytes:

Code:
#define BUFFER_SIZE 70

char data[BUFFER_SIZE];


Compiler error: Not enough RAM for variables

1. Why is that?
2. What can I do about that?

kr
Ttelmah
Guest







PostPosted: Tue Apr 04, 2006 2:25 am     Reply with quote

Possible answers:
The first is, have you got '#device *=16' near the start of your program?. If not, then your chip will only use the very first 'bank' of RAM, and will run out of RAM space very quickly. Adding this, gives you access to all the RAM, but with the 'downside' that accesses take slightly more cycles/space (a bank switch may need to be added). Hence the default is to not have this extra command, which for small programs gives 'tighter' code.
Second, you may just be running out of RAM. The chip, only has a total of 368 bytes of RAM, and by the time some if used for scratch variables, any other variables you have, etc. etc., you may simply not have enough space.
The third is to do with how memory is laid out in the chip. Though there is 368 bytes available, this is not in one 'lump'. It is arranged in four banks, with 96 bytes, 80 bytes, 96 bytes, and 96 bytes respectively. Now an array, has to be in a single bank, so if (for instance), you declare four arrays of 50 bytes each, these will have to be put, one into each bank. If you then try to declare a fifth such array, there is nowhere to fit this, since there are now only 46, 30, 46 and 46 bytes 'left' in the four banks. At this point you will get the memory space error, despite their being enough 'space', because there is not the required single 'lump' of space required....

Hopefully your problem is the first, and therefore simply fixed. Otherwise, you are going to have to look more carefully at how you use memory.

Best Wishes
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Tue Apr 04, 2006 3:55 am     Reply with quote

Is there any way that I can see the memory setup of my program. That is seeing how many bytes are still available in the four banks.
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Tue Apr 04, 2006 4:02 am     Reply with quote

I've now added #device *=16 line in the header.
Buffer_size can get up to 95 bytes, which is more then without the statement.

Still @buffer_size = 100, I get the compiler error.

When I compile @buffer_size = 95; the compiler (ccs) says 41% RAM used...
Ttelmah
Guest







PostPosted: Tue Apr 04, 2006 5:00 am     Reply with quote

If you look at the bank sizes I list, you will see why you cannot have a 100 byte array. You should be able to have a 96 byte one.
The .sym file shows the variable allocations.

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