TM34dz temp gauge with BS2

Nomadic0Nomadic0 Posts: 8
edited November 10 in BASIC Stamp Vote Up0Vote Down
Hey guys, in testing my temp chip, I wanted to know why I am getting a reading of 40 (room temp) for my temp gauge. I have it set up (with the analog to dig converter) like the pot in page 45 of this doc

https://www.parallax.com/downloads/basic-analog-and-digital-text

I am also using the sample program below it (but using DEC instead on BIN8)

On the bright side, it is reacting positively to heat

Thanks

Comments

  • 5 Comments sorted by Date Added Votes
  • How are you computing the temperature from the A/D data? My guess is that you're losing precision in the units place of your result during a divide operation.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • Tracy AllenTracy Allen Posts: 6,103
    edited November 11 Vote Up0Vote Down
    The deal is, you have fill in the subroutine in the program that converts the raw reading of the ADC into physical units such as voltage or temperature. In the program, the subroutine is a stub that is developed at great length later on in the chapter:
    Calc_Volts:
    RETURN
    
    Temperature from the LM34 is 10 millivolts per °F, so finding °F and voltage are close.

    To keep it simple, each bit represents 19.53 millivolts. That is 5000 millivolts reference divided into 256 steps. So, one bit represents about 2°F and 40 bits (as you found) represents about 19.53*40 = 781 millivolts or 78.1°F. You'd be pretty close by multiplying the binary value times two to get °F.

    There more accurate ways to do the math. The text shows one, here is another:
    Calc_Volts:
       volts = adcBits */ 5000
    RETURN
    
    The */ operator implicitly divides by 256, so the result comes out the same as if it were (for example) degF = 40 * 5000 / 256 = 781. The Stamp can't compute 40 * 5000 directly because of the 65535 limit of a 16 bit word, but */ gets around that.

  • That makes a lot more sense! I was wondering why it seemed so proportionate.

    I was also looking around and have failed to find a way to display a decimal in a DEBUG statement

    Is this possible?

    I appreciate all the feedback
  • Page 58 of that book gets into displaying the value with a decimal point. You have to split the value into the integer and fractional parts.

    In the example where answer is 781 millivolts representing 78.1 °F, You could do as follows:

    DEBUG DEC milliVolts/10, ".", DEC1 milliVolts, "degF"

    The integer division throws out the ones digit, and the DEC1 calls it out.
  • You don't know how much you helped me out

    I really appreciate it!
Sign In or Register to comment.