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.

code in c for temperature

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,995
Dear all

the code m sending is of thermocouple linearization equation written by me in keil-c51 languague .i want to make this code size more shorter although its working .how can i do this .please help me


Code:
////////////////// Raise-To-Power /////////////////////

double rtp(float rtp_base, int rtp_power){			
	int i;
	double rtp_result;

	rtp_result = 1;
	
	for(i=1;i<=rtp_power;i++){
		rtp_result= rtp_result * rtp_base;
		}

	return(rtp_result);
}
//////////////////////////////////////////////////////



//linearization equation

y = 0 + 2.508355e1*V1 +7.860106e-2*rtp(V1,2) - 2.503131e-1*rtp(V1,3) + 8.315270e-2*rtp(V1,4) -1.228034e-2*rtp(V1,5) + 9.804036e-4*rtp(V1,6) -4.413030e-5*rtp(V1,7) +1.057734e-6*rtp(V1,8)-1.052755e-8*rtp(V1,9);
	
		lcd_init();
		lcd_com(0x01);			//Clear Display
		lcd_com(0X0C);		//Display ON, Cursor 


		
		lcd_com(0x80);
		lcd_puts("Temp= ");
	
		
		sprintf (buf, "%d", y);
		lcd_puts(buf);
thnx
 

Hello,
you can avoid the power function using a recursive computation.
Let P(x)=a4 x^4 + a3 x^3 + a2 x^2 +a1 x + a0
you can write it as :
P(x)= (((a4*x + a3) *x + a2)*x + a1)*x + a0

you can compute P(x) using a loop like this :

y =a4
for (i=3;i>0;i--)
{
y=y*x+a(i-1)
}

Added after 2 hours 38 minutes:

you can also reduce the polynomial order using my software posted in this topic :



You can then replace the order 9 polynomial with many order 3 polynomials. each
order 3 polynomial is used on a small interval.
 

    shaz

    Points: 2
    Helpful Answer Positive Rating
P(x)= (((a4*x + a3) *x + a2)*x + a1)*x + a0

yazou35 that was just amazing. that helped me to save a lot of bytes of my micro-controller.

you can compute P(x) using a loop like this :

y =a4
for (i=3;i>0;i--)
{
y=y*x+a(i-1)
}

regarding this part, in this part i'll have to use diiferent arrays for differetnt equation's coefficients. which would again increase the size of the code.

you can also reduce the polynomial order using my software posted in this topic :

h**p://

You can then replace the order 9 polynomial with many order 3 polynomials. each
order 3 polynomial is used on a small interval.

actually i'm not having MATLAB so i can't see your work.

but, i'm really greatful to you, i have clicked on "Helped me"

Thnx
 

If you are using parallel port and LM35 temperature sensor for reading temperature then see the book for parallel port.
If you are using AVR microcontroller with LM35 temperature sensor, then u see the book on AVR microcontroller programming in C using WinAVR

you can get it from yahoo group-booksbybibin
h**p://groups.yahoo.com/group/booksbybibin/
 

actually i'm not having MATLAB so i can't see your work.

I posted here my linsens software :


This a windows console program that do the same thing as the matlab code.

I hope this will help you.

Yazou
 

hi, Can anyone help me, I already done the termometer project. Now I will change my project into termostat project, that still same, using ds 1621 and ATtiny2313. Is this schematic correct? and, what would i do in programing? may I used my old source code (just a few changed), or I must rebuild with new source code. thanks.

This is my new schematic for termostat project
 

int bin2dec(char *bin)
{
P2=0xff;

int n=0;
int len, sum = 0;
for(k = 0; k <= 7; k++)
{
n = (bin[k] - '0'); // char to numeric value
if ((n > 1) || (n < 0))
{ // puts("\n\n ERROR! BINARY has only 1 and 0!\n");
return (0);
}
for(b = 1, m = 7; m > k; m--)
{ // 1 2 4 8 16 32 64 ... place-values, reversed here
b *= 2;
} // sum it up

sum = sum + n * b; //printf("%d*%d + ",n,b); // ncomment to show the way this works
}
return(sum);

}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top