Ds18b20..


Closed Thread
Results 1 to 6 of 6

Thread: Ds18b20..

  1. #1
    Join Date
    Mar 2008
    Posts
    79

    Default Ds18b20..

    I've seen many examples of code for the DS18B20 and I've successfully made it work before
    However there is one thing I dont understand and could someone please explain it to me?
    IN this code
    Code:
    DS18B20_9bit CON %00011111 ; 93.75ms, 0.5°C
    'DS18B20_10bit CON %00111111 ; 187.5ms, 0.25°C <-- My favorite
    'DS18B20_11bit CON %01011111 ; 375ms, 0.125°C
    'DS18B20_12bit CON %01111111 ; 750ms, 0.0625°C (default)
    I can see how the various resolutions are BUT when it comes to this line
    Code:
    OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_9bit
    HOW do I tell it I want to have 10 or 11 or 12 bit resolution?

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Karen,

    First you need to uncomment ALL the constants.

    Then in the OWOUT statement, just change the DS18B20_9bit to the desired resolution.

    DT

    P.S. don't forget the trailing bracket ]

  3. #3
    Join Date
    Mar 2008
    Posts
    79


    Did you find this post helpful? Yes | No

    Default

    OMG how can i be so dumb sometimes!
    it was So obvious that I just didn't see it
    Thank you
    umm btw what do you mean about the trailing bracket? ]

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by karenhornby View Post
    umm btw what do you mean about the trailing bracket? ]
    Look at you second bit of code in post #1. I think that is what he means.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Mar 2008
    Posts
    79


    Did you find this post helpful? Yes | No

    Default

    Am I right in assuming IF i dont use the constants then it would default to 0.0625°C resolution and take 750ms to take a reading?
    BUT IF I want to change the resolution I'd use the constants, but the code would be
    Code:
    OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_9bit] 
    OR OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_10bit] etc?
    and this would take 187.5ms?

    OK figured out $33 is skip rom command, and $4E is Write scratchpad
    but what's the 0,0 after it?


    ANd IF I was using more than 1 temp sensor then it would be something like
    Code:
    OWOUT  DQ, 1, [$55,$28,$B1,$FE,$22,$00,$00,$00,$5D,$44, $3F ] 
    ; or do I HAVE to use the DS18B20_10bit instead of $3F?
    Assuming the ROM address is $B1,$FE,$22,$00,$00,$00?

    I know that Match ROM is $55, Read ROM is $33, and Search Rom is $F0

    And I know the $44 at the end is telling it to start a temperature conversion


    Sorry for asking so many questions
    Last edited by karenhornby; - 18th June 2008 at 15:30.

  6. #6
    Join Date
    Mar 2008
    Posts
    79


    Did you find this post helpful? Yes | No

    Default

    THINK I've sussed a bit more:
    IF I want to change the resolution from the default I can use something like
    Code:
    OWOUT DQ, 1, [$CC, $4E, 0, 0, $5F] ' 11 bit resolution
    and to address individual 1wire devices I'd use something like

    Code:
    OWOUT DQ, 1, [$55,$28,$B1,$FE,$22,$00,$00,$00,$5D,$44,$5F] THEN
    OWIN DQ, 4, [Stat]  ' Stat is constant + Check for still busy converting
     IF Stat = 0 THEN W1    ' Still busy?, then loop
     OWOUT DQ, 1,[$55,$28,$B1,$FE,$22,$00,$00,$00,$5D,$BE]
     OWIN DQ, 2, [Temp.LOWBYTE,Temp.HIGHBYTE]  'Read two bytes, + end communications
        GOSUB Convert_Temp

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