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.

ADC problem with lm35 sensor

Status
Not open for further replies.

auto_mitch

Full Member level 3
Joined
Oct 14, 2004
Messages
172
Helped
16
Reputation
32
Reaction score
3
Trophy points
1,298
Activity points
1,240
temperatura lm35 celcius formula *5/255

Hi!
this is my first project using the ADC of my mega8535.
i want to measure the temperature through lm35 and display it on the lcd. i have connected the AREF=4.7V
Vcc=4.7V,AVcc=4.7V. My analogue channel is ADC3(PA3). The LM35 is connected to 4.7V and the signal pin is directly connected to ADC3. As i have seen in datasheet with this connection i can measure 2-150 Celcius degrees, and for each degree you measure 10mv. From these information i have calculated the function that converts voltage to temperature (Temp=0.1*Voltage+2).
This is my code in codevision. My problem is that i cannot measure normal temperature and my highest temp that i can measure is 30.82C. Could you please help me what am doing wrong.
thanx.


Code:
#include <mega8535.h>
#asm                                     
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
#include <delay.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include<stdio.h>

float current_temp;
float voltage;
char lcdbuffer[16];

//ADC interrupt service routine
interrupt [ADC_INT] void adc_isr(void)
{
    unsigned int ADC_DATA;
    ADC_DATA=ADCW; // get data from ADC
    voltage=((float)4680*(float)ADC_DATA)/(float)1023;
    ADCSRA=ADCSRA|0x40;            
}

void temp()
{   
    current_temp=0.1*voltage+2.0;
    ftoa(current_temp,2,lcdbuffer);
    lcd_gotoxy(8,0);
    lcd_puts(lcdbuffer);
}

void main(void)
{
lcd_init(16);         // LCD Initialization.                       
ADMUX=0x3;
ADCSRA=0xE9;
lcd_gotoxy(0,0);
lcd_putsf("Temp:");
while (1)
      {
      #asm ("sei")

      temp();
      };
}
 

I think you should maybe put an amplifier to the LM35 before sending to ADC. The voltage would now be higher than the expected 10mv temperature, so you will also be required to change your temperature scaling formula.
 

from my exp...

ref vge should be always less the supply vge...
i would recomend u to connet Vcc to 5V... and Vref to4.7...

Then only u can get the full scale reading.....

otherwise the 4.7volts equivivalent value will be the maximum ADC can measure...

put a 100pf cap on the adc line...
or for more accuracy use a OPAMP vge follower between the ADC & pIC....

pls donot forget to pres helpme

Code:
//ADC interrupt service routine 
interrupt [ADC_INT] void adc_isr(void) 
{ 
    unsigned int ADC_DATA; 
    ADC_DATA=ADCW; // get data from ADC 
    voltage=((float)4680*(float)ADC_DATA)/(float)1023; 
    ADCSRA=ADCSRA|0x40;     
[b]    ADC_read = 1;   [/b]    
} 

void temp() 
{    
    current_temp=0.1*voltage+2.0; 
    ftoa(current_temp,2,lcdbuffer); 
    lcd_gotoxy(8,0); 
    lcd_puts(lcdbuffer); 
[b]   ADC_read = 0;      [/b] 
} 

void main(void) 
{ 
lcd_init(16);         // LCD Initialization.                        
ADMUX=0x3; 
ADCSRA=0xE9; 
lcd_gotoxy(0,0); 
lcd_putsf("Temp:"); 
while (1) 
      { 
      #asm ("sei") 
   [b]  if (ADC_read == 0)
      temp(); [/b]
      }; 
}
 

    auto_mitch

    Points: 2
    Helpful Answer Positive Rating
Hi,
You just go through the full scall analog in and find out the resolution of an ADC with reference.
You adjust sensor out either POT or Amplifier.
Eg:
Full scale analog in is 5 Volts
Dout is 8 bits ( 255 decimal)
So,The resolution is == 5/255 -1
= 19.86 millivolts

Solution:
Sesonr output is 10mv/ c
so use amplifier to get approx 20mv/c

This is called signal conditioner
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top