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 CCS Technical Support

table results

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



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

table results
PostPosted: Tue Feb 23, 2010 3:35 pm     Reply with quote

Hello!

I am using a KTY84 temperature sensor to make a thermometer.
This changes its resistance according to the temperature.

I have some given values from the datasheet for 0,10,20,25,30.....290,300 degrees celcius in 10 degrees steps except for the 25 degrees that I have a given value also.

So, I did this:
ADC reading---temperature to display
Code:

   if   (value==339) return(0);
   else if   (value==357) return(10);
   else if   (value==375) return(20);
   else if   (value==384) return(25);
   else if   (value==393) return(30);
   else if   (value==411) return(40);
   else if   (value==429) return(50);
   else if   (value==445) return(60);
   else if   (value==462) return(70);
   else if   (value==478) return(80);
   else if   (value==495) return(90);
   else if   (value==511) return(100);
   else if   (value==526) return(110);
   else if   (value==540) return(120);
   else if   (value==556) return(130);
   else if   (value==571) return(140);
   else if   (value==584) return(150);
   else if   (value==598) return(160);
   else if   (value==609) return(170);
   else if   (value==623) return(180);
   else if   (value==635) return(190);
   else if   (value==647) return(200);
   else if   (value==658) return(210);
   else if   (value==667) return(220);
   else if   (value==680) return(230);
   else if   (value==687) return(240);
   else if   (value==698) return(250);
   else if   (value==708) return(260);
   else if   (value==716) return(270);
   else if   (value==726) return(280);
   else if   (value==734) return(290);
   else if   (value==740) return(300);

Of course this is very simple and it works but how can I calculate the values between these? I want to have a result for every single degree not for every ten degrees... Confused

Thanks.
jaimechacoff



Joined: 14 Feb 2010
Posts: 24
Location: Santiago, Chile

View user's profile Send private message

PostPosted: Tue Feb 23, 2010 3:48 pm     Reply with quote

you can convert all those points in a polynomial function.

I use to use Cubic Spline, that means that you will find a function and it will cross each one of the point of your table, and of course, between each point as well.

read about:

http://en.wikipedia.org/wiki/Spline_interpolation

its pretty much easy.

good luck.
jaimechacoff



Joined: 14 Feb 2010
Posts: 24
Location: Santiago, Chile

View user's profile Send private message

PostPosted: Tue Feb 23, 2010 3:52 pm     Reply with quote

ok, I did it very faster and i believe is an exponential function, of course, with the Spline you will find a polynomial, and insted of all those "else if" you put the function : )))))))))))

Last edited by jaimechacoff on Tue Feb 23, 2010 3:54 pm; edited 1 time in total
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Tue Feb 23, 2010 3:53 pm     Reply with quote

Thanks but I think that this it way too "math" for me.

I will study this anyway.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 23, 2010 3:54 pm     Reply with quote

It would be far better to do it with an equation. But if you don't want to
do that (or you can't), then you can use the "brute force" method of one
big look-up table. Example:
Code:

#include <16F877.H>
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)


const int16 temp_table[] =
{
0,   // 339  // Lowest input temperature
1,   // 340
2,   // 341
2,   // 342
3,   // 343
3,   // 344
4,   // 345
4,   // 346
5,   // 347
5,   // 348
6,   // 349
6,   // 350
7,   // 351
7,   // 352
8,   // 353
8,   // 354
9,   // 355
9,   // 356
10,  // 357

// Add more table entries, from 358 up to 740.

};


int16 adjust_temp(int16 temperature)
{
int16 retval;

// Force temperature to be within limits of lookup table.
if(temperature < 339)
   temperature = 339;

if(temperature > 740)
   temperature = 740;

// Remove offset
temperature -= 339;

// Get adjusted value from table.
retval = temp_table[temperature];

return(retval);
}


//-------------------------
// Substitute your actual sensor driver code
// for this routine.

int16 get_temp(void)
{



return(348);
}



//======================================
void main()
{
int16 raw_temperature;
int16 final_temperature;

while(1)
  {
   raw_temperature = get_temp();  // Read the sensor

   final_temperature = adjust_temp(raw_temperature);

   printf("Temperature = %lu \n\r", final_temperature);
  }

}

jaimechacoff



Joined: 14 Feb 2010
Posts: 24
Location: Santiago, Chile

View user's profile Send private message

PostPosted: Tue Feb 23, 2010 3:57 pm     Reply with quote

PCM already did your work ; )))

but really, try fitting a equation, even you can do it with excel : )
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Tue Feb 23, 2010 3:58 pm     Reply with quote

Thanks PCM programmer.

I want to avoid this method of a huge table with 300 values.
I prefer to use a function which takes the 2 values and gives me the values between them.
jaimechacoff



Joined: 14 Feb 2010
Posts: 24
Location: Santiago, Chile

View user's profile Send private message

PostPosted: Tue Feb 23, 2010 4:02 pm     Reply with quote

I got this equation:

Code:

Return = 0.0008value**2 - 0.1224value - 42.736



Its not actually correct but fits the point you gave us in the original post, now its up to you do it better ; )
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Tue Feb 23, 2010 4:09 pm     Reply with quote

I am not sure of how to use this. I am sorry. Sad
As for the table option the PIC16F877A can not hold 300 values in ram.
jaimechacoff



Joined: 14 Feb 2010
Posts: 24
Location: Santiago, Chile

View user's profile Send private message

PostPosted: Tue Feb 23, 2010 4:17 pm     Reply with quote

first that all, you should do a kind of simulation, Excel can help you a lot.

Make a graph of the equation, test if all your point are in the curve, or at least close (your know which is your better accuracy), then you will know what you will have and just then you will be able to programm it ... just be careful ; )
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Tue Feb 23, 2010 11:23 pm     Reply with quote

You can't get 300 values in RAM, but you can in ROM.
mutthunaveen



Joined: 08 Apr 2009
Posts: 100
Location: Chennai, India

View user's profile Send private message

interpolation method is very useful for u
PostPosted: Wed Feb 24, 2010 5:13 am     Reply with quote

first of all

use MSEXCEL and plot the graph with your tabel values

then, graph will be displayed. split the graph by 4 or 5 parts, according to the slopes.

extract the X and Y cordinates of 5 parts

apply them in the interpolation formula. derieve the formula and load into ur chip.....

this will do all the work....................... Cool


--------------
hard work makes all
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Wed Feb 24, 2010 8:49 am     Reply with quote

Thank you all for the support.

I do not know how to do this in excel so I have to follow PCM programmer's idea to write all 300 values manually. Crying or Very sad

Thanks!
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