It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.
+ Reply to Thread
Results 1 to 29 of 29
  1. #1
    Join Date
    Feb 2013
    Posts
    497

    Default It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Hello, I'm trying to get this sensor working with PIC16F1519. It is connected to PORTD.1 and MAX7219 display to PORTC. Nothing else. I'm using 4.7k resistor to deliver voltage to it. But it does not works. If I use 4.7k or 5.6k resistor, it will return 127, if I use 2.2k or 10k resistors, it will return 85. I've tried replacing chip, playing with ANSELD and TRISD registers - no luck. I'm using "classic" code from melabs example. What I'm doing wrong?

    Code:
    ;----[16F1519 Hardware Configuration]-------------------------------------------
    #IF __PROCESSOR__ = "16F1519"
      #DEFINE MCU_FOUND 1
    #CONFIG
    cfg1 = _FOSC_INTOSC           ; INTOSC oscillator: I/O function on CLKIN pin
    cfg1&= _WDTE_OFF              ; WDT disabled
    cfg1&= _PWRTE_OFF             ; PWRT disabled
    cfg1&= _MCLRE_OFF             ; MCLR/VPP pin function is MCLR
    cfg1&= _CP_OFF                ; Program memory code protection is disabled
    cfg1&= _BOREN_OFF             ; Brown-out Reset disabled
    cfg1&= _CLKOUTEN_OFF          ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
    cfg1&= _IESO_OFF              ; Internal/External Switchover mode is disabled
    cfg1&= _FCMEN_OFF             ; Fail-Safe Clock Monitor is disabled
      __CONFIG _CONFIG1, cfg1
    cfg2 = _WRT_OFF               ; Write protection off
    cfg2&= _VCAPEN_OFF            ; VCAP pin function disabled
    cfg2&= _STVREN_ON             ; Stack Overflow or Underflow will cause a Reset
    cfg2&= _BORV_LO               ; Brown-out Reset Voltage (Vbor), low trip point selected.
    cfg2&= _LPBOR_OFF             ; Low-Power BOR is disabled
    cfg2&= _LVP_OFF               ; High-voltage on MCLR/VPP must be used for programming
      __CONFIG _CONFIG2, cfg2
    #ENDCONFIG
    #ENDIF
    ;----[Verify Configs have been specified for Selected Processor]----------------
    ;       Note: Only include this routine once, after all #CONFIG blocks
    #IFNDEF MCU_FOUND
      #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #ENDIF
    
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2018 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 11.12.2018                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    'SERVOCONTROLLER SYSTEM
                            
    'init
    include "modedefs.bas"
    OSCCON = %01111010  'SET INTOSC TO 16MHZ
    ANSELC=%00000000
    ANSELD=%00000000
    TRISC=%00000000 'set PORTC as output all
    TRISD=%11111111 'set PORTD as output all
    DEFINE OSC 16
    dqd var PORTD.1
    tvla var word
    temperature var word
    'DEFINES:
     Clk     Var PORTC.6  ' Data is clocked on rising edge of this pin            mcvane
     Dta   Var PORTC.5  ' Bits are shifted out of this pin          KVITELI
     Load    Var PORTC.4  ' Transfers data to LEDs when Pulsed   lurji
     
     
     'MAX7219 STUFF
        ' ** Declare Constants **
     Decode_Reg  Con 9 ' Decode register, a 1 turns on BCD decoding for each digit. 
     Lum_Reg  Con 10 ' Intensity register.
     Scan_Reg Con 11 ' Scan-limit register.
     Switch_Reg Con 12 ' On/Off Register.
     Test_Reg Con 15 ' Test mode register (all digits on, 100% bright)
     Max_Digit Con 4 ' Amount of LED Displays being used.
    ' ** Declare Variables **
       Counter  Var Word ' Variable used for the Demo Counting routine
     Max_Disp Var Word ' 16-bit value to be displayed by the MAX7219
     Max_Dp  Var Byte ' Digit number to place Decimal point (0-4)
     Register Var Byte ' Pointer to the Internal Registers of the MAX7219
     R_Val  Var Byte ' Data placed in Each Register
     Digit  Var Byte ' Position of individual numbers within MAX_Disp (0-3)
     Position Var Byte ' Position of each LED display (1-4)
     
     ' Turn Off test mode
     Register=Scan_Reg  ' Point to the Scan Register
     R_Val=7    ' send 3, (Four LED Displays 0-3)
     Gosub Transfer   ' Transfer this 16-bit Word to the MAX7219
     Register=Lum_Reg  ' Point to the Luminance Register
     R_Val=1    ' Send 5, (Value for Brightness)
     Gosub Transfer   ' Transfer this 16-bit Word to the MAX7219
     Register=Decode_Reg  ' Point to BCD Decode Register
     R_Val=%00001111 ' Decode the first 8 digits
     Gosub Transfer   ' Transfer this 16-bit Word to the MAX7219
     Register=Switch_Reg  ' Point to the Switch Register 
     R_Val=1    ' Set to One, (switches the display ON)
     Gosub Transfer   ' Transfer this 16-bit Word to the MAX7219
     Register=Test_Reg  ' Point to the Test Register
     R_Val=0    ' Reset to Zero, (turns off Test mode)
     Gosub Transfer   ' Transfer this 16-bit Word to the MAX7219
    
     Max_Dp=0   ' Display number for Decimal Point
    REGISTER=8      'display some name
    R_VAL=124
    GOSUB TRANSFER
    REGISTER=7
    R_VAL=110
    GOSUB TRANSFER 
    REGISTER=6
    R_VAL=120
    GOSUB TRANSFER 
    REGISTER=5
    R_VAL=57
    GOSUB TRANSFER 
    
    TTK:
    pause 500 
    gosub gradus1
    max_disp=temperature
    GOSUB DISPLAY
    GOTO TTK
    
    
    
    GRADUS1:
            OWOUT DQD, 1, [$CC, $44] ' Start temperature conversion
            pause 750
            OWOUT DQD, 1, [$CC, $BE]         ' Read the temperature
            OWIN DQD, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
            temperature = temperature */ 1600
            TEMPERATURE=TEMPERATURE/100
    
      
    return
     
    Display:
     Digit=0      ' Start at Digit 0 of Max_Disp Variable
     For Position=4 to 1 step -1   ' Start at Farthest Right of Display   
     Register=5-Position    ' Place Position into Register
     R_Val=Max_Disp Dig Digit   ' Extract the individual numbers from Max_Disp   
     If Max_Disp<10 and Position=3 then R_Val=15 ' Zero Suppression for the second digit
     If Max_Disp<100 and Position=2 then R_Val=15 ' Zero Suppression for the Third digit
     If Max_Disp<1000 and Position=1 then R_Val=15 ' Zero Suppression for the Forth digit
     If Max_Disp<10000 and Position=0 then R_Val=15 ' Zero Suppression for the Fifth digit
     If Digit=Max_Dp then R_Val.7=1   ' Place the decimal point, held in Max_DP
     Gosub Transfer     ' Transfer the 16-bit Word to the MAX7219
     If Digit>=3 then Digit=0   ' We only need the first four digits
     Digit=Digit+1     ' Point to next Digit within Max_Disp
     Next Position     ' Close the Loop
     Return
    ' Send a 16-bit word to the MAX7219 
    Transfer:
       Shiftout Dta,Clk,msbfirst,[Register,R_Val] ' Shift Out the Register first, then the data
     High Load    ' The data is now acted upon
     PAUSEUS 100
    @ Nop
    @ Nop     ' A small delay to ensure correct clocking times
     Low Load    ' Disable the MAX7219 
     Return     ' Exit from Subroutine

  2. #2
    Join Date
    Feb 2013
    Posts
    497

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Tried to move to PORT.C or B, same result.....

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,179

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Well, you are working with a parasitic powered device and the "85" you are getting from it is correct as it is the poweron default temperature. have you read the spec for the part? it states:
    CONVERT T [44h]
    This command initiates a single temperature conversion. Following the conversion, the resulting thermal
    data is stored in the 2-byte temperature register in the scratchpad memory and the DS18B20-PAR returns
    to its low-power idle state. Within 10 μs (max) after this command is issued the master must enable a
    strong pullup on the 1-Wire bus for the duration of the conversion (tconv) as described in the PARASITE
    POWER section.
    is the port pin at a high level with out the resistor after giving the "44" command? It may have worked on the test board designed by MeLabs because they used the normal DS18B20 part which has an input for +5 volts.
    I also notice this in your code as the comment is wrong:
    TRISD=%11111111 'set PORTD as output all
    setting these bits to 1 set's the pins to inputs. Thy something like this for parasitic powered devices:
    TRISD.1 = 0 'set portd.1 as an output, this pin will be made an input when required
    LATD.1 = 1 'set the default output state to high, when not set as output this pin will source +5 volts.
    Dave Purola,
    N8NTA
    EN82fn

  4. #4
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,179

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Try this:
    ANSELD=%00000000
    TRISD=%11111101
    LATD.1 = 1 'DEFAULT OUTPUT STATE FOR PORTD.1
    dqd var PORTD.1


    GRADUS1:
    OWOUT DQD, 1, [$CC, $44] ' Start temperature conversion
    TRISD.1 = 0 'MAKE PIN AN OUTPUT WITH DEFAULT STATE HIGH
    pause 760 'ADD AN EXTRA 10 Ms.
    OWOUT DQD, 1, [$CC, $BE] ' Read the temperature
    OWIN DQD, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
    temperature = temperature */ 1600
    TEMPERATURE=TEMPERATURE/100
    return
    Dave Purola,
    N8NTA
    EN82fn

  5. #5
    Join Date
    Feb 2013
    Posts
    497

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Thanks, tried it, but still 85.....

  6. #6
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,179

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Well I have NO idea what pullup resistor you are using but, after my last post I took the code I presented to you and placed it into an 16F88 processor running @ 20 Mhz. with a 4.7K resistor. It works flawlessly. Here are the lines of code exactly.

    OWOUT PB0, 1, [$CC, $44] ' Start temperature conversion
    PORTB.0 = 1 'KEEP PIN POWERED
    TRISB.0 = 0 'MAKE PIN AN OUTPUT WITH DEFAULT STATE HIGH
    pause 760 'ADD AN EXTRA 10 Ms. FOR THE CONVERSION
    OWOUT PB0, 1, [$CC, $BE] ' Read the temperature
    OWIN PB0, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
    Dave Purola,
    N8NTA
    EN82fn

  7. #7
    Join Date
    Feb 2013
    Posts
    497

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    I tried all values from 2.2k to 10k, same "85".

    Here is complete code

    Code:
    ;----[16F1519 Hardware Configuration]-------------------------------------------
    #IF __PROCESSOR__ = "16F1519"
      #DEFINE MCU_FOUND 1
    #CONFIG
    cfg1 = _FOSC_INTOSC           ; INTOSC oscillator: I/O function on CLKIN pin
    cfg1&= _WDTE_OFF              ; WDT disabled
    cfg1&= _PWRTE_OFF             ; PWRT disabled
    cfg1&= _MCLRE_OFF             ; MCLR/VPP pin function is MCLR
    cfg1&= _CP_OFF                ; Program memory code protection is disabled
    cfg1&= _BOREN_OFF             ; Brown-out Reset disabled
    cfg1&= _CLKOUTEN_OFF          ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
    cfg1&= _IESO_OFF              ; Internal/External Switchover mode is disabled
    cfg1&= _FCMEN_OFF             ; Fail-Safe Clock Monitor is disabled
      __CONFIG _CONFIG1, cfg1
    
    cfg2 = _WRT_OFF               ; Write protection off
    cfg2&= _VCAPEN_OFF            ; VCAP pin function disabled
    cfg2&= _STVREN_ON             ; Stack Overflow or Underflow will cause a Reset
    cfg2&= _BORV_LO               ; Brown-out Reset Voltage (Vbor), low trip point selected.
    cfg2&= _LPBOR_OFF             ; Low-Power BOR is disabled
    cfg2&= _LVP_OFF               ; High-voltage on MCLR/VPP must be used for programming
      __CONFIG _CONFIG2, cfg2
    
    #ENDCONFIG
    
    #ENDIF
    
    ;----[Verify Configs have been specified for Selected Processor]----------------
    ;       Note: Only include this routine once, after all #CONFIG blocks
    #IFNDEF MCU_FOUND
      #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #ENDIF
    
    
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2018 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 11.12.2018                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    'SERVOCONTROLLER SYSTEM
                            
    'init
    
    include "modedefs.bas"
    OSCCON = %01111010  'SET INTOSC TO 16MHZ
    ANSELC=%00000000
    ANSELD=%00000000
    TRISC=%00000000 'set PORTC as output all
    TRISD=%11111101 'set PORTD as output all
    LATD.1=1
    
    DEFINE OSC 16
    
    dqd var PORTD.1
    tvla var word
    temperature var word
    'DEFINES:
    
    	Clk     Var	PORTC.6		' Data is clocked on rising edge of this pin            mcvane
    	Dta  	Var	PORTC.5		' Bits are shifted out of this pin          KVITELI
    	Load    Var	PORTC.4		' Transfers data to LEDs when Pulsed   lurji
    	
    	
    	'MAX7219 STUFF
    
        ' ** Declare Constants **
    	Decode_Reg 	Con	9	' Decode register, a 1 turns on BCD decoding for each digit. 
    	Lum_Reg		Con	10	' Intensity register.
    	Scan_Reg	Con	11	' Scan-limit register.
    	Switch_Reg	Con	12	' On/Off Register.
    	Test_Reg	Con	15	' Test mode register (all digits on, 100% bright)
    
    	Max_Digit	Con	4	' Amount of LED Displays being used.
    
    ' ** Declare Variables **
      	Counter		Var	Word	' Variable used for the Demo Counting routine
    	Max_Disp	Var	Word	' 16-bit value to be displayed by the MAX7219
    	Max_Dp		Var	Byte	' Digit number to place Decimal point (0-4)
    	Register	Var	Byte	' Pointer to the Internal Registers of the MAX7219
    	R_Val		Var	Byte	' Data placed in Each Register
    	Digit		Var	Byte	' Position of individual numbers within MAX_Disp (0-3)
    	Position	Var	Byte	' Position of each LED display (1-4)
    	
    	' Turn Off test mode
    
    	Register=Scan_Reg		' Point to the Scan Register
    	R_Val=7				' send 3, (Four LED Displays 0-3)
    	Gosub Transfer			' Transfer this 16-bit Word to the MAX7219
    
    	Register=Lum_Reg		' Point to the Luminance Register
    	R_Val=1				' Send 5, (Value for Brightness)
    	Gosub Transfer			' Transfer this 16-bit Word to the MAX7219
    
    	Register=Decode_Reg		' Point to BCD Decode Register
    	R_Val=%00001111	' Decode the first 8 digits
    	Gosub Transfer			' Transfer this 16-bit Word to the MAX7219
    
    	Register=Switch_Reg		' Point to the Switch Register 
    	R_Val=1				' Set to One, (switches the display ON)
    	Gosub Transfer			' Transfer this 16-bit Word to the MAX7219
    
    	Register=Test_Reg		' Point to the Test Register
    	R_Val=0				' Reset to Zero, (turns off Test mode)
    	Gosub Transfer			' Transfer this 16-bit Word to the MAX7219
    
    
    	Max_Dp=0			' Display number for Decimal Point
    
    REGISTER=8      'display some name
    R_VAL=124
    GOSUB TRANSFER
    REGISTER=7
    R_VAL=110
    GOSUB TRANSFER	
    REGISTER=6
    R_VAL=120
    GOSUB TRANSFER	
    REGISTER=5
    R_VAL=57
    GOSUB TRANSFER	
    
    
    
    TTK:
    
    pause 500	
    gosub gradus1
    max_disp=temperature
    GOSUB DISPLAY
    
    GOTO TTK
    
    GRADUS1:
    
    OWOUT DQD, 1, [$CC, $44] ' Start temperature conversion
    TRISD.1 = 0 'MAKE PIN AN OUTPUT WITH DEFAULT STATE HIGH
    pause 760 'ADD AN EXTRA 10 Ms.
    OWOUT DQD, 1, [$CC, $BE] ' Read the temperature
    OWIN DQD, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
    temperature = temperature */ 1600
    TEMPERATURE=TEMPERATURE/100
    
      
    return
    	
    Display:
    	Digit=0						' Start at Digit 0 of Max_Disp Variable
    	For Position=4 to 1 step -1			' Start at Farthest Right of Display 		
    	Register=5-Position				' Place Position into Register
    	R_Val=Max_Disp Dig Digit			' Extract the individual numbers from Max_Disp			
    	If Max_Disp<10 and Position=3 then R_Val=15	' Zero Suppression for the second digit
    	If Max_Disp<100 and Position=2 then R_Val=15	' Zero Suppression for the Third digit
    	If Max_Disp<1000 and Position=1 then R_Val=15	' Zero Suppression for the Forth digit
    	If Max_Disp<10000 and Position=0 then R_Val=15	' Zero Suppression for the Fifth digit
    	If Digit=Max_Dp then R_Val.7=1			' Place the decimal point, held in Max_DP
    	Gosub Transfer					' Transfer the 16-bit Word to the MAX7219
    	If Digit>=3 then Digit=0			' We only need the first four digits
    	Digit=Digit+1					' Point to next Digit within Max_Disp
    	Next Position					' Close the Loop
    	Return
    
    ' Send a 16-bit word to the MAX7219 
    Transfer:
      	Shiftout Dta,Clk,msbfirst,[Register,R_Val] ' Shift Out the Register first, then the data
    	High Load				' The data is now acted upon
    	PAUSEUS 100
    @	Nop
    @	Nop					' A small delay to ensure correct clocking times
    	Low Load				' Disable the MAX7219 
    	Return					' Exit from Subroutine

  8. #8
    Join Date
    Oct 2009
    Posts
    596

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Have you tried a different sensor. It could be that the current sensor is faulty as the code looks to be correct.
    What's the cable length between the chip and the sensor. I have 18B20's in a project, one of which is at the end of a 6m cable and that reads fine with 4.7K pull up.

  9. #9
    Join Date
    Feb 2013
    Posts
    497

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Yes tried another one, same "85". There is no cables, sensor directly hooked on breadboard.

  10. #10
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,179

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    CuriousOne, How many times are you letting the program cycle? Here is the output from my terminal after I reset the processor power. Notice the "85" as the first reading from the DS18B20-PAR. This behavior is normal after power up.

    +85.0C +185.0F
    +21.1C +70.1F
    +21.2C +70.2F
    +21.2C +70.2F
    +21.2C +70.2F
    +21.2C +70.2F
    +21.2C +70.2F
    +21.2C +70.2F
    +21.2C +70.2F

    Also, is the pullup source voltage stable during operation? It sounds like the device is being reset between each reading.
    Dave Purola,
    N8NTA
    EN82fn

  11. #11
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,179

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Try this routine:

    OWOUT DQD, 1, [$CC, $44] ' Start temperature conversion
    LATD.1=1 SET PIN STATE TO HIGH
    TRISD.1 = 0 'MAKE PIN AN OUTPUT WITH DEFAULT STATE HIGH
    pause 760 'ADD AN EXTRA 10 Ms.
    OWOUT DQD, 1, [$CC, $BE] ' Read the temperature
    OWIN DQD, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
    temperature = temperature */ 1600
    TEMPERATURE=TEMPERATURE/100
    Dave Purola,
    N8NTA
    EN82fn

  12. #12
    Join Date
    Feb 2013
    Posts
    497

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Excellent!
    now it works!

    so it was latd/trisd issue as I guess...

  13. #13
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,179

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Yes, the LATD.1 = 1 has to be set as there is no telling what state it was left in after the preceding OWOUT command.
    Dave Purola,
    N8NTA
    EN82fn

  14. #14
    Join Date
    Feb 2013
    Posts
    497

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Tried to adapt code for 16F886. As expected, it does not works returns steady 0.

    Code:
    ;----[16F886 Hardware Configuration]--------------------------------------------
    #CONFIG
    cfg1 = _INTRC_OSC_NOCLKOUT    ; INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN
    cfg1&= _WDT_ON                ; WDT enabled
    cfg1&= _PWRTE_OFF             ; PWRT disabled
    cfg1&= _MCLRE_OFF             ; RE3/MCLR pin function is digital input, MCLR internally tied to VDD
    cfg1&= _CP_OFF                ; Program memory code protection is disabled
    cfg1&= _CPD_OFF               ; Data memory code protection is disabled
    cfg1&= _BOR_OFF               ; BOR disabled
    cfg1&= _IESO_ON               ; Internal/External Switchover mode is enabled
    cfg1&= _FCMEN_ON              ; Fail-Safe Clock Monitor is enabled
    cfg1&= _LVP_OFF               ; RB3 pin has digital I/O, HV on MCLR must be used for programming
    cfg1&= _DEBUG_OFF             ; In-Circuit Debugger disabled, RB6/ICSPCLK and RB7/ICSPDAT are general purpose I/O pins
      __CONFIG _CONFIG1, cfg1
    
    cfg2 = _BOR40V                ; Brown-out Reset set to 4.0V
    cfg2&= _WRT_OFF               ; Write protection off
      __CONFIG _CONFIG2, cfg2
    
    #ENDCONFIG
    include "modedefs.bas"
    TRISA=%00000000  'SET A TO OUTPUT
    TRISB=%01000010
    ANSEL=%00000000  'SET AD TO DIGITAL
    OSCCON=%01100111  'SET FREQUENCY TO 4MHZ
    'CM1CON0=0         'DISABLE COMPARATORS
    'CM2CON0=0         'SAME HERE
    
    DEFINE OSC 4
    ' Set LCD Data port 
    DEFINE LCD_DREG PORTA  
    ' Set starting Data bit (0 or 4) if 4-bit bus 
    DEFINE LCD_DBIT 0  
    ' Set LCD Register Select port 
    DEFINE LCD_RSREG PORTA  
    ' Set LCD Register Select bit 
    DEFINE LCD_RSBIT 4  
    ' Set LCD Enable port 
    DEFINE LCD_EREG PORTB  
    ' Set LCD Enable bit  
    DEFINE LCD_EBIT 3  
    ' Set LCD bus size (4 or 8 bits) 
    DEFINE LCD_BITS 4  
    ' Set number of lines on LCD  
    DEFINE LCD_LINES 2  
    ' Set command delay time in us 
    DEFINE LCD_COMMANDUS 1500  
    ' Set data delay time in us 
    DEFINE LCD_DATAUS 44
    
    i var word
    DQD var PORTB.1
    temperature var word
    
    fucha:
    OWOUT DQD, 1, [$CC, $44] ' Start temperature conversion
    high portb.1 ''SET PIN STATE TO HIGH
    TRISB.1 = 0 'MAKE PIN AN OUTPUT WITH DEFAULT STATE HIGH
    pause 760 'ADD AN EXTRA 10 Ms.
    OWOUT DQD, 1, [$CC, $BE] ' Read the temperature
    OWIN DQD, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
    temperature = temperature */ 1600
    lcdout $FE,$C0, #temperature
    goto fucha

  15. #15
    Join Date
    Oct 2009
    Posts
    596

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    85 or 127 normally indicates a failed read of the device - often due to hardware. Do you have 4k7 pull up resistor on the DQ line ? Are the 5v and Gnd rails connected?

  16. #16
    Join Date
    Mar 2016
    Posts
    62

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    I tested your code on 16F688, and it works just fine with internal OSC set to 8MHz instead 4MHz.
    With OSC set at 4MHz the result is steady 85.
    Try it at 8MHz.
    Last edited by louislouis; - 7th April 2019 at 13:51. Reason: completing

  17. #17
    Join Date
    Feb 2013
    Posts
    497

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    On 886 I'm only getting 0, not 85 or 127, so I guess maybe chip is faulty. I've checked with multimeter, I see some pulses going on the pin. Tried to adjust resistor from 4.7k to 5.6k - no luck. Will try with another 18b20p tomorrow.

  18. #18
    Join Date
    Mar 2016
    Posts
    62

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Try 8MHz internal OSC.

  19. #19
    Join Date
    Feb 2013
    Posts
    497

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Tried, no change:

    This is correct I guess: OSCCON=%01110101

  20. #20
    Join Date
    Feb 2013
    Posts
    497

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Got it working!

    Moved to PortC.4

    Now have to find why it does not worked with PortB.1, maybe due to wpua ?

  21. #21
    Join Date
    Mar 2016
    Posts
    62

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Correct.

    And what if connect the DS18B20 with 3 wires? Does the reading correct value?

  22. #22
    Join Date
    Feb 2013
    Posts
    497

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Set WPUB=0 Still no change. No matter which PortB port I try. Will keep investigating

  23. #23
    Join Date
    Feb 2013
    Posts
    497

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    I do not have DS18B20, only DS18B20PAR, which supports only 2 wire connection mode, so can't test.

  24. #24
    Join Date
    Feb 2013
    Posts
    497

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Figured out, it was ANSELH register. Disabled it and now it works on portb also!

    Thanks everyone for help.

  25. #25
    Join Date
    Sep 2009
    Posts
    753

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    I don't know why people have so much trouble setting port.
    I always first set ANCON(ANSEL, etc), then TRIS, then optionally set port state (PORT or LAT register).

  26. #26
    Join Date
    Feb 2013
    Posts
    497

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    It would be great if MeConfig had options for that, but I guess, no one will implement...…

  27. #27
    Join Date
    Sep 2009
    Posts
    753

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    I guess it too much work, just count supported PIC. And it doesn't require more then 5min of reading datasheet.
    So probably they cannot justify investment.
    Also MCC(or what ever is called) have more then just pin configurator. And code to convert from C to PBP require only to remove ; and replace 0x with $.

  28. #28
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,245

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    MeConfig is abandonware.
    Charles wrote in a post somewhere that it was all Darrels project and since he passed away it won't be maintained.

    I know Darrel was a Delphi guy so I suspect it was written in Delphi of some flavour, perhaps someone is willing to take it on if Charles would releas the source (if he even has it).

  29. #29
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,891

    Default Re: It is Y2K19 but DS18B20PAR+ Returns either 127 or 85 depending on resistor value.

    Since there is MCC I see no point...

    Ioannis

Similar Threads

  1. Replies: 5
    Last Post: - 17th May 2012, 10:14
  2. DS1307 returns incorrect data ???
    By gtvmarty in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 8th October 2009, 09:54
  3. 16F819 ADC 8bit=127, Not 255?Help!
    By Accelerator in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 24th June 2006, 17:34
  4. Replies: 5
    Last Post: - 20th March 2006, 01:34
  5. Program returns to beginning at interupt
    By BGreen in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 25th April 2005, 11:20

Members who have read this thread : 21

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