Problem in display correct values of the temperature sensor

Status
Not open for further replies.

caramelz

Junior Member level 2
Joined
Jul 19, 2012
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,464
hi I'm using Pic18f4520, the temperature sensor doesnt give the correct values. the values isnt consistent at all too.

Temperature sensor is connect to AN12 of the IC
I display the ADC reading into the LCD, the values kept jumping from 50 , 70, 100 back to 50.
Can anyone tell me whats wrong with it. thanks
 

I'm using a LM35 sensor.

Code:
ADCON2=0b10001010;

void temperature(void)
{
	unsigned int temp;
	char degree[4]="   ";
	unsigned int me;
	temp=ADCRead(12);
	me=temp;
	Init_LCD();
	itoa(me,degree);						
		i=0;  
		W_ctr_8bit(0x80);		
		while (degree[i]){              	
			W_data_8bit(degree[i]); 	
			i++;
		}              		
	
}
unsigned int ADCRead(unsigned int ch)
{
	if(ch>13)return 0; 	
	ADCON0=0x00;
	ADCON0=(ch<<2);
	ADCON0bits.ADON=1;
	Delay10TCYx(5);	
	ADCON0bits.GO = 1;	
	while(ADCON0bits.DONE);	
	ADCON0bits.ADON=0;
	return (ADRESH*256+ADRESL);
}
 

Where is ADCON1 settings?

TRISBbits.TRISB0 = 1;
ADCON1 = 0b00000001;
//or
ADCON1 = 0b00000010;
//or
ADCON1 = 0b00000000;


Mention Fosc used so that ADCON2 value can be calculated. Put Init_LCD(); in main() before while(1) loop.
 
Last edited:

I'm using 20Mhz crystal
ADCON0=0b00000001;
ADCON1=0b00000111;
ADCON2=0b10001010;
the sensor is connected in RB0 CH12.
Sensor Connection: 5V, GND, RB0.
 
Last edited:

I just changed the sensor to CH8(RB2) as to minimize the port usage cos i have 8 other ADC CH for measuring the batteries.
yeah I had set the trisB to Input for RB2
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…