Temp sensor problem


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425

    Default Temp sensor problem

    OK, I certainly don't understand what's going on. I am using a LM34CZ (if someone has a more precise temp sensor please let me know) and I am simply trying to read the voltage from it. It wasn't working correctly so I put a potentiometer on the analog port instead of it and that doesn't work either.

    Below is the code.......someone please tell me what I am doing wrong. This code was actually taken from Bruce at Rentron.com. It is erratic but also the difference is +13 volts at some points. I have 2.55 on porta.3 and the input from the pot is on porta.1. I am using a 16F876.



    DEFINE osc 20 ' We're using a 20 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 1, 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

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Minimum Tad is 1.6uS.

    If you're using a 20MHz osc, then you'll want to change the A/D conversion
    clock setting. Change DEFINE ADC_CLOCK 1 to DEFINE ADC_CLOCK 2.

    My example uses a 4MHz osc, so DEFINE ADC_CLOCK 1 works. This selects
    8Tosc which is fine up to 5MHz. 8/5MHz = 1.6uS which is right at the cut
    off point of 1.6uS min Tad.

    Above 5MHz you want 32Tosc. Anything below this, and your A/D clock is
    too fast. For example: 8/20MHz = 400nS = 4 times too fast for min Tad.

    Also make sure you're never applying > Vref to any A/D input. If you have
    +Vref set to 2.55V, you should never exceed 2.55V input on any A/D pin.
    Last edited by Bruce; - 14th June 2006 at 04:38.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply. It is a lot better but I measure the voltage into porta.3 as .67 but the display says .72. I have checked it up and down and it's linear but the PIC isn't displaying the correct voltage. Is there any better method to measuring an analog voltage? I was thinking of using an ADC0831 but I wanted to stay away from adding more chips. Maybe a current loop temp senor? In my project, I wanted to have data like 72.3, 72.4 instead of just 72 or 73. Are there any sensors that will display three digits to have better clarity?

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Graphic LCD with PICbasic pro
    By amindzo in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th November 2012, 11:45
  2. Stuck with 85C temp on ds18b20
    By revelator in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 3rd April 2009, 19:50
  3. Random Numbers
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 18th December 2008, 08:47
  4. help with write command
    By cphillips82 in forum General
    Replies: 9
    Last Post: - 20th April 2008, 23:49
  5. Need help with LCD number display.
    By Steve Matson in forum mel PIC BASIC
    Replies: 8
    Last Post: - 26th June 2007, 23:07

Members who have read this thread : 1

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