Page 1 of 1

Programming warnings & memory usage

Posted: Wed Oct 07, 2020 3:08 pm
by beneee
I have been working on a program for a 12F1501 and as the project gets bigger so does the program and data space that it uses - this is expected, I am surprised about how quickly they go up though with very little in the project so I am assuming the chip I am using has very little space.

One curiosity is the data space hit 100% and worked then continued to grow and my project is now almost complete and it is now 127.1% and still writing to the chip without issue and working, what is happening here?

I also have 4 warnings which I am assuming are related to the 4 PWMs I am using but unsure how to fix this.

The snip of the compiler message is below and I have attached my program in case you want to look though it and be appalled at the inefficient code - please feel free to edit and optimise.

Thanks
Ben

* From the data sheet, the 12F1501 has 1024 program memory flash words and 64 bytes of data SRAM *

. . . . .

using updated 32-bit floating-point libraries; improved accuracy might increase code size
Small.c: 785: (1257) local variable "_FCR_RETVAL" is used but never given a value (warning)
Small.c: 963: (1257) local variable "_FCR_RETVAL" is used but never given a value (warning)
Small.c: 1141: (1257) local variable "_FCR_RETVAL" is used but never given a value (warning)
Small.c: 1319: (1257) local variable "_FCR_RETVAL" is used but never given a value (warning)
. . .


Memory Summary:
Program space used 304h ( 772) of 400h words ( 75.4%)
Data space used 3Dh ( 61) of 30h bytes (127.1%)
EEPROM space None available
Data stack space used 0h ( 0) of 1h byte ( 0.0%)
Configuration bits used 2h ( 2) of 2h words (100.0%)
ID Location space used 0h ( 0) of 4h bytes ( 0.0%)
Small.fcfx
(23.09 KiB) Downloaded 196 times

Re: Programming warnings & memory usage

Posted: Mon Oct 19, 2020 9:26 am
by beneee
Can anyone point me in the right direction, if no-one can answer is there documentation that explains the memory usage.

Ben

Re: Programming warnings & memory usage

Posted: Mon Oct 19, 2020 10:58 am
by Steve
These are messages from the XC8 compiler. It seems strange that it's working though, as I would have assumed it would fail if too much memory is being used. It might be best to get this value below 100% as it could cause unexpected problems within your program (e.g. variables being overwritten).

Data space is essentially the RAM of the device and is where variables are allocated. If more than 100% of the space is being used, it could show this memory is being recycled for other variables. You could try being more careful about the data types you use (use bytes where you can), reducing the array/string sizes, and perhaps reuse the same global variables. You could also try using local variables instead of global variables as that might make things more efficient.

Re: Programming warnings & memory usage

Posted: Mon Oct 19, 2020 11:32 am
by stefan.erni
Hi Ben

This PIC has very little ram maybe you can switch to one with 256 byte
Here a link to the 8pin 8bit PIC.

https://www.microchip.com/ParamChartSea ... nchID=1001

regards
stefan
PIC8.png
PIC8.png (112.69 KiB) Viewed 4324 times

Re: Programming warnings & memory usage

Posted: Mon Oct 19, 2020 3:35 pm
by beneee
Thanks.

I only picked that one as it had 4 PWM outputs in a 8 pin package so my choices were a bit limited.

Still curious as to why I can use 127% of the available data space.

Ben

Re: Programming warnings & memory usage

Posted: Mon Oct 19, 2020 4:41 pm
by stefan.erni
Hi Ben

Half of the people cannot calculate percentages, that are more than 80%.

I suspect the calculation is wrong.
But you don't have much ram left, with one or two 16Bit more is the limit. A byte need 1Ramplace an integer need 2Ramplace.
Is a 16Pin PIC an option?

regards

Stefan

Re: Programming warnings & memory usage

Posted: Mon Oct 19, 2020 5:12 pm
by medelec35
Hi guys,
I know the XC8 compiler shipped with Flowcode has a bug that reports wrong memory values.
When I went to XC8 versions of 2.00 and greater, bug was no longer present.

Re: Programming warnings & memory usage

Posted: Mon Oct 19, 2020 5:19 pm
by LeighM
hmm, Compiler says you have used 61 of 48 bytes. Datasheet says 64

edit: Martin's post beat mine through the ether :lol:
and explains the issue