|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Help creating large 'float' lookup table |
Posted: Mon Jan 20, 2003 12:41 pm |
|
|
:=Hello,
:=
:=I am using PCM 3.136 and a 16F877. I would like to create a large
lookup table of float values in ROM at compile time and then access them
at run time.
---------------------------------------------------
Here is one method:
Code: | #include "c:\program files\picc\devices\16F877.h"
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT, NOLVP
#use Delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
// ROM TABLES
#org 0x1800, 0x190F // Allow 0x110 bytes for the table
float const ROM_TABLE_0[64] = {
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26,27,28,28,30,31,
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63
};
#org 0x1910, 0x1A2F // Allow 0x110 bytes for the table
float const ROM_TABLE_1[64] = {
100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,
116,117,118,119,120,121,122,123,124,125,126,127,128,128,130,131,
132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,
148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163
};
#org 0x1A30, 0x1B3F // Allow 0x110 bytes for the table
float const ROM_TABLE_2[64] = {
200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
216,217,218,219,220,221,222,223,224,225,226,227,228,228,230,231,
232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,
248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263
};
float get_value_from_rom_table(char table, char index);
//===========================================
main()
{
float value;
value = get_value_from_rom_table(0, 5);
printf("value = \%f\n\r", value);
value = get_value_from_rom_table(1, 63);
printf("value = \%f\n\r", value);
value = get_value_from_rom_table(2, 10);
printf("value = \%f\n\r", value);
while(1); // Prevent PIC from going to sleep
}
//===========================================
float get_value_from_rom_table(char table, char index)
{
switch (table)
{
case 0:
return ROM_TABLE_0[index];
break;
case 1:
return ROM_TABLE_1[index];
break;
case 2:
return ROM_TABLE_2[index];
break;
default:
return 0;
}
} |
Edited on Feb 4, 2005:
Removed the double-spacing that was added when this
post was ported from the old CCS forum to this new one.
Also added code-style formatting so it's easier to read.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10824
Last edited by PCM programmer on Fri Feb 04, 2005 10:54 am; edited 1 time in total |
|
|
Burt Poppenga Guest
|
Re: Help creating large 'float' lookup table |
Posted: Mon Jan 20, 2003 12:55 pm |
|
|
Many thanks for the reply.
So in a nutshell you are suggesting breaking up the large table into smaller tables that can be handled. If each ROM location is 16 bits, then does each entry of:
float const ROM_TABLE_x[] = { 12.4747, ...
end up consuming two rom locations (for the 32 bit float)? If so, I was thinking about using fixed point to encode my data to save ROM space (my data would fit into an 8.8 fixed point number). Does anyone already have CCS C routines to convert:
8.8 fixed -> float
S.7.8 fixed (signed) -> float
float -> 8.8 fixed
float -> S.7.8 fixed
Thanks again,
Burt
___________________________
This message was ported from CCS's old forum
Original Post ID: 10826 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Help creating large 'float' lookup table |
Posted: Mon Jan 20, 2003 1:14 pm |
|
|
:=So in a nutshell you are suggesting breaking up the large table into smaller tables that can be handled. If each ROM location is 16 bits, then does each entry of:
:=
:= float const ROM_TABLE_x[] = { 12.4747, ...
:=
:=end up consuming two rom locations (for the 32 bit float)? If so, I was thinking about using fixed point to encode my data to save ROM space (my data would fit into an 8.8 fixed point number). Does anyone already have CCS C routines to convert:
:=
:= 8.8 fixed -> float
:= S.7.8 fixed (signed) -> float
:= float -> 8.8 fixed
:= float -> S.7.8 fixed
--------------------------------------------------------
On a 16F877, each ROM location is not 16 bits -- it's actually
only 14 bits. In the code that I posted, the compiler puts
a RETLW instruction in each ROM location. The CCS floating
point format uses 4 bytes per float, so that's 4 ROM locations
per entry in the tables.
If you want to pack data into the ROM using all 14 bits, you
can't use RETLW. You'll need to use the read_program_eeprom()
function. Here's an example of that (using text strings):
http://www.ccsinfo.com/forum/viewtopic.php?t=7971
If you need 16 bits, you'll need to go to the 18Fxxx series
processors.
Tell us what your overall goal is. There might be people on
here who could let you know about a better way to do it than
by using float tables.
---------
Edited on Feb 4, 2005:
Corrected the link so it points to the correct article, instead of
giving a "404" error. When this post was ported from the old
CCS forum to this new one, all of the embedded links were broken.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10828
Last edited by PCM programmer on Fri Feb 04, 2005 11:01 am; edited 1 time in total |
|
|
Burt Poppenga Guest
|
Re: Help creating large 'float' lookup table |
Posted: Mon Jan 20, 2003 7:50 pm |
|
|
I have an application that has a sensor hanging off the A/D converter. Based on the sensor reading and configuration of the application, I need to look up a floating point value to complete some computations. As it turns out, I can get away without using floating point numbers (I can use a form of fixed point, and 14 bits is just barely enough).
So I need to have 4 tables, each with approximately 300 entries (longs, where only 14 bits are used).
I can't really go the route of:
#ORG 0x1800, 0xXXX
const int16 ZN_1[300] = {
963,964,966,969,971,973,976,979, ... };
Because the array is just too long (and I don't really want to break up the tables).
So I tried to go this way:
#define ZN_1 0x1800
#ROM ZN_1 = {
963,964,966,969,971,973,976,979,982, ... }
But I am afraid that bad things could happen because the ROM area is not reserved by the compiler. So I tried:
#RESERVE 0x1800:0x1FFF
Right after my #ROM. This caused complier errors in some pretty strange places.
Any help would be great!
Burt
___________________________
This message was ported from CCS's old forum
Original Post ID: 10843 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Help creating large 'float' lookup table |
Posted: Tue Jan 21, 2003 1:54 pm |
|
|
:=So I tried to go this way:
:= #define ZN_1 0x1800
:= #ROM ZN_1 = {
:= 963,964,966,969,971,973,976,979,982, ... }
:=
:=But I am afraid that bad things could happen because the ROM area is not reserved by the compiler. So I tried:
:= #RESERVE 0x1800:0x1FFF
:=
:=Right after my #ROM. This caused complier errors in some pretty strange places.
------------------------------------------------------------
#reserve is used for RAM. You have to use #org for ROM.
The following code works. To see the ROM values, compile
the code, then go to the Window menu in MPLAB, and select
"Program Memory". Scroll down to hex address 0x1800 and
you'll see the data. (It's not shown in the .LST file)
#org 0x1800, 0x1FFF {}
#define ZN_1 0x1800
#ROM ZN_1 = {963,964,966,969,971,973,976,979,982}
___________________________
This message was ported from CCS's old forum
Original Post ID: 10861 |
|
|
Burt Poppenga Guest
|
Re: Help creating large 'float' lookup table |
Posted: Tue Jan 21, 2003 6:28 pm |
|
|
Many thanks ... works like a dream!
___________________________
This message was ported from CCS's old forum
Original Post ID: 10872 |
|
|
little_angel
Joined: 09 Oct 2009 Posts: 3
|
|
Posted: Sat Oct 24, 2009 2:39 am |
|
|
IF i use PIC18 series this method working ?
Example: i wan to display float that contained "-"
-0.3
-1.147
-1.298
I declared with
Quote: | #org 0x180B, 0x190B // Allow 0x110 bytes for the table
float const ROM_TABLE_1[256] = {
000 ~ 255
};
|
but it showed error 126 : Invalid Range
any solutions? |
|
|
Ttelmah Guest
|
|
Posted: Sat Oct 24, 2009 2:58 am |
|
|
256 float values, need 0x400 bytes....
Best Wishes |
|
|
|
|
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
|