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

strange memory issue in standard pic

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



Joined: 22 Sep 2012
Posts: 37

View user's profile Send private message

strange memory issue in standard pic
PostPosted: Sun Oct 21, 2012 4:22 am     Reply with quote

Hi,

I'm using PIC16F506.
I defined an int array of size 5, and the compiler said I was out of memory.

specifically:
I'm trying to do: "int arr[5]"
and I get the following error:
Quote:
Not enough RAM for all variables


As far as I understand, the pic is useless without the ability to define such a small array. What am I missing out on here?
Another important thing: does the fact that the pic has 1024 Word Program Memory mean that I can put only 1024 machine-instructions on it?
Thanks a lot.



Code:
#include <16F506.h>

#device adc=8
#fuses INTRC_IO, IOSC8, NOWDT
#use delay(clock = 8M)
#use rs232(baud=9600,xmit=pin_B0,rcv=pin_B1)

//consts

void main() {

int i=0;
int arr[3];
int adc_value;
setup_comparator(NC_NC_NC_NC);
setup_adc_ports(AN2);
set_adc_channel(2);
setup_adc( ADC_CLOCK_INTERNAL );
setup_adc(ADC_CLOCK_DIV_16);

delay_us(20);
delay_ms(15000);
while (TRUE)
{
   
   adc_value=READ_ADC();         //READ FROM ADC PORT
//   DELAY_US(4);
   arr[i] = adc_value;
   i++;
   
   if (i==3)
      {
         for (int k=0 ; k<3 ; k++)
             {
                 delay_ms(500);
                 printf("%d ",arr[k]);
             }
         break;
   }
}
}
temtronic



Joined: 01 Jul 2010
Posts: 9163
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Oct 21, 2012 5:21 am     Reply with quote

1) had to add

int k=0;

at the begiining of main to get rid of the 'int' in the line

for (int k=0 ; k<3 ; k++)

so that program would compile...

2) the printf(..) line is taking up a LOT( most) of the RAM !
I remarked it out and could get the array to hold 5 bytes, no problem.


I suggest trying the simpler putc() function and see what happens.


hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19336

View user's profile Send private message

PostPosted: Sun Oct 21, 2012 8:06 am     Reply with quote

#device *=16

By default, your code will only access the first page of RAM. Makes code smaller, so if you don't need much RAM, can be better, but to access the whole of the RAM, this is needed.
As temtronic says, your printf, will use a lot of RAM, and with only the first page available, this gives your problem...

Best Wishes
danielz85



Joined: 22 Sep 2012
Posts: 37

View user's profile Send private message

PostPosted: Sun Oct 21, 2012 9:00 am     Reply with quote

thanks!!!
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Oct 22, 2012 3:53 pm     Reply with quote

BTW: did this program have a reason to exist,
other than to show how VERY limited the 16f505 really is ?

Between the soft UART declaration,
and the printf() function , you have done MAXED out the part, with almost no utility to show for it. Very Happy Very Happy Very Happy

Have any members who read this thread ever used the 16F505 for a real world, (non-school assignment), deliverable application?
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Oct 22, 2012 4:25 pm     Reply with quote

asmboy wrote:

Have any members who read this thread ever used the 16F505 for a real world, (non-school assignment), deliverable application?


No, but I used a 12c672 for reading the temp/voltages inside my RS/6000.


for an 8pin IC, it had Dallas-1wire for 4 DS182x Temp sensors, (2) ADC inputs and RS232 (TX only, IIRC)

Worked great!

(but had a lot more memory)
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
temtronic



Joined: 01 Jul 2010
Posts: 9163
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Oct 22, 2012 4:40 pm     Reply with quote

I've used them to get backup lights onto 'utility' trailers that only have 4 pin wiring as well as 'code converters' for 25 year old proprietary communications equipment, oh yeah, also to 'upgrade' a remote energy control system from 16 4000series devices to 1 PIC.

see...bigger is NOT necessarily better !!

hth
jay
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: Mon Oct 22, 2012 8:23 pm     Reply with quote

danielz85 wrote:
thanks!!!


Obviously it is not a real app or it would crash anyway because you always increment i in the while loop and therefore are writing outside the array boundary of arr[]
_________________
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