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" error and PIC16F636

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



Joined: 27 Jan 2010
Posts: 3

View user's profile Send private message

"not enough ram" error and PIC16F636
PostPosted: Wed Jan 27, 2010 10:22 am     Reply with quote

Hi gents
I'm using CCS 3.249, and I'm trying to program a PIC16F636, but I'm having a problem with the RAM memory,
When I'm compiling I'm using 76% RAM and 12% of ROM.

I add one int16 variable usually 2% of RAM, and CCS is sending "not enough ram"

I was supposed to get : 78% RAM and 12% of ROM.

Do you have any suggestion to solve my problem, I'm not using all the memory.

Thanks!

Fabien
Ttelmah
Guest







PostPosted: Wed Jan 27, 2010 10:37 am     Reply with quote

Possibly.
#device *=16

By default, the compiler only accesses the first bank of memory. Allows the code to be slightly smaller, and faster, with no bank switching involved. The above tells the compiler to use all the memory.
However on your chip, all the available RAM is in the bottom bank, so should be accessible without this. But, it sounds as if possibly the chip is not accessing the access bank area (top 16 locations), so worth trying this.

An int16, uses more than 2%. Actually 3.125%. This chip has just 64 bytes of RAM, so a 2 byte variable uses 1/32 of the memory space.

Remember also, that if (for instance), you add a 16bit variable, and in doing so add 16bit arithmetic operations, the 'scratch' RAM used by the compiler will also increase, so a single variable could result in more memory being used than you think....

Best Wishes
Fabien



Joined: 27 Jan 2010
Posts: 3

View user's profile Send private message

PostPosted: Wed Jan 27, 2010 11:08 am     Reply with quote

Hi Ttelmah,
I tried to put #device *=16, but nothing change...I can't use more than 76% of RAM.

I'm not using the variable to make arithmetic operations I'm just calling them to send via SPI to another component, my variable are like this one:
Code:

int16 ALC_BLOCK [6][2] = { { 0x0F11 , 0x1400 } ,
                           { 0x0F0A , 0x0B49 } ,
                           { 0x0F0B , 0x07FD } ,
                           { 0x0F0C , 0x0401 } ,
                           { 0x0F14 , 0x08F4 } ,
                           { 0x0F15 , 0x00E4 } } ;

Fabien
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 27, 2010 2:24 pm     Reply with quote

I compiled the test program below with vs. 3.249 and got the following
result in the .LST file:
Quote:

CCS PCM C Compiler, Version 3.249, xxxxx 27-Jan-10 12:23

Filename: pcm_test.lst

ROM used: 226 words (11%)
Largest free fragment is 1822
RAM used: 127 (100%) at main() level
127 (100%) worst case
Stack: 0 locations

MPLAB Output Window:
Quote:

0 Errors, 0 Warnings.
Loaded C:\Program Files\PICC\Projects\PCM_Test\pcm_test.cof.
BUILD SUCCEEDED: Wed Jan 27 12:23:38 2010


Test program:
Code:

#include <16F636.H>
#fuses XT, NOWDT, BROWNOUT, PUT
#use delay(clock=4000000)

int16 ALC_BLOCK [6][2] = { { 0x0F11 , 0x1400 } ,
                           { 0x0F0A , 0x0B49 } ,
                           { 0x0F0B , 0x07FD } ,
                           { 0x0F0C , 0x0401 } ,
                           { 0x0F14 , 0x08F4 } ,
                           { 0x0F15 , 0x00E4 } } ;

int16 ALC_BLOCK1 [6][2] = {{ 0x0A11 , 0x1A00 } ,
                           { 0x0A0A , 0x0A49 } ,
                           { 0x0A0B , 0x0AFD } ,
                           { 0x0A0C , 0x0A01 } ,
                           { 0x0A14 , 0x0AF4 } ,
                           { 0x0A15 , 0x0AE4 } } ;


int16 ALC_BLOCK2[6][2] =  {{ 0x0B11 , 0x1B00 } ,
                           { 0x0B0A , 0x0B49 } ,
                           { 0x0B0B , 0x0BFD } ,
                           { 0x0B0C , 0x0B01 } ,
                           { 0x0B14 , 0x0BF4 } ,
                           { 0x0B15 , 0x0BE4 } } ;

int16 ALC_BLOCK3[6][2] =  {{ 0x0C11 , 0x1C00 } ,
                           { 0x0C0A , 0x0C49 } ,
                           { 0x0C0B , 0x0CFD } ,
                           { 0x0C0C , 0x0C01 } ,
                           { 0x0C14 , 0x0CF4 } ,
                           { 0x0C15 , 0x0CE4 } } ;


int16 ALC_BLOCK4[4][2] =  {{ 0x0D11 , 0x1D00 } ,
                           { 0x0D0A , 0x0D49 } ,
                           { 0x0D0B , 0x0DFD } ,
                           { 0x0D0C , 0x0D01 } };

int16 a, b, c, d, e;

//======================================
void main()
{

while(1);
}
Ttelmah
Guest







PostPosted: Wed Jan 27, 2010 3:35 pm     Reply with quote

I think you are not understanding how large your variable is.
What you post is twelve int16 variables. 24 bytes, and would use 37.5% of the total RAM. You don't have this much available...
So the compiler is 'right'.
However, it sounds as if you don't actually need them to be _variables_ at all?. You talk about 'just sending them over SPI'. The point about a 'variable', is that it is 'variable' (can be changed), so has to be stored in RAM. If these are fixed values, then declare the data as a constant instead...

Best Wishes
Fabien



Joined: 27 Jan 2010
Posts: 3

View user's profile Send private message

PostPosted: Thu Jan 28, 2010 2:43 am     Reply with quote

Hi gents, Thanks for your reply,
i switched my variables to constante like this :
Code:

int16 const ALC_BLOCK [6][2] = { { 0x0F11 , 0x1400 } ,
                           { 0x0F0A , 0x0B49 } ,
                           { 0x0F0B , 0x07FD } ,
                           { 0x0F0C , 0x0401 } ,
                           { 0x0F14 , 0x08F4 } ,
                           { 0x0F15 , 0x00E4 } } ;


my data memory came back to 5%...

But i can't use my data in my function i've the following error
"attempt to create a pointer to a constant"

the function call is :
Code:

write_internal_data_memory(ALC_BLOCK,6*2);


and the function is
Code:

void write_internal_data_memory (int16 *block, int8 dimension)
{
  int1 CR1_B7 = 1 ;
  int8 i ;
  int8 save = 0 ;

  for(i=0; i<dimension; i=i+2)
  {
    mcu_data_write(CR6_ADDR, (block[i]&0xFF00)>>8);
    mcu_data_write(CR7_ADDR, block[i]&0x00FF);
    mcu_data_write(CR8_ADDR, (block[i+1]&0xFF00)>>8);
    mcu_data_write(CR9_ADDR, block[i+1]&0x00FF);
    save=mcu_data_read(CR1_ADDR);
    mcu_data_write(CR1_ADDR, save|0x80);
    do
    {
      CR1_B7=((mcu_data_read(CR1_ADDR)&0x80)>>7);
    }
    while(CR1_B7==1);
  }
}


thanks for your help
Ttelmah
Guest







PostPosted: Thu Jan 28, 2010 2:55 am     Reply with quote

Since they are constants, do you actually 'need' to hand them to the function?. Declare the value inside the function that uses it, and just access the elements as an array.
Do a search here for 'pointer to constant', to see 'why' this is necessary...

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