View previous topic :: View next topic |
Author |
Message |
danielz85
Joined: 22 Sep 2012 Posts: 37
|
strange memory issue in standard pic |
Posted: Sun Oct 21, 2012 4:22 am |
|
|
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;
}
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Sun Oct 21, 2012 5:21 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Sun Oct 21, 2012 8:06 am |
|
|
#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 |
|
![](templates/subSilver/images/spacer.gif) |
danielz85
Joined: 22 Sep 2012 Posts: 37
|
|
Posted: Sun Oct 21, 2012 9:00 am |
|
|
thanks!!! |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Oct 22, 2012 3:53 pm |
|
|
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.
Have any members who read this thread ever used the 16F505 for a real world, (non-school assignment), deliverable application? |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Mon Oct 22, 2012 4:25 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Mon Oct 22, 2012 4:40 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Mon Oct 22, 2012 8:23 pm |
|
|
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!! |
|
![](templates/subSilver/images/spacer.gif) |
|