View previous topic :: View next topic |
Author |
Message |
kmp84
Joined: 02 Feb 2010 Posts: 354
|
16F1847 Out of ROM |
Posted: Wed Feb 03, 2021 4:46 am |
|
|
Hello,
I have a code that is written for 8051 device and take 5791 bytes. I'm trying to translate to PIC16F1847 with 8K Words flash and compiller tells me:
Quote: |
*** Error 71 "D:.............Out of ROM, A segment or the program is too large Task_1
Seg 00021-007FF, 0424 left, need 007FA
Seg 00800-00FFF, 0800 left, need 00859
Seg 01000-017FF, 0800 left, need 00859
Seg 01800-01FFF, 0800 left, need 00859
Seg 00000-00002, 0000 left, need 00859 Reserved
Seg 00003-00003, 0001 left, need 00859
Seg 00004-00020, 0000 left, need 00859 Reserved
Seg 00021-007FF, 0424 left, need 00859
|
CCS v5.093
Any idea why code memory not enough?
Best Regards! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 03, 2021 4:52 am |
|
|
You have some routines that are too large to fit into a code page.
Try breaking them up into two or more smaller routines.
This "too large" routine can also be the main() routine. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 354
|
|
Posted: Wed Feb 03, 2021 5:09 am |
|
|
Hi,
Main routine is just few row. Problem is "Task_1" which is about <100 rows code. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9240 Location: Greensville,Ontario
|
|
Posted: Wed Feb 03, 2021 5:32 am |
|
|
While Task_1 is '<100 rows of code', it appears to be over 3,000 bytes long.
That PIC has banks of memory, 2K each, and you can't put 3000 bytes of code into 2000 bytes of memory.
As PCM_P says, you'll have to recode 'Task_1' into smaller 'chunks' so that the compiler san fit it into the PIC.
Without seeing your code, one way is to create 'functions' to replace code.
Consider 'all-in-one' code that scans a keypad, reads the ADC, displays on LCD, then sends data to a PC.
Instead of 4 'continuous' operations, create 4 'functions' that are called by 'Task_1'.
The compiler will 'fit' the functions into the PIC memory and 'connect' them so that they operate as the original 'Task_1' was supposed to.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Wed Feb 03, 2021 7:39 am |
|
|
It is very important to understand, that 'lines' has no relation really to
the actual size of code.
You can have a line like 'delay_cyles(1)', which uses just one instruction,
or a line line:
a=exp(b);
which can in itself easily use a KB of code space!...
Things like floating point maths, or prints, _drink_ code space.
Then if a routine, calls another routine, that is used just once, by default,
the compiler will tend to make this routine 'inline'. Attaching it into
the original routine. You have to add #separate to the declaration of the
routine, to force it to be kept as a separate entity.
The sheer size of FP maths, is why 'old hands' here will suggest that if
you do use this, 'think again', and try to code as scaled integers instead.
For instance (without setup etc.):
Code: |
float val;
int16 reading;
reading=read_adc();
val=(reading*5.0)/1024;
printf("Voltage is %5.3f/n", val);
|
Then compare with:
Code: |
int32 val;
int16 reading;
reading=read_adc();
val=(reading*5000)/1024;
printf("Voltage is %5.3lw/n", val);
|
The latter will be perhaps 10* faster, and use less than 1/4 the code space.
Instead of doing the calculation as a floating point number it is being
done as an integer a thousand times larger. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 354
|
|
Posted: Wed Feb 03, 2021 7:44 am |
|
|
Quote: |
As PCM_P says, you'll have to recode 'Task_1' into smaller 'chunks' so that the compiler san fit it into the PIC.
Without seeing your code, one way is to create 'functions' to replace code |
"Task_1" program manage serial communication data and put it to structure. It's no easy to separate to smaller programs.
May be I have to return to 8051. :(
Best Wishes! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Wed Feb 03, 2021 8:29 am |
|
|
Or use a PIC18, instead of a PIC16... |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 354
|
|
Posted: Wed Feb 03, 2021 9:19 am |
|
|
The reason I work with this PIC16 is that hardware are ready and I'm trying to upgrade functionality. Not that PIC16, PIC18 are bether than Silabs C8051xxx
Thanks for help,
Best Wishes! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9240 Location: Greensville,Ontario
|
|
Posted: Wed Feb 03, 2021 9:31 am |
|
|
I did a LOT of '8051' family coding, both ASM and BASIC52 then 'jumped ship' and got into PICs 2.5 decades ago, so I'm familiar with both.
I still have working wirewrapped remote energy controllers based on the 8032, plus a lot of chips. All that was replaced with an 18F46K22.....
If you want, PM me the PIC code, i may be able to offer ways to get it to fit.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Wed Feb 03, 2021 11:02 am |
|
|
Is your board PDIP or SSOP?.
If SSOP, there are 20pin PIC18's. Chips like the 18F16Q40/41.
Far more flexible and capable than the PIC16.
However it should not be hard to split up your serial handler. For example
separate the receive handling from the parsing. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9240 Location: Greensville,Ontario
|
|
Posted: Wed Feb 03, 2021 12:13 pm |
|
|
That's why I offered to help, 'offline', cause posting 3K of code is a LOT !
Sometimes a 'fresh pair of eyes' can see a simple, easy solution or a workable alternative. |
|
|
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
|
Posted: Wed Feb 03, 2021 12:47 pm |
|
|
Why not post some lines of your 8051 code |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Wed Feb 03, 2021 12:50 pm |
|
|
Except he is saying the C code is only 100 lines. Not too silly at all. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 354
|
|
Posted: Wed Feb 03, 2021 1:26 pm |
|
|
Hi,
It's no problem to post code, but I don't think it makes sense, because I have second "Task2" which also have to tune and that would be pointless!
Quote: |
Is your board PDIP or SSOP?.
If SSOP, there are 20pin PIC18's. Chips like the 18F16Q40/41.
Far more flexible and capable than the PIC16.
|
My device is 20 pin SSOP, but power pins for 18F16Q40/41 are different.
P.S
The "18F16Q40/41" are very interesting chips but I don't think to start new project with PIC. I move slowly to 8 bit MCU Silabs C8051Fxxx and EFM8 because developing new projects and debugging is faster and stable!
Thanks again! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9240 Location: Greensville,Ontario
|
|
Posted: Wed Feb 03, 2021 3:08 pm |
|
|
re: "Task_1" program manage serial communication data and put it to structure. It's no easy to separate to smaller programs.
I do that with my remote energy control system. send 'updated on/off times' for slave heating units and parse the data into a propriatory serial data stream to up to 32 slaves up to 15 miles away on solid copper. I've actually takene the original 6800 8KN ASM converted to BASIC52 to tun on an 8032 system and now converted for a 3rd time. I currently use the PIC18F46K22 for 99% of all products and have never run out of memory,peripherals or pins. I learned 'C' through the generous examples that CCS supplied with PCM 2v534 some 20+ years ago. I'm NOT a 'schooled' trained programmer but it all works. The PICs have been reliable and stable, though I 'debug' in the real world as no 'simulator' or 'ICD' IS the real World.
I can't say the PIC is better than the 8051, heck I've still got 8008 PCBs here....What I will say is that you should choose a more powerful PIC, spend an extra 50 cents even if you don't need 40 pins or 2 UARTS..yet... All projects 'grow' so having a known 'powerful' micro wil save you a LOT of R&D time, which IS money. |
|
|
|