LM35 Temp and Pseudocode help wanted


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2008
    Location
    Spokane, WA
    Posts
    9

    Default LM35 Temp and Pseudocode help wanted

    I can blink a few leds, now I would like to try to turn on an led when my LM35 temp sensor reaches about 80 degrees F (27C), eventually running it out serially to a display.
    I have a few questions about digitizing the analog signal. I am in the process of setting up the AN registers. I was going to use the internal Vref but not sure how to do it. Datasheet gives option (p43) for vdd or Vref pin. It is shown disconnected on my schematic. How do I scale this? The LM gives 10mv/degreeC (21 = 210mV = 69.8F about ROOM TEMP) Is there another way to calibrate it? Do I need to put a reference voltage on this pin?? I am including what I have so far- far from complete - just getting things configured. I am having a hard time writing the pseudocode especially with the above info missing. I guess what I want to do is:
    set up an
    set up digital output
    read an input
    compare it to vref
    if vref register<AN input, scan again
    if vref register>AN input, change states of GPIO2
    maintain this state while scanning again

    http://ww1.microchip.com/downloads/e...doc/41190c.pdf

    Code:
    SYMBOL ANSEL = $9F                        'SET TO AI, NOT DI
                                              'SET OSC - p44 DATASHEET
                                              
    SYMBOL ADCON0 = $1F                       'SET PIN0 TO ANALOG IN  p43
                                              'TURN ON AD
                                              'START AD
                                              'SET CHAN AN0      
                                              'VREF PIN       ???????????????  
                                              'LH JUSTIFIED                  
    SYMBOL CMCON = $19                        '001 ON/OFF COMPARE MODULE. BIT6 IS STATUS CHANGE FLAG P37
    symbol VRCON = $99                        'INTERNAL VREF CTRL REGISTER
    '===============================================================================
    POKE ANSEL,%00011111                      'SEE ABOVE
    POKE ADCON0,%01100011                     'SEE ABOVE                                       
    POKE CMCON,%01000001                      'COMPARITOR CONTROL CONFIG  
    POKE VRCON,%01000111                      'SET LOW RANGE
                                              'CVREF ENABLE ????????????????
    '===============================================================================
    SYMBOL TRISA = $85                        'IO ADDRESS DIRECTION
    POKE TRISA,%00000011                      'SET PIN0 AS INPUT – TEMP SENSOR
                                              'SET PIN1 AS INPUT – VREF
                                              'SET PIN2 AS OUTPUT   
    SYMBOL GPIO = $05                         '                                      
    SYMBOL TEMPSENS_IN = B1                   'BYTE VAR TO STORE ANALOG DATA
    SYMBOL VREF        = B2                   'BYTE VAR TO STORE REF DATA     
    SYMBOL FAN_ON      = BIT8                 'SET BIT8 TO ENABLE FAN ON       
    '===============================================================================
    SYMBOL TEMP_PIN = PIN0
    SYMBOL VREF_PIN = PIN1
    SYMBOL FAN_PIN  = PIN2
    Thanks for any help or kick in the right direction. Jeff
    Attached Images Attached Images

  2. #2
    Join Date
    Mar 2006
    Location
    Pennsylvania, USA.
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Hi Jeff,
    Go to this site,
    http://www.rentron.com/PicBasic1.htm
    scroll to the bottom, and read Bruce's great tutorial on precision temperature measurement. He is using a different version of the sensor that you are using, but he discusses the differences, shows how to set up the A/D registers and how to set up vref. You can spend hours on Bruce's website, he shares a lot of knowledge, and I'm certain you'll find what you need there.

    Jerry
    If your oscilloscope costs more than your car...

  3. #3
    Join Date
    Jun 2008
    Location
    Spokane, WA
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    Brilliant, I'll check it out! Thanks!

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