TMP36 temperature sensor with PIC16F877A query

Status
Not open for further replies.

isaac12345

Member level 2
Joined
Mar 24, 2010
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,634
Hi all,

I'm quite new to microcontrollers and would like to ask 2 questions please-

1. What's the formula for converting the reading from the ADC into the TMP36's temperature (in degree Celsius)?I had a look on the internet and the formula that's available is for an Arduino.

2. I'm using the CCS C compiler and in the documentation its mentioned that the read_adc() function returns an 8bit integer. Is this integer the exact value of the voltage read at the analog pin or some other number which needs to be first converted into the voltage (and then further into temperature)?

Thanks!
 

Hi,

Not sure if you mean you are using the Arduino ?

Also the answer depends on what voltage you are running the chip / adc at and if you are using a 10bit or 8 bit ad converter ?

Example of at 5v chip with an 8 bit adc

5v/ 256 adc steps = 19.53 mv per step.
The TM36 outputs at 10mv per 1 degC, so that means you can only get a result of 2deg C per step on your display.

Typically 100mv ( 10c ) from the TM36 returns an adc value of decimal 05 so you would need to multiply it by 2 to give dec 10 for the display,


If you used 5V with a 10 bit adc then thats so much better

5v / 1024 adc steps = 4.88mv per steps
So 100mv ( 10c) returns the adc value of dec 20 so this time you need to divide it by 2 to give the correct dec 10 to the display. it also means you can now display the result to the nearest 0.5 c degree.


There are ways it improve the accuaracy even more but thats a little complicated for now.
 

    isaac12345

    Points: 2
    Helpful Answer Positive Rating
Thanks. I'm using 5V@8bits for the adc. Could you please advise about how I should setup the adc clock? I'm using a 4Mhz external crystal as a clock so should I set the adc to use the internal clock or some other clock?Is the code below thus fine? I'm using the CCS C compiler.

Code:
#include "16F877A.h"
#device ADC=8

void main() //********************************************
{
	int adc_value;
	int temperature;
	set_tris_a(1); //setting port A to output
	set_adc_channel(0); //channel 0 selected or pin RA0 selected for adc
	setup_adc(ADC_CLOCK_DIV_8);
	setup_adc_ports(RA0_ANALOG);
	
	adc_value=read_adc(); //read value off adc
	temperature= adc_value*2; //convert adc raw value into temperature in degree celsius
	
	if(temperature<=2 && temperature>=43) //if temperature is more than specified limits, switch off pin D0
		output_low(PIN_D0);
}
 

Hi,

Afaid I missed the obvious yesterday when your Title states the pic16F877A chip.

So if you are using that then you must be using its 10 bit ADC - yes ??
It returns the 10 bit result in two bytes ARESL and ADRESH

If you just use 8 bit at 5 volts then your reading will only be 12deg, 14deg, 16 deg etc with nothing in between - so to get a proper display in 1deg increments you must use the 10 bit adc or a voltage reference which is a little more complicated.

Afaid I cannot help with your detailed code as I only do assembler, but parameters for the adc as the same.

You can use this little utility with calculates the values for you.
You will be running off your 4meg osc and suggest you leave the source impedance as 10k.
 

can please .any body help me i have of a temperature control system using PICbasic "microcode studio " the FULL CIRCUITS is ready i need some programmer to help me .IF somebody could help please contanct me keyrouzelie@ymail.com and i will send him the circuits .thank you guys
 

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…