PDA

View Full Version : LM35DZ + Temp



savnik
- 3rd March 2007, 11:34
I have the code below to show the temperature on LCD
The code works but i want to show on Lcd and the decimal value,
but i cann't
Like this : Temp=25.6C


' **Setting for ADC of 16F88**

Define ADC_BITS 10 ' 10-bit ADC used
Define ADC_CLOCK 3 ' Internal clock used
Define ADC_SAMPLEUS 50 ' Sample timing

Samples var word ' Samples
Sample var byte ' Sample
Vin var Word ' Vin is variable

Samples=0

ADCloop:

For Sample=1 to 10 ' Take 10 samples
ADCIN 2, Vin ' Read ADC ch-2 and save in Vin
' (range 0-1023)
Samples=Samples + Vin
Pause 200 ' Wait for LCD to startup
' Seems to be appropriate.
Next sample

Vin=Samples/10 ' Mean of 10 Vin values
Vin=(Vin*/500)>>2

Lcdout $fe, 1 ' Clear LCD
LCDOUT $FE,2
Lcdout "Temp=",Dec2 Vin,"C"

Samples=0

goto ADCLoop

skimask
- 3rd March 2007, 22:15
' **Setting for ADC of 16F88**
Define ADC_BITS 10 ' 10-bit ADC used
Define ADC_CLOCK 3 ' Internal clock used
Define ADC_SAMPLEUS 50 ' Sample timing
Samples var word:Sample var byte:Vin var Word:Samples=0
ADCloop:
For Sample=1 to 10:ADCIN 2,Vin:Samples=Samples + Vin:Pause 200 Next sample
Vin=Samples/10:Vin=(Vin*/500)>>2:Lcdout $fe, 1:LCDOUT $FE,2
Lcdout "Temp=",DEC (Vin DIG 2),DEC (Vin DIG 1),".",DEC (Vin dig 0),"C"
Samples=0:goto ADCLoop

savnik
- 4th March 2007, 18:25
' **Setting for ADC of 16F88**
Define ADC_BITS 10 ' 10-bit ADC used
Define ADC_CLOCK 3 ' Internal clock used
Define ADC_SAMPLEUS 50 ' Sample timing
Samples var word:Sample var byte:Vin var Word:Samples=0
ADCloop:
For Sample=1 to 10:ADCIN 2,Vin:Samples=Samples + Vin:Pause 200 Next sample
Vin=Samples/10:Vin=(Vin*/500)>>2:Lcdout $fe, 1:LCDOUT $FE,2
Lcdout "Temp=",DEC (Vin DIG 2),DEC (Vin DIG 1),".",DEC (Vin dig 0),"C"
Samples=0:goto ADCLoop

It's not show corect.
I try the code below and work but the decimal change every 0.5C
How change to have resolution every 0.1C


Quanta Con 1250

ADCIN 2,AD_Result ' Place the conversion of channel0 into AD_RESULT
Volts = (AD_RESULT*10) */ Quanta
Lcdout $FE,1
Lcdout "Temp : ",dec1 Volts DIG 3,DEC1 Volts DIG 2,".",DEC1 Volts DIG 1,DEC1 Volts DIG 0,"C"
' So as to display like "23.4C"

skimask
- 4th March 2007, 19:24
It's not show corect.
I try the code below and work but the decimal change every 0.5C
How change to have resolution every 0.1C


Ok, forget all the math and displaying for the moment...

What is the output on the LCD if you only read the A/D converter with the LM35DZ connected... no averaging, no multiple samples, no nothing, just one saple, one display...pause, one sample, one display, and so on...
Get a good reading that seems to make sense, then we can work on displaying it correctly...

Darrel Taylor
- 4th March 2007, 19:24
The LM35 puts out 10mv/°C.
1 "Step" of 10-bit A/D is 4.88mv.
So each "step" equals ~0.5°C

If you use a Vref of 2.5V, you could get 0.25°C resolution.

With an op-amp you might get down to 0.1°C res. if you don't need the full +150°C range.

Or you could use a DS18B20. That'll get 0.0625°C.
<br>

skimask
- 4th March 2007, 19:29
The LM35 puts out 10mv/°C.
1 "Step" of 10-bit A/D is 4.88mv.
So each "step" equals ~0.5°C

If you use a Vref of 2.5V, you could get 0.25°C resolution.

With an op-amp you might get down to 0.1°C res. if you don't need the full +150°C range.

Or you could use a DS18B20. That'll get 0.0625°C.
<br>

Good call DT! I thought the datasheet said 1mv/C.

mister_e
- 4th March 2007, 19:39
what happened in your first example?

If you used DEC3, what was the results...apart that the decimal point was missing?

Now, i have set ADCON1 register to produce Right Justified results (ADCON1.7=1) and used this


ADCloop:
For Sample=1 to 10 ' Take 10 samples
ADCIN 0, Vin ' Read ADC ch-2 and save in Vin
' (range 0-1023)
Samples=Samples + Vin
Next sample

Vin=Samples/10 ' Mean of 10 Vin values
Vin=(Vin*/500)>>2

Lcdout $fe, 1 ' Clear LCD
LCDOUT $FE,2
Lcdout "Temp=",DEC Vin DIG 2, DEC Vin DIG 1,".", DEC1 VIN,"C"

Samples=0
PAUSE 100
goto ADCLoop


it worked.

EDIT: ARGH!

savnik
- 4th March 2007, 19:42
The LM35 puts out 10mv/°C.
1 "Step" of 10-bit A/D is 4.88mv.
So each "step" equals ~0.5°C

If you use a Vref of 2.5V, you could get 0.25°C resolution.

With an op-amp you might get down to 0.1°C res. if you don't need the full +150°C range.

Or you could use a DS18B20. That'll get 0.0625°C.
<br>
Thank you for answer
I have use this schematic

savnik
- 4th March 2007, 19:50
what happened in your first example?

If you used DEC3, what was the results...apart that the decimal point was missing?

Now, i have set ADCON1 register to produce Right Justified results (ADCON1.7=1) and used this


ADCloop:
For Sample=1 to 10 ' Take 10 samples
ADCIN 0, Vin ' Read ADC ch-2 and save in Vin
' (range 0-1023)
Samples=Samples + Vin
Next sample

Vin=Samples/10 ' Mean of 10 Vin values
Vin=(Vin*/500)>>2

Lcdout $fe, 1 ' Clear LCD
LCDOUT $FE,2
Lcdout "Temp=",DEC Vin DIG 2, DEC Vin DIG 1,".", DEC1 VIN,"C"

Samples=0
PAUSE 100
goto ADCLoop


it worked.

EDIT: ARGH!
The LCD show Temp=02.5C
but the right is Temp=25C

savnik
- 4th March 2007, 19:57
Ok, forget all the math and displaying for the moment...

What is the output on the LCD if you only read the A/D converter with the LM35DZ connected... no averaging, no multiple samples, no nothing, just one saple, one display...pause, one sample, one display, and so on...
Get a good reading that seems to make sense, then we can work on displaying it correctly...

The output on the LCD is 44-46 (Vin = 44~46)
The temperature is about 22C in room

savnik
- 4th March 2007, 19:59
I change to :


ADCloop:

ADCIN 2,Vin
Pause 200
Vin=(Vin* 10)/2
Lcdout $fe, 1
LCDOUT $FE,2
Lcdout "Temp=",DEC (Vin DIG 2),DEC (Vin DIG 1),".",DEC (Vin dig 0),"C"
goto ADCLoop

and believe is right
The LCD now show : Temp=22.5C

savnik
- 4th March 2007, 20:02
The LM35 puts out 10mv/°C.
1 "Step" of 10-bit A/D is 4.88mv.
So each "step" equals ~0.5°C

If you use a Vref of 2.5V, you could get 0.25°C resolution.

With an op-amp you might get down to 0.1°C res. if you don't need the full +150°C range.

Or you could use a DS18B20. That'll get 0.0625°C.
<br>
I want to measure from 0 - 100C

skimask
- 4th March 2007, 21:35
I want to measure from 0 - 100C

So what's the problem? The answer has already been given to you twice in the posts above, even if other parts of the code were wrong, if you'd take a few seconds to look over the display part of the above code, you'd find your answer, between that and the PBP manual, which does describe what you need...

savnik
- 5th March 2007, 07:05
I want to measure from 0 - 100C
I answer , don't ask