Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

solving polynomial in mcu

Status
Not open for further replies.

shaz

Member level 4
Joined
Mar 9, 2005
Messages
70
Helped
10
Reputation
20
Reaction score
6
Trophy points
1,288
Activity points
1,994
hi, for thermocouple linearization i learned i need to use polynomials which can give me correct results, for example, in case of R-TYPE thermocouple for temperature lying between 250-1200 Celcius,

Temp.= 1.334584505E+01 + 1.472644573E+02 x V + -1.844024844E+01 x V^2 + 4.031129726E+00 x V^3 + -6.249428360E-01 x V^4 + 6.468412046E-02 x V^5 + -4.458750426E-03 x V^6 + 1.994710149E-04 x V^7 + -5.313401790E-06 x V^8 + 6.481976217E-08 x V^9 + 0.000000000E+00 x V^10

where V is thermocouple EMF voltage in mV

lets say voltage read is V=6.157mV, then temperature is, (using above equation)

Temp.= 1.334584505E+01 + 1.472644573E+02 x 6.157 + -1.844024844E+01 x 6.157^2 + 4.031129726E+00 x 6.157^3 + -6.249428360E-01 x 6.157^4 + 6.468412046E-02 x 6.157^5 + -4.458750426E-03 x 6.157^6 + 1.994710149E-04 x 6.157^7 + -5.313401790E-06 x 6.157^8 + 6.481976217E-08 x 6.157^9 + 0.000000000E+00 x 6.157^10

=> Temp = 649.9 'Celcius ~ 650 'Celcius

(for refrence i'm attaching R-type thermocouple output chart, linearization coefficents are also given in it, at bottom)

friends please advise me how can i solve this polynomial in C programming of micro-controller because using assembly it seems to be something like impossible. I can use Hi-tech C (if i plan to use PIC micro-controller PIC16F877) or Keil C51 (if i plan to use 8051 core micro-controller, like 89c52), which one do u advise.

i'll honour any help, any suggestion you advise.

thanks
 

future

Newbie level 6
Joined
Dec 20, 2004
Messages
13
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
109
Re: solviing polynomial in mcu

Pre-compute a table for all possible ADC readings you have, for example:

8bit ADC will give a 256byte table.
 

shaz

Member level 4
Joined
Mar 9, 2005
Messages
70
Helped
10
Reputation
20
Reaction score
6
Trophy points
1,288
Activity points
1,994
future thanks, but that wont help cause i'm using different types of thermocouples and R-type (which i discribed above itself goes upto 1768 degree celcilus which can only be handled by a 12-bit adc, (consediring resoultion=1) so feeding so many values i don't think so it's possible.
 

BabyTiger

Full Member level 2
Joined
Aug 8, 2005
Messages
123
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,298
Activity points
2,126
Please see Application note from MicroConverter from Analog Device. They have source code and document in MCS-51.
 

shaz

Member level 4
Joined
Mar 9, 2005
Messages
70
Helped
10
Reputation
20
Reaction score
6
Trophy points
1,288
Activity points
1,994
BabyTiger can u please provide the link
 

artem

Advanced Member level 4
Joined
May 22, 2003
Messages
1,347
Helped
126
Reputation
252
Reaction score
32
Trophy points
1,328
Location
Turkey
Activity points
13,450
Search google for :
numerical method to solve polynom
 

ravimarcus

Full Member level 4
Joined
May 9, 2005
Messages
218
Helped
31
Reputation
62
Reaction score
12
Trophy points
1,298
Location
Bangalore, INDIA
Activity points
2,797
shaz said:
future thanks, but that wont help cause i'm using different types of thermocouples and R-type (which i discribed above itself goes upto 1768 degree celcilus which can only be handled by a 12-bit adc, (consediring resoultion=1) so feeding so many values i don't think so it's possible.

Shaz - Use double table for lookup. Use the lower ADC value on one table and upper ADC value on another. Merge the result data and you have a linearised 12/16 bits value. It works :)

Off course, you will need a large amount of memory to store all the values. Either use the internal program memory to store or use a SEEPROM to store the values.

Cheers

Ravi

Added after 4 hours 11 minutes:

Here is a double lookup table method to linearise or convert 12/16 bits to another set of 12/16 bits.

Cheers

Ravi
 

artem

Advanced Member level 4
Joined
May 22, 2003
Messages
1,347
Helped
126
Reputation
252
Reaction score
32
Trophy points
1,328
Location
Turkey
Activity points
13,450
shaz, i appologise for mistake in my previous post . If you know the polynom, you can write a simple C code to implement .
Use double types when coding formula calculation.
Do these compilers for mentioned micros support double ? Could you check that ? If not - try float, and test got values against double types as :

Just use conventional compiler for PC and write polynom formula with double and float , then test difference for each input-output pair values and note maximum difference. If it is acceptable - go ahead with float.
 

alzomor

Advanced Member level 2
Joined
Jun 9, 2005
Messages
674
Helped
39
Reputation
78
Reaction score
8
Trophy points
1,298
Location
Germany
Activity points
6,406
Hi

You can check on the net for Cordic.
Cordic is a method to implement complex math with just Add and shift.


It may help

Salam
Hossam Alzomor
www.i-g.org
 

rauol

Full Member level 6
Joined
Oct 2, 2002
Messages
325
Helped
16
Reputation
32
Reaction score
4
Trophy points
1,298
Location
India
Activity points
2,647
will a 8 Bit MCU be sufficiant for this kind of Math or you require a 16 Bit version.
 

creative_35

Full Member level 1
Joined
Apr 10, 2006
Messages
95
Helped
9
Reputation
18
Reaction score
3
Trophy points
1,288
Location
Under Mango Tree
Activity points
2,031
rauol said:
will a 8 Bit MCU be sufficiant for this kind of Math or you require a 16 Bit version.
with fingers we can count up to 10 and for counting 20 what we will do? count once again or borrow some one's fingers?
 

yazou35

Junior Member level 1
Joined
Apr 23, 2006
Messages
18
Helped
6
Reputation
12
Reaction score
1
Trophy points
1,283
Activity points
1,533
Hello,
you can simplify the problem by making a linearization of your high order polynomials by using lower order polynomials on smaller intervalls.

I send here a matlab program linc5 that make linearization of sensor data into polynomials. You can input the polynoimial order and the max accepted approximation error. There are two examples file, tc_b.dat for a thermocouple type B and pt46.dat for a platinum 46 ohm sensor.

I hope this will help you.
 

nebisman

Full Member level 4
Joined
Apr 13, 2002
Messages
226
Helped
10
Reputation
22
Reaction score
9
Trophy points
1,298
Activity points
1,849
There are some direct functions in hitech C compiler. As far as I remember they are hardly optimized and I thik that their computtion time isn't so long


Look at this,...
 

sky123

Junior Member level 2
Joined
Feb 12, 2003
Messages
21
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,283
Activity points
171
To be honest, pre-computing is the way to go, otherwise you have include a maths library to handle these floating point numbers. a 1Mbit serial flash only costs a dollar or two, and can store a whole range of pre-computed tables, and will only use a couple of I/O pins from your microcontroller. Then you can dynamically select the one closest to your needs.

Another way is to try and scale your numbers, so that you can perform integer arithmetic - not always possible, depending on the complexity of the calculations.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top