Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LM35 Testing

Status
Not open for further replies.
Hello,

C:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
unsigned char digits[] = {  0b00010000,0b01111101,0b00100010,0b00101000,0b01001101,0b10001000,

0b10000000, 0b00111101,0X00,0b00001000};

void main(){
TRISD=0X00;   
TRISB=0X00;
PORTB=0X00;
TRISA = 0xff ;
ADCON1=0b00000000;
ADCON0=0b10000001;//000 = channel 0, (RA0/AN0)
ADIF=0;
    ADIE=1;
    PEIE=1;
while(1){
    __delay_us(10);
GO_DONE=1;
    __delay_us(10);

unsigned int x=0;
unsigned char y=0;
unsigned char z=0;
y=0b10110111;
z=0b11000000;
ADRESH=y;
ADRESL=z;


//x = (unsigned int) ADRESH << 8  + ADRESL;  //Right!
x = (( unsigned int) ADRESH << 2) + (ADRESL >>6); // Left!
x=(ADRESH*500)/1024;
PORTD = 8;
x=x%10;
PORTB=digits[x];
__delay_ms(5);
PORTB=0X00;
x=ADRESH;
PORTD = 4;
x=(x/10)%10;
PORTB=digits[x];
__delay_ms(5);
PORTB=0X00;
x=ADRESH;
PORTD = 2;
x=x/100;
PORTB=digits[x];
__delay_ms(5);
PORTB=0X00;
x=ADRESL;
x=x%10;
PORTD = 1;
PORTB=digits[ADRESL];    // just for test on display working or not
__delay_ms(5);
PORTB=0X00;
       
    }
}
 
x=(ADRESH*500)/1024;

You need to cast here!!!! ADRESH is a byte int... so multiplying by 500 won't do any good..
C:
long ADCresult;

ADCresult = ( unsigned int) ADRESH << 2) + (ADRESL >>6);

ADCresult *= 500;
ADCresult /=1024;
PORTD = 4;
PORTB = digits[ADCresult /100];
PORTD = 2;
PORTB = (digits[ADCresult % 100 /10] ) +DP; //  the decimal place
PORTD = 1;
PORTB = digits[ADCresult % 10];
 
Hello,
unsigned int from where this come?
and what is the need of 500 here?
logic behind it?
It is called a cast!! ADRESH is a byte.... 0~255... Multiplying this with 500 wont do yo much good!

Assume 255.. 255 is the largest number that ADRESH will hold 255 << 2 = 1020.. So when you cast ADRESH to an int the 1020 will fit!
 
Hello,
The lm35 again has damage i think it is getting very hot with 6V.
the output is directly connected to ADC.
 
Hello,
Now it is 7805 with Capacitor of 22 uF on both side.
Please tell how to solve the problem of lm35 it is getting hot and after this the ADC at 0v giving 000 and 5v it i s 484 irregular number..
 
Hello,
Now it is 7805 with Capacitor of 22 uF on both side.
Please tell how to solve the problem of lm35 it is getting hot and after this the ADC at 0v giving 000 and 5v it i s 484 irregular number..

What do you mean... 0v = 0 and 5v = 484..... where is the 5v coming from??? The LM35 should only EVER produce 1.5v
 
OK, i have seen there was fault in 7805 regulator i have changed it!
Rated for Full −55°C to 150°C Range it is gone to 157*C i have kept soldering iron on it!
placing ice only take 9*C

what this mean
Suitable for Remote Applications
Low-Cost Due to Wafer-Level Trimming
Low Self-Heating, 0.08°C in Still Air
Non-Linearity Only ±¼°C Typical
Low-Impedance Output, 0.1 Ω for 1-mA Load
 
You can test tranx, capacitors, coils even IC with a meter. So what it will not tell you if it is good or how good it is and if it is bad will not tell you how bad it is. It is an indicator that is all.
 

ADCresult *=500;
ADCresult /=1024;



The ADC is 10 bit result ok
then we multiply it by 500 and divide by 1024, what this mean?
logic behind it?
 
ADCresult *=500;
ADCresult /=1024;



The ADC is 10 bit result ok
then we multiply it by 500 and divide by 1024, what this mean?
logic behind it?

Did you do math at school???

If you want to measure 0 ~ 5v.... With a 10 bit ADC... 0 = 0 and 5 = 1023 Okay!

if you want 2 decimal precision then you a) use floating point unit
result = ADCresult *5.0v / 1024... this will give you 0.00 ~ 5.00v​
or b) you use fixed math.
result = ADCresult * 100 * 5 / 1024.. this will give you 0 ~ 500v so you can insert your own decimal place...​

I have only just combined the 5 and the 100
result = ADCresult * 500 / 1024.. this will also give you 0 ~ 500v so you can insert your own decimal place...​
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top