View previous topic :: View next topic |
Author |
Message |
Doralice
Joined: 03 Feb 2011 Posts: 5 Location: Florence, Italy
|
Look up table with PIC12F683 in CCS C |
Posted: Thu Apr 14, 2011 8:49 am |
|
|
Hello!!
I'm working with a PIC12F683 and I'm using a CCS C compiler.
I need to allocate in program memory two look up tables, the first is declared as
const char potenz[178]={...};
The second has 256 elements, each one 16 bits length:
const int16 potenz1[256]={...};
As a result, after building, the first table is correctly allocated, but the second one is missing.
Each words in program memory is 14 bits length.
Can allocate it a table with elements of 16 bits length?
Any suggestion is appreciated!!
Thanks!! _________________ Bugs will appear in one part of a working program when another 'unrelated' part is modified.
Doralice |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 14, 2011 12:21 pm |
|
|
What's your compiler version ? I tried it just now, and the compiler stores
it as a ton of RETLW's. It's there. But to see it, you need to edit the
12F683.h file and comment out the #nolist statement at the top of the file.
Then re-compile and look at the .LST file. You should see the RETLW's.
Also, to see the data, you need to access the const array with a variable.
If you just access a few elements with constant indexes, the compiler
will optimize those accesses into MOVLW statements. It won't put the
whole array into Flash memory. It does this to save ROM. |
|
|
Doralice
Joined: 03 Feb 2011 Posts: 5 Location: Florence, Italy
|
Ram and Rom memory |
Posted: Fri Apr 15, 2011 7:50 am |
|
|
Good evening,
my compiler version is:
"CCS C Compiler PCM version 4.118"
I've explained below the declarations I've made inside my declaration file "potenz.h". I have to store this two look up tables in the program memory.
Code: |
const char potenz []= //614 bytes
{142,
142,
142,
142,
142,
142,...};
const char potenz1 []= //78 bytes
{55,
55,
55,...};
|
I've commented out, first of all, #nolist, but nothing happened, so I've tried to comment out also #list, but it stores in program memory only the first look up table. Looking at the lst file, I'll suppose it stores the second table in RAM memory because I've assigned an element of the second table to a variable and it has been translated with a MOVLW instruction.
How can I find out the address where each variables is allocated in Ram?
Can I force the compiler to store the second look up table in program memory?
Thx for your patience!
_________________ Bugs will appear in one part of a working program when another 'unrelated' part is modified.
Doralice |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Fri Apr 15, 2011 2:38 pm |
|
|
It is not stored in RAM memory. What is applying is the second paragraph in PCM programmers reply. Since you are only accessing a fixed location, the compiler is 'optimising' the table away, and just storing the used value as a MOVLW.
You need a single line like:
val=potenzl[val];
where 'val' is a variable, to make the compiler realise that it can't predict what lines are needed, and it'll then store the whole table.
Best Wishes |
|
|
Doralice
Joined: 03 Feb 2011 Posts: 5 Location: Florence, Italy
|
Code optimization |
Posted: Mon Apr 18, 2011 1:37 am |
|
|
Yes,
thank you and PCM Programmer.
Now I've understood how the compiler optimizes the code in memory.
I'll try now to allocate a table with char elements and a table with int16 elements.
Doralice _________________ Bugs will appear in one part of a working program when another 'unrelated' part is modified.
Doralice |
|
|
bells_electronics
Joined: 05 Dec 2009 Posts: 40
|
|
Posted: Sun Apr 22, 2012 12:24 pm |
|
|
@ Doralice
Did you solve your issue? if yes then how? |
|
|
|