PDA

View Full Version : 16f877 and LM34 Problem



tico
- 18th January 2007, 02:21
I have built the example on rentron.com

http://rentron.com/PicBasic/LM34.htm

Everything is working well except for the conversion I have vref set for 2.55 and the temp is displaying as 96 not 70 as exepcted (verified with voltmeter 0.702v)

I incresed the vref as attempt to see if that will help, with vref raised to 2.81 the conversion is as expected. I do not understand why this is not working.

My only difference from the example is I am using a 20mhz osc, and yes it is defined. I literaly cut and pasted the code from the site and changed the 4 to a 20.

Is there any way to possibly read in the voltage without a ref and do a conversion on it.

I am experimenting and looking for options.

Thanks in advance for your help and ideas.

skimask
- 18th January 2007, 02:26
I have built the example on rentron.com

http://rentron.com/PicBasic/LM34.htm

Everything is working well except for the conversion I have vref set for 2.55 and the temp is displaying as 96 not 70 as exepcted (verified with voltmeter 0.702v)

I incresed the vref as attempt to see if that will help, with vref raised to 2.81 the conversion is as expected. I do not understand why this is not working.

My only difference from the example is I am using a 20mhz osc, and yes it is defined. I literaly cut and pasted the code from the site and changed the 4 to a 20.

Is there any way to possibly read in the voltage without a ref and do a conversion on it.

I am experimenting and looking for options.

Thanks in advance for your help and ideas.

Did you try it with OSC 4?
How about seeing your actual code...maybe a typo you missed or something...

tico
- 18th January 2007, 02:30
Thanks Skimask here is the code
I tried with OSC4 and nothing happened I am assuming that is due to the use of debug and tiiming is wrong for 9600 baud.
I did not try with a 4mhz osc due to the fact that i dont have one yet.

'************************************************* ***************
'* Name : LM34.BAS *
'* Author : Bruce Reynolds *
'* Date : 10/23/2001 *
'* Version : 1.0 *
'* Notes : 8-bit A/D temperature conversion with National *
'* ; LM34CAZ analog temperature sensor. *
'* : *
'************************************************* ***************

DEFINE loader_used 1 ' Boot loader is being used
DEFINE debug_mode 0 ' Debug sending True serial data
DEFINE debug_reg portc ' Debug Port = PortC
DEFINE debug_bit 6 ' Debug.bit = PortC.6
DEFINE debug_baud 9600 ' Default baud rate = 9600
DEFINE osc 20 ' We're using a 4 MHz oscillator
DEFINE ADC_BITS 8 ' Set A/D for 8-bit operation
DEFINE ADC_CLOCK 1 ' Set A/D clock Fosc/8
DEFINE ADC_SAMPLEUS 50 ' Set A/D sampling time @ 50 uS
samples VAR WORD ' Multiple A/D sample accumulator
sample VAR BYTE ' Holds number of samples to take
temp VAR BYTE ' Temperature storage
samples = 0 ' Clear samples accumulator on power-up

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00000011 ' Set PORTA.0,1,2,5 = A/D, PortA.3 = +Vref
PAUSE 500 ' Wait .5 second

loop:
FOR sample = 1 TO 20 ' Take 20 samples
ADCIN 0, temp ' Read channel 0 into temp variable
samples = samples + temp ' Accumulate 20 samples
PAUSE 250 ' Wait approximately 1/4 seconds per loop
NEXT sample
temp = samples/20
DEBUG "Temperature is: ",DEC temp," Deg F",10,13
samples = 0 ' Clear old sample accumulator
GOTO loop ' Do it forever

END

Darrel Taylor
- 18th January 2007, 02:37
Try changing the ADC_CLOCK to 2 or 3.

FOSC/8 is too fast for 20mhz.

Datasheet says max of 5mhz OSC with FOSC/8.

FOSC/32 (ADC_CLOCK 2) should work at 20Mhz.
But, FRC (ADC_CLOCK 3) will work at any OSC.

HTH,

tico
- 18th January 2007, 02:50
That was the ticket set ADC_CLOCK 3
set vref to 2.55
lm34 .734
debug states 73 degrees

Thanks for all of your help I have been fighting with this for a bit and it was something as simple as that.