# temperature sensors

Printable View

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 07-04-2007
danko
Code:

```unsigned int read_adc(unsigned char adc_input){   ADMUX=adc_input|ADC_VREF_TYPE; //Set channel for input   ADCSRA=( (1<<ADEN) | (1<<ADSC) | (1<<ADIE) | (1<<ADPS1) | (1<<ADPS2) );//start conversion   while(!(ADCSRA & 0x10)); //Wait for conversion to complete   ADCSRA|=0x10;   return ADCW; }```
Salem this is something i found at the website you gave me. This is the conversion part right?
• 07-04-2007
Salem
Looks promising.
• 07-05-2007
danko
Salem > so sorry to bother you always, but I've been hearing alot of the Vref thingy. But i don't really understand what is it about.

They gave me an example.

Supposing, at a temperature of 30 deg C, it gives an output of 3V (this is just an example, check the datasheet of LM35 for exact figures). You have set a Vref+ at 5V and Vref- at 0V. Then if you do the AD conversion correctly, your ADC will read:

3 volt
-------- x 0x3FF ~= 0x265
5 volt

I'm somewhere there, but not fully.

Thanks in advance, greatly appreiciated.
• 07-05-2007
Salem
It's just simple linear interpolation
0V is read by the ADC as 0x000
5V is read by the ADC as 0x3FF

You then need another set of interpolation limits (assuming the relationship is linear), which turns say 3V into 30&#176;C
• 07-05-2007
danko
woah, hmm it's getting weird.

What i heard from my friend is Vref is generated using a potentiometer. Using that you can "substitude" it for the sensor.

How do you determine that 3V is 30 celsius?. Or do i assume a imaginary figure and work from there on?.
• 07-05-2007
Salem
> How do you determine that 3V is 30 celsius?.
I thought you knew that already, with "check the datasheet of LM35 for exact figures".

We really need a circuit diagram of some sort to visualise how all these Vref's relate to one another.

A potentiometer is good, since you can just turn it to generate varying input at the ADC, and from that generate a changing display.

For the moment, just try displaying the hex value of the ADC result on your LCD, then worry about all the conversions later.
• 07-05-2007
danko
i think i got alot of reading to do.

thanks Salem, i'll do whatever i can before i comeback here agaiin.

the code i pasted youi before, some other forummers said it was for another PIC18 controller.

thanks
• 07-10-2007
danko
I've been reading alot this few days, but suddenly something struck me.

>For the moment, just try displaying the hex value of the ADC result on your LCD, then worry about all the conversions later.
If I plugged the sensor into the ADC port, it will display the hex values on the LCD? I mean after programming.

I don't know whether the sensor is working or not lol. Cause it's like no where to show even hex values.
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12