Shop OBEX P1 Docs P2 Docs Learn Events
Trying to read LM34 value in F with ADC0831 without any luck — Parallax Forums

Trying to read LM34 value in F with ADC0831 without any luck

PeteStarksPeteStarks Posts: 7
edited 2013-12-10 12:24 in BASIC Stamp
I have not touched my BS2 parts in many years which has made me more than a bit rusty. I normally use the Propeller for most of my tinkering, but seeing as I need a very simple device to monitor analog sensors such as the LM34 I felt it was overkill. I would also like to make use of all the parts I currently have in my bin which include the LM34, ADC0831 and the BS2.

I have checked the object exchange and see there is an object to do exactly what I need and would work in a matter of seconds if I were using a Prop, but I am attempting to go forward with the BS2. I have complete information overload on this very simple problem and have been skimming through the Process Control book, Stamp Works, the Pbasic references and Tracy Allen’s fine website. Between all these different bits of information and code I have somehow missed a working example that will output the LM34 data to DEBUG in F format.

Could someone please take mercy on my poor brain and either post or link me to some working code that will do what I need? I personally learn much faster by reverse engineering something that works rather than reading 500 pages of theory about changing a light bulb.

I would post my code, but it has changed so many times and with so many dead ends I would just like to start fresh at this point. Any help is more than appreciated :)

Comments

  • SapphireSapphire Posts: 496
    edited 2013-06-21 14:41
    This will work, provided that the Vref of your ADC is set to 1.28v exactly. If not, then you will have to change the scaling factor in the DEBUG line.
      CS   PIN  0   ' chip select  
      DX   PIN  1   ' data out
      CLK  PIN  2   ' clock
      result  VAR BYTE  ' result of ADC conversion
    
      DO
        LOW CS                              ' enable CS
        SHIFTIN DX,CLK,MSBPOST,[result\9]   ' read temperature and store in result
        HIGH CS                             ' disable CS
    
        DEBUG "Temp = ",DEC result*/$080,"F",CR    ' display temp ($080 is scaling of 1/2 for Vref = 1.28v)
        PAUSE 1024
      LOOP
    

    If your Vref is 5.0v then the scaling factor will be $1F4 (nearly 1.93) to account for the larger span. For improved accuracy keep Vref as low as possible. The LM34 outputs an analog voltage of 10mV per degree F.
  • PeteStarksPeteStarks Posts: 7
    edited 2013-06-21 15:18
    I knew there had to be a few simple lines of code this all boiled down to!
    Thank you very much for allowing me to stop drowning in google searches, only to find code that ALMOST fit my situation. I am running with a Vref of 5v as provided by the BS2 BOE, which is still pretty close compared to my laser thermometer. It seems the magic scaling factor is what was hanging me up. I'll spend a little time dialing in the accuracy, but your post has set me straight.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-06-21 18:39
    As a note, since the LM34 outputs 1mV per degree then if you had a 2.55V reference the output of the ADC would be in degrees. In other words an 85 from the ADC would equal 85 degrees. Of course, I haven't found a fixed 2.55V reference IC that is stand-alone.

    Edit: Correction, 10 mV/Degree, but the math would still be much easier/simpler. :innocent:
  • PeteStarksPeteStarks Posts: 7
    edited 2013-06-21 19:21
    Thanks for the info Chris. I have opened a new can of worms(and thread) for the MCP3002 ADC, but anything that will simplify the math is welcome :)
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2013-07-13 13:12
    [QUOTE=Chris Savage;1191334 I haven't found a fixed 2.55V reference IC that is stand-alone. :innocent:[/QUOTE]

    Here is one http://www.ti.com/lit/ds/symlink/ref3112.pdf
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-07-15 15:08
    According to the datasheet you linked it apears to be 2.5V not 2.55V
  • ad9409ad9409 Posts: 8
    edited 2013-12-10 12:24
    Sapphire wrote: »
    This will work, provided that the Vref of your ADC is set to 1.28v exactly. If not, then you will have to change the scaling factor in the DEBUG line.
      CS   PIN  0   ' chip select  
      DX   PIN  1   ' data out
      CLK  PIN  2   ' clock
      result  VAR BYTE  ' result of ADC conversion
    
      DO
        LOW CS                              ' enable CS
        SHIFTIN DX,CLK,MSBPOST,[result\9]   ' read temperature and store in result
        HIGH CS                             ' disable CS
    
        DEBUG "Temp = ",DEC result*/$080,"F",CR    ' display temp ($080 is scaling of 1/2 for Vref = 1.28v)
        PAUSE 1024
      LOOP
    

    If your Vref is 5.0v then the scaling factor will be $1F4 (nearly 1.93) to account for the larger span. For improved accuracy keep Vref as low as possible. The LM34 outputs an analog voltage of 10mV per degree F.

    Why are you scaling by a 1/2 factor?
    Also what is the clock and chip select exactly doing?

    Thanks
Sign In or Register to comment.