auto_mitch
Full Member level 3
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.
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();
};
}