DS18S20 reading negative temperature


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Nov 2007
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Actually, the solution to your problem is easier than I thought. DS18S20's resolution is 0.5 C. So, you can use the following algorithm for negative temps -

    Lets say RAWTEMP is where you stored the raw data out of the DS18S20. If bit#8 of RAWTEMP is 1, then you know that the temp is negative. In that case, invert RAWTEMP and add 1 to it (RAWTEMP = ~RAWTEMP + 1). If you multiply this number by 5 and store it in a variable, say TempC, you'll see that TempC will be the actual temperature, only multiplied by 10. For example, when TempC reads 450, then your actual temperature is -45 C. Let's try to do this with a real raw binary reading out of the DS18S20 -

    Let's say that the raw binary reading out of your DS18S20 is

    1111 1111 0101 1101

    Since bit#8 is 1, we know that this is some negative temperature reading. Now we invert and then add 1 to the reading-
    Code:
     RAWTEMP = 1111 1111 0101 1101
    ~RAWTEMP = 0000 0000 1010 0010
          +1 = 0000 0000 1010 0011
    "0000 0000 1010 0011" represents a decimal value of 163. Multiply this number by 5 and we get 815. So, this really is -81.5C (of course this is out of the range of your sensor, but you get the idea). For example, take one of the readings from DS18S20's datasheet. -55C is represented by the raw binary value of "1111 1111 1001 0010". Inverting and then adding 1 reselts in "0000 0000 0110 1110" whis is 110 in decimal. Multiply this number by 5 and you get 550, which is -55C.

    Hope this helps.

  2. #2
    Join Date
    Jun 2004
    Posts
    24


    Did you find this post helpful? Yes | No

    Smile

    This is true presario, and is perfectly adequate for my needs - the circuit needs to trigger an alarm when the ambient temperature falls below zero, and another alarm if the temperature reaches -7 degrees C. So I was going to use a spare indoor thermostat that I make previously, and reprogramme the PIC to suit (saving time and build cost). However, my pride would like me to display the temperature to the same resoultion of 0.1 degree, both in the negative and possitive, the formula used in onewire.bas, gives a resoultion of 0.01 degrees.

    I think the best way forward is to try it and see what happens, and look at the contents of the DS18S20 COUNT_REMAIN and COUNT_PER_C registers, with the sensor left in my freezer for an hour or so, with a known accurate thermometer and adjust algorithm accordingly.

    many thanks

Similar Threads

  1. Reading temperature using multi DS18B20
    By KVLV in forum Code Examples
    Replies: 16
    Last Post: - 3rd November 2017, 19:48
  2. Wireless with DS18S20
    By lerameur in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 2nd May 2007, 20:07
  3. Reading (ADC) negative current
    By sougata in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 21st November 2006, 17:38
  4. DS18s20 - negative teperature
    By Ceug2005 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd February 2005, 12:40
  5. 16F877, DS18S20 and Serial Comm Problem
    By YellowTang in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th April 2004, 10:36

Members who have read this thread : 2

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