using the DS18B20


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2006
    Posts
    747

    Default using the DS18B20

    HI,

    I have been trying to make a DS18S20 work, I have used the code on Rentron to guide me.
    http://www.rentron.com/PicBasic/one-wire3.htm
    BUt what I get around 3000 degrees as my output.
    I basically took his code and removed the Fahrenheit calculation and put it on a LCDout command. with no minus temperature.
    shouldn't the command Div32 give me the temperature in Celcius directly ?

    ken


    Start_Convert:
    OWOUT Comm_Pin, 1, [$CC, $44]' Skip ROM search & do temp conversion
    Wait_Up:
    OWIN Comm_Pin, 4, [Busy] ' Read busy-bit
    IF Busy = 0 THEN Wait_Up ' Still busy..?, Wait_Up..!
    OWOUT Comm_Pin, 1, [$CC, $BE]' Skip ROM search & read scratchpad memory
    OWIN Comm_Pin, 2, [R_Temp.Lowbyte, R_Temp.Highbyte]' Read two bytes / end comms
    GOSUB Convert_Temp
    GOTO Start_Convert
    Convert_Temp:
    Sign = "+" Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value
    TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
    Lcdout $fe, 1 'Clear screen
    Lcdout "Value: ", DEC TempC, Deg,"C " 'Display the decimal value
    RETURN
    END
    Last edited by lerameur; - 17th December 2006 at 13:30.

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Hi lerameur,


    In your code, after TempC = DIV32 10 you are missing following two lines.

    Code:
    Dummy = 1125 * R_Temp
    TempC = (R_Temp & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
    ------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I tried that too,but I get 2 degrees steady output. I thought it would be somewhere in my LCDout command,

    Start_Convert:
    OWOUT Comm_Pin, 1, [$CC, $44]' Skip ROM search & do temp conversion
    Wait_Up:
    OWIN Comm_Pin, 4, [Busy] ' Read busy-bit
    IF Busy = 0 THEN Wait_Up ' Still busy..?, Wait_Up..!
    OWOUT Comm_Pin, 1, [$CC, $BE]' Skip ROM search & read scratchpad memory
    OWIN Comm_Pin, 2, [R_Temp.Lowbyte, R_Temp.Highbyte]' Read two bytes / end comms
    GOSUB Convert_Temp
    GOTO Start_Convert
    '65
    Convert_Temp: ' +32.0 to +257 F
    Sign = "+"
    Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value
    TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
    Dummy = 1125 * R_Temp
    TempF = DIV32 100

    TempC = (R_Temp & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
    Float = ((R_Temp.Lowbyte & $0F) * 625) ' Lower 4-bits of result * 625
    Lcdout $fe, 1 'Clear screen
    Lcdout " TempC = ",Sign,DEC TempC,".",DEC Float,Deg,"C " 'Display the decimal value
    RETURN

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    For the DS18S20 just read the temperature, divide by 2, and that will be the
    temp in deg C for positive temps.

    For negative temp in deg C, complement the value read, divide by 2, then
    add 1. That's all you need to do for a DS18S20 deg C conversion.

    The code you're trying to use is for a DS18B20 which is 12-bit. The DS18S20
    isn't 12-bit. Compare both datasheets for an explanation.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    If i look on the chip, it says DS1820, but on my order sheet from digikey it says DS18S20+CT-ND
    You think they sent me the wrong chip ?

    I got it working, juste did not seperate th loe and high bytes

    k
    Last edited by lerameur; - 17th December 2006 at 23:03.

  6. #6
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    HI I found this program ,
    it seems to work , but it is 2 degrees higher then my other thermometer.
    Ken



    DQ var PortB.3
    temp var word

    loop:
    owout DQ,1,[$cc]
    owout DQ,0,[$44]
    Pause 500
    owout DQ,1,[$cc]
    owout DQ,0,[$be]
    owin DQ,0,[temp.byte0,temp.byte1]
    lcdout $FE,1
    temp=temp*5

    lcdout " Temp = ",DEC2 temp/10,".", dec1 temp," ",$DF,"C"
    goto loop

    End

  7. #7
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    i got this part to work fine now

Similar Threads

  1. Reading temperature using multi DS18B20
    By KVLV in forum Code Examples
    Replies: 16
    Last Post: - 3rd November 2017, 19:48
  2. Please help with code for DS18B20
    By fratello in forum mel PIC BASIC Pro
    Replies: 109
    Last Post: - 28th April 2013, 21:12
  3. Help with DS18B20 program
    By presario1425 in forum mel PIC BASIC Pro
    Replies: 38
    Last Post: - 22nd August 2012, 00:50
  4. Multi DS18b20 Code help.
    By sccsltd in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th December 2009, 06:13
  5. DS18B20 error reading
    By Gaetano in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th August 2007, 16:21

Members who have read this thread : 1

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