DS18B20 and PIC18F4550


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2006
    Location
    Gothenburgh, Sweden
    Posts
    18

    Default DS18B20 and PIC18F4550

    Hi

    I'm trying to get the temperature values from a DS18B20 but it seems like I receive only the lower 6 bits. Right now I have 101110 wich is 2.8750.
    When I touch the sensor it will increase the values, like 110011 wich is 3.1875. So I think the sensor is ok but for some reason it doesnt give me all bits. I use a 4.7k pull up.

    My program looks like this:

    Code:
    ADCON1 = %00001111			   
    DEFINE OSC 48          
    DEFINE LOADER_USED 1
    DEFINE RESET_ORG 800h           ' For Microchip USB Bootloader
    DEFINE INTERRUPT_ORG 808h       ' For Microchip USB Bootloader
    Define  LCD_DREG        PORTA
    Define  LCD_DBIT        0
    Define  LCD_RSREG       PORTA
    Define  LCD_RSBIT       4
    Define  LCD_EREG        PORTB
    Define  LCD_EBIT        3
    DEFINE  LCD_BITS 4 
    DEFINE  LCD_LINES 2 
    DEFINE  LCD_RWREG PORTA
    DEFINE  LCD_RWBIT 2
    
    
    DQ          VAR	PortC.0     ' One-wire Data-Pin "DQ" on PortC.0
    Busy        VAR BIT         ' Busy Status-Bit
    R_Temp      VAR	WORD        ' RAW Temperature readings
    
    	Low PORTA.5			                 ' LCD R/W line low (W)
    
    MainProgram:
        OWOUT   DQ, 1, [$CC, $44]           ' Skip ROM search & do temp conversion
    Wait_Up:
        OWIN    DQ, 4, [Busy]               ' Read busy-bit
        IF      Busy = 0 THEN Wait_Up       ' Still busy..?, Wait_Up..!
        OWOUT   DQ, 1, [$CC, $BE]           ' Skip ROM search & read scratchpad memory
        OWIN    DQ, 2, [R_Temp.Lowbyte, R_Temp.Highbyte]' Read two bytes / end comms
        lcdout $fe,1,"High= ",bin R_Temp.Highbyte," Low= ",bin R_Temp.Lowbyte
    GOTO MainProgram
    END
    And it gives me "High= 0 Low= 101110" on the LCD.
    I have two sensors to test with and they act the same way.
    What can be wrong here? I tried to take the code direct from here: http://www.rentron.com/PicBasic/one-wire3.htm
    But no success. It just print +2.8750 on LCD.

    Thanks in advance.

    Stefan.

  2. #2
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    This may seem like an obvious thing but several ppl including myself made this mistake.

    On the datasheet look at the not below the pinout, it says "Bottom View" which is opposite from what you may be used to.

    Vcc and Gnd may be flipped. When this happens they seem to be functioning but that isn't the case.

    Seriously start there.

  3. #3
    Join Date
    Mar 2006
    Location
    Gothenburgh, Sweden
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    Hm... My misstake... I thought I could see a "B" In DS18B20 but there is no "B" so the resolution of the sensor is 0.5degrees instead of 0.0625degrees.
    101110 = 23,0Deg and 110011 = 25,5Deg.

    /Stefan.

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