16f877 and LM34 Problem


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Dec 2006
    Posts
    38

    Default 16f877 and LM34 Problem

    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.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tico View Post
    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...

  3. #3
    Join Date
    Dec 2006
    Posts
    38


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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,
    DT

  5. #5
    Join Date
    Dec 2006
    Posts
    38


    Did you find this post helpful? Yes | No

    Talking

    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.

Similar Threads

  1. Temp project using LM34
    By Philley in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st May 2007, 22:51

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts