CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Newbie needs help to make a lookup table

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
John_Lintern



Joined: 30 Sep 2004
Posts: 14

View user's profile Send private message Send e-mail

Newbie needs help to make a lookup table
PostPosted: Mon Nov 29, 2004 9:51 am     Reply with quote

I need to use a lookup table of some sort but I have no idea how to do it !

I need a value to be looked up from two variables, 'Throttle Position' and 'RPM'.

Both these variables are 8-bit integers ranging from 0 to 255.

The lookup value will also be an 8-bit integer ranging from 0 to 255.

So I need to create a MAP, just like the fuel and ignition MAPS used in engine management control units.

If I used a lookup table for every value of the two inputs I would have a table of 65,025 bytes ! (255*255)

So I have reduced this by using a resolution of 5 for the 'Throttle Position' and a resolution of 4 for the 'RPM', this gives me a table of 3,328 bytes (52*64).

i.e.

0 4 8 12 16 20 24 28 32 ......252
5
10
15
20
25
...
...
...
255

The values of the lookup table will probably be stored in an external eeprom at a later date.

But for now, what is the best way for me to create a lookup table ?

Can I use something like...

BYTE CONST SINE_WAVE[200,100] = {
128,132,136,139,143,147,150,154,158,161,165,169,172,176,179,
182,186,189,192,195,199,202,204,207,210,213,215,218,220,223,
225,227,229,231,233,235,237,238,240,241,242,243,244,245,246,
247,247,247,248,248,248,248,248,247,247,247,246,245,244,243,
242,241,240,238,237,235,233,231,229,227,225,223,220,218,215,
213,210,207,204,202,199,195,192,189,186,182,179,176,172,169,
165,161,158,154,150,147,143,139,136,132,128,124,120,117,113,
109,106,102,98,95,91,87,84,80,77,74,70,67,64,61,57,54,52,49,
46,43,41,38,36,33,31,29,27,25,23,21,19,18,16,15,14,13,12,11,
10,9,9,9,8,8,8,8,8,9,9,9,10,11,12,13,14,15,16,18,19,21,23,
25,27,29,31,33,36,38,41,43,46,49,52,54,57,61,64,67,70,74,77,
80,84,87,91,95,98,102,106,109,113,117,120,124};


I tried to compile my program with this code inserted but it came up with an error.

It highlighted the 200 (in the line BYTE CONST SINE_WAVE[200,100]) and said 'Expecting a ]'.

Can anyone offer some help ?

PS. I am using a PIC16C74B
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Nov 29, 2004 10:11 am     Reply with quote

It should look something like this
Code:
BYTE const SINE_WAVE[200][100] = {


but you are probably going to get a script out of range error
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Nov 29, 2004 12:57 pm     Reply with quote

At least to start you might try 52 lookup tables of 64 entries each. Use a switch case to select which table to use. It will a lot easier for the compiler to deal with.
_________________
The search for better is endless. Instead simply find very good and get the job done.
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Mon Nov 29, 2004 8:10 pm     Reply with quote

I've had trouble with very large lookup tables, though I have an ancient compiler version and maybe there's a way to do it now.

What I do is write a program on the PC to generate the table in Intel hex form, then splice it into the hex file that the compiler produces, load it to the processor as usual and use read_program_eeprom() to get the data out of ROM. As a bonus, you get 14 bits for each location.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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