Shop OBEX P1 Docs P2 Docs Learn Events
Stumped Trying to convert Deg C to Deg F — Parallax Forums

Stumped Trying to convert Deg C to Deg F

GuidoGuido Posts: 195
edited 2007-05-28 22:49 in BASIC Stamp
I am using Peter Andersons PIC One Wire Controller using a DS18B20 Temperature sensor. I am having a heck of a time converting his program to Read Degrees F. Any Help would be appreciaqted.
Guido




Main:
DO
AGN:
··· SEROUT 9, T9600, 10, [noparse][[/noparse]"P0", "W0cc", "S044"]···· 'perform temp meas
···································································· ' note strong pullup
··· PAUSE 1100················································ ' wait for conversion to complete
··· SEROUT 9, T9600, 10, [noparse][[/noparse]"P0", "W0cc", "W0be"]···· ' send temperature data
··· SEROUT 9, T9600, 10, [noparse][[/noparse]"R0"]···················· ' fetch data
··· SERIN 8, T9600, 1500, TimeOut, [noparse][[/noparse]DEC X.LOWBYTE]
··· PAUSE 100
··· SEROUT 9, T9600, 10, [noparse][[/noparse]"R0"]···················· ' fetch data
··· SERIN 8, T9600, 1500, TimeOut, [noparse][[/noparse]DEC X.HIGHBYTE]
··· PAUSE 100
··· ' now do the calculations
··· SignBit = X / 256 / 128
··· IF SignBit = 1 THEN ' its negative
······ X = X ^ $ffff + 1 ' take the two's comp
··· ENDIF
··· ' multiply by 6.25 - This is 100 * Tc
··· Y = X / 4·· ' 0.25
··· X = X * 6 + Y
··· Whole = X / 100
··· Fract = X // 100
··· IF SignBit = 1 THEN
······ DEBUG "-", DEC Whole, ".", DEC2 Fract, CR
··· ELSE
······ DEBUG DEC Whole, ".", DEC2 Fract, CR
··· ENDIF
··· PAUSE 3000 ' wait 3 secs
· LOOP

Comments

  • BeanBean Posts: 8,129
    edited 2007-05-28 21:50
    Try this:

    Main:
    DO
    AGN:
        SEROUT 9, T9600, 10, [noparse][[/noparse]"P0", "W0cc", "S044"]     'perform temp meas
                                                                         ' note strong pullup
        PAUSE 1100                                                 ' wait for conversion to complete
        SEROUT 9, T9600, 10, [noparse][[/noparse]"P0", "W0cc", "W0be"]     ' send temperature data
        SEROUT 9, T9600, 10, [noparse][[/noparse]"R0"]                     ' fetch data
        SERIN 8, T9600, 1500, TimeOut, [noparse][[/noparse]DEC X.LOWBYTE]
        PAUSE 100
        SEROUT 9, T9600, 10, [noparse][[/noparse]"R0"]                     ' fetch data
        SERIN 8, T9600, 1500, TimeOut, [noparse][[/noparse]DEC X.HIGHBYTE]
        PAUSE 100
        ' now do the calculations
        SignBit = X / 256 / 128
        IF SignBit = 1 THEN ' its negative
           X = X ^ $ffff + 1 ' take the two's comp
        ENDIF
        ' multiply by 11.25 - This is 100 * Tf
        Y = X / 4   ' 0.25
        X = X * 11 + Y
        x = x + 3200  ' Add 32 degrees (Tf offset)
        Whole = X / 100
        Fract = X // 100
        IF SignBit = 1 THEN
           DEBUG "-", DEC Whole, ".", DEC2 Fract, CR
        ELSE
           DEBUG DEC Whole, ".", DEC2 Fract, CR
        ENDIF
        PAUSE 3000 ' wait 3 secs
      LOOP
    
    

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • GuidoGuido Posts: 195
    edited 2007-05-28 22:11
    Bean!!!!!

    Thank You very much works great. Maybe you can also help me with this. I would like to serout the Temperature readings to another stamp. But I don not want to waste two word Variables to do it? Any Ideas
  • GuidoGuido Posts: 195
    edited 2007-05-28 22:49
    Never Mind

    Thanks Again Bean
Sign In or Register to comment.