Shop OBEX P1 Docs P2 Docs Learn Events
Temperature Conversions — Parallax Forums

Temperature Conversions

Tom PTom P Posts: 97
edited 2007-05-16 21:16 in BASIC Stamp
How do I implement BASIC STAMP 2 math to convert a number from Celsius to Fehrenheit?

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2007-05-16 13:49
    What have you tried to date?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • Tom PTom P Posts: 97
    edited 2007-05-16 13:55
    Nothing yet! Before I spin my math deficient wheels, I wanted some advice!!
    Tom
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-16 13:59
    See the following link. Tracy Allen posted a link to a Digital Thermometer and I posted one as well to a project (Digital Thermostat) he actually helped me with the conversion code on. I hope this helps. Take care.

    http://forums.parallax.com/showthread.php?p=646324

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-16 14:03
    1) You have to know the formula for converting from Celsius to Fahrenheit

    2) Because the Stamp only does 16-bit integer arithmetic, you have to decide how much precision you want (tenths of a degree or degrees or what?)

    3) Have a look at EmeSystems' website (www.emesystems.com) for all kinds of information on doing fixed point arithmetic with the Stamp, particularly the webpage on math. There are lots of practical examples with sample code for the Stamp.
  • stamptrolstamptrol Posts: 1,731
    edited 2007-05-16 14:47
    1. For determining whether to wear a sweater or coat:

    celcius to F
    double it and add 32 (ie 20C = 72F)
    F to celcius
    subtract 32 then halve it (ie 80F = 24C)

    2. more generally: c to F
    F= (9/5 * C) +32
    F to C
    C= (F-32)*5/9

    As Mike has pointed out, watch your variable sizes and anticipate the maximum possible result of any calculations.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-16 14:56
    From the code I linked to, here is the routine which reads the temperature from the DS1620 and then converts the C temp to F. Thanks to Tracy Allen for offering improvements to my original code. Resolution is much improved although in this application I am only using 1 degree of resolution anyway. Take care.
    Get_Temp:
      HIGH Reset                                      ' Select DS1620
      SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdTemp]      ' Send Read Temp Command
      SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]tempIn\9]       ' Read Temp Data
      LOW Reset                                       ' Deselect DS1620
      tempIn.BYTE1 = -tempIn.BIT8                     ' Extend Sign To 16 Bits
      tempC = tempIn * 5                              ' Convert To C * 5 (Resolution 0.5 C)
      tempF = tempC + 2732 * 9 / 50 - 459             ' C * 10 to F (First To Kelvin * 10)
      RETURN
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • WhitWhit Posts: 4,191
    edited 2007-05-16 21:16
    Mike Green said...
    3) Have a look at EmeSystems' website (www.emesystems.com)
    ·Neat stuff Mike! Thanks for the link.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Whit+
Sign In or Register to comment.