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

2D Lookup Table Smoothing

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



Joined: 31 Oct 2008
Posts: 17

View user's profile Send private message

2D Lookup Table Smoothing
PostPosted: Sat Oct 30, 2010 4:20 pm     Reply with quote

I’m wondering if any of you guys have a good suggestion on how to “linearize” the parsing of a 2D lookup table (i.e. array).

I have a program that puts out a duty cycle determined by an ADC reading and a calculated RPM value. I am doing this by using a 16x16 lookup table populated with duty values (ranging from 0 to 1023).

My program works quite well except that my algorithm resolves any in-between ADC readings to an adjacent array index making my control output too “grainy”. I think I can figure out how I would “smooth” my output in a one-dimensional array situation but not in two.

Here is the relevant code:

Code:

long motor_duty_table[16][16]; //Filled by a PC application via RS232
long vert_index_resolver[16] = {0,68,136,204,272,340,408,476,544,612,680,748,816,884,952,1020}; //Used to determine the vertical array index
long horiz_index_resolver[16] = {0,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000,11000,12000,13000,14000,15000}; //Used to determine the horizontal array index


// This Function takes a current ADC reading or the current RPM reading and returns the corresponding array index
int resolve_index(long reading, long *array)
{
 int result = 0xFF;
 i = 0;
 while((result == 0xFF) && (i<16))
 {
   if(i<15)
   {
      if((reading >= array[i]) && (reading < array[i+1])) result = i;
      else result = 0xFF;
   }
   else
   {
      if(reading >= array[i])  result = i;
      else result = 0xFF;
   }
   i++;
 }
 return result;   
}

//The function is used like this:

int i, j;

i = resolve_index(ADC_reading,vert_index_resolver);
j = resolve_index(RPM_reading,horiz_index_resolver);

set_pwm2_duty(motor_duty_table[i][j]);
newguy



Joined: 24 Jun 2004
Posts: 1906

View user's profile Send private message

PostPosted: Sat Oct 30, 2010 10:07 pm     Reply with quote

You could do three interpolations. Interpolate between the "left" two y points which are just left of your wanted x, and do the same for the two y's on the right. What you're looking for is the interpolated yleft and yright which gives you the two endpoints for your x interpolation.
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Tue Nov 02, 2010 4:14 pm     Reply with quote

Maybe it's time to shift over to an algorithm where you'd calculate an output on the basis of two inputs and a formula. Then you could load the parameters for the calculation rather than a lookup table. Granted it would involve the use of floating point calculations which we all hate, but there comes a point where that's the best way to do things.
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