Quick DS18B20 question


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2009
    Posts
    9

    Default Quick DS18B20 question

    Hi, Ive hooked up the DS18B20 and have got it converting fine, but im confused by something.

    In the datasheet for the part it says it defaults to 12bit mode which should be 0.0625°C steps.

    In the example grid below its got an example of 0000 0111 1101 0000 = 125c
    so 0000 0111 1101 0000 = 2000 2000 * 0.0625 = 125 which tallys with their example. But why on my device is it sending out 101011110 which needs to be /10 to return the correct result of 35C. I would have thought going from the sheet it should have needed to be /0.0625

    Could someone explain where im going wrong reading the datasheet, as im clearly beeing stupid.

    Thanks

    Trev

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


    Did you find this post helpful? Yes | No

    Default

    35°C?, Dude, turn on the Air Conditioner!
    You can't think straight when the room is 95°F.

    Your example of 101011110, says it's 21.875°C (71.375°F) sounds much more comfortable to me.

    But since I don't know where the device is or how your program is coded, there's really no way to answer the question without joking.

    Have you seen this page?
    http://www.rentron.com/PicBasic/one-wire3.htm
    <br>
    DT

  3. #3
    Join Date
    May 2009
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel, thanks for the reply, ill have a good look at the link. Below is the code ive been working with. It seems to work fine, but thinking of it 30odd c does seem high

    Trev

    Code:
    OPTION_REG = %11010111 'Set PIC options (see datasheet).
    CMCON = 7 'turn analogue outputs to digital
    TRISA = %11111111	'all RA ports are inputs
    TRISB = %0 	'all RB ports are inputs
    TRISD = %00000000 	'all RB ports are inputs
    
    
    DEFINE LCD_DREG PORTD		' Set LCD Data port
    DEFINE LCD_DBIT 4			' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTD		' Set LCD Register Select port
    DEFINE LCD_RSBIT 3			' Set LCD Register Select bit
    DEFINE LCD_EREG PORTD		' Set LCD Enable port
    DEFINE LCD_EBIT 2			' Set LCD Enable bit
    DEFINE LCD_BITS 4			' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2			' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2000	' Set command delay time in us
    DEFINE LCD_DATAUS 50		' Set data delay time in us
    
    TEMPSEN VAR PORTD.1
    temperature Var	Word			' Temperature storage
    negTemp var temperature.bit11	' if 1 then its negative temp
    
    count_remain Var Byte			' Count remaining
    count_per_c Var	Byte			' Count per degree C
    
    
    
    PAUSE 500 'GIVE TIME TO SETTLE
    
    	LCDOUT $FE,1
    	LCDOUT "Hello"
    	PAUSE 500
    
    LOOP:
    
    
    
    
    	OWOut TEMPSEN, 1, [$CC, $44]       ' Start temperature conversion
    
    	waitloop: 
    	OWIn TEMPSEN, 4, [count_remain]	' Check for still busy converting
    	If count_remain = 0 Then waitloop
    
    	OWOut TEMPSEN, 1, [$CC, $BE]		' Read the temperature
        OWIn TEMPSEN, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
    
    
    	Lcdout $fe, 1,dec temperature, "_", dec1 temperature,"_",dec2 temperature
    	Lcdout $fe, $c0,bin temperature
    
    	Pause 5000
    
    
    If negTemp = 0 Then
    
    	lcdout $fe, 1, " Temp = ",DEC2 temperature/10,".", dec1 temperature," ",$DF,"C"
    	Lcdout $fe, $c0,dec temperature,"_", dec temperature/10,"_",DEC2 temperature/10
    Else
    	Lcdout $fe, 1, "Not Done"
    Endif
    
    	Pause 100
    
    
    GOTO LOOP
    
    
    
    
    
    END

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


    Did you find this post helpful? Yes | No

    Default

    Looks like you started out with a DS1820 example, since the DS18B20 doesn't have COUNT_REMAIN and COUNT_PER_C registers.

    To answer your original question, yes it does normally default to 12-bit.
    However, any resolution can be stored in non-volitile memory, in which case it will power-up at that reolution instead.

    But with any resolution, the calculation is the same ( * 625, DIV32 10).

    Bruce's page I pointed to previously covers that, and more.

    Hope it works out for you.
    <br>
    DT

  5. #5
    Join Date
    May 2009
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel for the help, its much appreciated. Im trying to get used to reading the datasheets to understand how to communicate with the devices but as you can see not reading them so well at the moment.
    I did try to read the datasheet for the (real time Ic) DS1302 last night but well that just confused me, i think i need the picture book version for ages 1 to 5

    ill have a good read of that link you gave me.


    Trev

Similar Threads

  1. Please help with code for DS18B20
    By fratello in forum mel PIC BASIC Pro
    Replies: 109
    Last Post: - 28th April 2013, 21:12
  2. Quick USB CRC5 question
    By Michael Wakileh in forum USB
    Replies: 2
    Last Post: - 12th June 2009, 04:23
  3. PIC16F84A - Quick question
    By samuelbarber in forum mel PIC BASIC
    Replies: 1
    Last Post: - 29th June 2005, 14:32
  4. Interrupt Quick Question
    By shawn in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th January 2005, 05:51
  5. quick question
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd December 2004, 01:45

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