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.

[SOLVED] Problem with LM35 negative temperature reading

Status
Not open for further replies.

Praveen Kumar P S

Member level 4
Joined
Aug 21, 2014
Messages
79
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Location
India
Activity points
627
Hello friends...

This program is for reading the Temperature and display it on a lcd display at the same time the pic serially transmit the temperature.....My program works.....:roll::roll:..But it is not displaying any negative temperature....:bang::bang::bang:

plzz help guys...............

Here is my code:::

Code:
#include <18f4550.h>
#device ADC=10
#fuses HS,NOWDT,NOPUT,NOPROTECT,NODEBUG,BROWNOUT,NOLVP,NOCPD,NOWRT 
#use delay(crystal=48000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include<flex_lcd416.c>
void main() 
{ 
unsigned int8 t;
lcd_init();
lcd_gotoxy(4,1);
lcd_putc("Temperature\n");
setup_port_a(ALL_ANALOG);
setup_adc( ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0);
for(;;)
{
set_adc_channel(0);
delay_ms(10);
t = read_adc()/2;
lcd_gotoxy(6,3);
printf("Temp::\t%3.0u \xDFC\n\r",(unsigned int8)t);
printf(lcd_putc,"%3.0u \xDFC ",(unsigned int8)t); 
delay_ms(10);

}
}
 

Hi,

Is your adc able to decode negative voltage?

If yes, did you negative bias with resistor your lm35 output?

Klaus
 
your variables are unsigned, e.g.
Code:
unsigned int8 t;
and the printf() conversion specifications etc are for unsigned types
if you expect negative values should you be using signed types?
 
Hi,

Is your adc able to decode negative voltage?

If yes, did you negative bias with resistor your lm35 output?

Klaus

I connect output of lm35 directly to AN0 pin of the pic.....i didnt have a -ve bias with resistor.....
why is the resistor for.....??
thank you....

plzz help
 

i changed my program but still no effect...........
here is my new code..

Code:
#include <18f4550.h>
#device ADC=10
#fuses HS,NOWDT,NOPUT,NOPROTECT,NODEBUG,BROWNOUT,NOLVP,NOCPD,NOWRT 
#use delay(crystal=48000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include<flex_lcd416.c>
void main() 
{ 
signed int8 t;
lcd_init();
lcd_gotoxy(4,1);
lcd_putc("Temperature\n");
setup_port_a(ALL_ANALOG);
setup_adc( ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0);
for(;;)
{
set_adc_channel(0);
delay_ms(10);
t = read_adc()/2;
lcd_gotoxy(7,3);
printf("Temp::\t%3.0d \xDFC\n\r",(signed int8)t);
printf(lcd_putc,"%3.0d \xDFC ",(signed int8)t); 
delay_ms(10);

}
}

guys...any hing wrong with my code...plz help
thank u....
 

hello,


What is the specsheet of your LM35
is it a LM35DZ or a LM335
LM335 can measure negative temperature, LM35DZ can NOT ...


if you can use 4.096V as +VREF and use -VREF with a resistor divider by 2 sor -VREF=2,048V
you can have a scale of 2048mV for 1024 points
and measure from -68.2°C up to 136.6°C with a resolution of 0.2°C
see table..

problem:
signed int8 ?
an int is 16 bits..
why not simply use
Code:
int t;    // must be an int signed
because read_adc must be an integer ( with only 10 bits used inside the result)

%3.0 decimal, is reserved for floating point
you must write %3d


Code:
printf("Temp::\t%3d \xDFC\n\r",t);

why divide Adc result by 2 ?
you measure is a raw measure in points, you need to convert it in °C or °F
see correspondance table for a LM335 ..
Positive is upper 2730mV = 0°Kelvin


LM335.jpg
 
[Merged]CanT read data from sensors....!!!

Hello guys....
i dont why my program is not working.....It read values from the sensors...but not showing any correct temperature and my humidity sensor output always zero.....
here is my code....:::

Code:
#include <18f4550.h>
#device ADC=10
#fuses HS,NOWDT,NOPUT,NOPROTECT,NODEBUG,NOLVP,NOCPD,NOWRT,NOMCLR,INTRC_IO,NOPBADEN,BROWNOUT,PUT
#use delay(crystal=48000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,ERRORS)
#include<flex_lcd416.c>

void main()
{
unsigned int8 t0,t1,T;
unsigned int8 h;
lcd_init();
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(ALL_ANALOG);
set_adc_channel(0);
delay_ms(10);
t0=read_adc()/2;
delay_ms(10);
set_adc_channel(1);
delay_ms(10);
t1 = read_adc()/2;
delay_ms(10);
T=t0-t1;
lcd_gotoxy(1,2);
printf(lcd_putc,"Temp::\t%3.0d \xDFC ",(signed int8)T);
printf("Temp::\t%3.0d \xDFC\r",(signed int8)T);

set_adc_channel(2);
delay_ms(10);
h=read_adc()/2;
delay_ms(10);
lcd_gotoxy(1,1);
printf(lcd_putc,"Humidity::%3.0u",(unsigned int8)h);
output_high(PIN_B3);


}

plzz help me........:bang::bang::bang::bang::bang::bang:
 

Re: [Merged]CanT read data from sensors....!!!

Here I am attaching LM35 firmware and Proteus simulation. If you need more precise measurement then I will use Vref+ and make it. :thumbsup:
 

Attachments

  • LM35 Negative Temperature Measurement.rar
    19 KB · Views: 113
  • LM35 Negative Temperature Measurement rev1.rar
    18.9 KB · Views: 115
Last edited:
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top