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

Large array in RAM

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







Large array in RAM
PostPosted: Thu Mar 26, 2009 5:31 am     Reply with quote

Hi all,

I am trying to create a large array in RAM to store 120 16-bit numbers such that I can access them in the most efficient way (in terms of processor time). I am using a PIC16F876A with the PCM compiler. Simply declaring:

Code:
long events[120];


gives me the compiler error 'Data item too big'; I am a bit of a C/low-level-PIC novice so I'm guessing this is something to do with the data spanning a bank in RAM? Either way, could someone please suggest the best method for storing such an array or structure so that reading data from a particular element is done in an efficient manner?

On a similar note, I am a little cofused as to CCS' response to the following line:

Code:
long events[60];


which gives the error 'Not enough RAM for all variables'. However, declaring the following does not:

Code:
long events[30];
long events2[30];



Apologies for the probably obvious questions above, but I'm trying to find my feet with the nuances of C on a PIC!

Many thanks,
Angus
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Mar 26, 2009 6:18 am     Reply with quote

PIC16 in special has limited RAM and some restriction in memory layout additionally. According to the bank structure, an array can't be larger than 128 Bytes, which explains the first error message.

Furthermore, the usable RAM has to be interleaved with existing special function registers in four banks, which further restricts the available array size. With 16F877 it's 80 respectively 96 Bytes, which explains your second observation.

You may want to consult FIGURE 2-3: PIC16F876A/877A REGISTER FILE MAP in the datasheet and the CCS C generated *.sym file showing the actual memory layout of your design, to see if the compiler misses any available option. If not, you simply have to split your data accordingly.
Angus_Thomson
Guest







PostPosted: Thu Mar 26, 2009 7:23 am     Reply with quote

Many thanks for your help; looking at the SYM file makes things a lot clearer. I guess I'll simply split the array into 3 in the seperate banks.



Cheers!

Angus



FvM wrote:
PIC16 in special has limited RAM and some restriction in memory layout additionally. According to the bank structure, an array can't be larger than 128 Bytes, which explains the first error message.

Furthermore, the usable RAM has to be interleaved with existing special function registers in four banks, which further restricts the available array size. With 16F877 it's 80 respectively 96 Bytes, which explains your second observation.

You may want to consult FIGURE 2-3: PIC16F876A/877A REGISTER FILE MAP in the datasheet and the CCS C generated *.sym file showing the actual memory layout of your design, to see if the compiler misses any available option. If not, you simply have to split your data accordingly.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 26, 2009 10:44 am     Reply with quote

Here is an example of using "access routines" to handle r/w to multiple
smaller arrays:
http://www.ccsinfo.com/forum/viewtopic.php?t=20955&start=3
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