Please help with code for DS18B20


Closed Thread
Page 1 of 3 123 LastLast
Results 1 to 40 of 110
  1. #1
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579

    Default Please help with code for DS18B20

    I made the great project of "Digital thermostat (080090-11)" from Elektor july_august 2008 ; unfortunate I do not have DS1820 but DS18B20. The temperature show on display is like "xxx.xx 'C" !.
    I read this : "In order to convert the HEX code to a temperature value, first you need to identify if you are using a DS18S20, or DS18B20 series sensor. The code to read the temperature needs to be slightly different for the DS18B20 (and DS1822), because it returns a 12-bit temperature value (0.0625 deg precision), while the DS18S20 and DS1820 return 9-bit values (0.5 deg precision)".
    I try millions different routines, but the result is verry bad...because of this section, I think :
    "DisplayTemp:
    If V >= 10000 then ' Above 0 C.
    Temperature=V-10000
    Else
    Temperature=10000-V ' Below 0 C.
    EndIf
    LcdOut $FE, $C0, Sign, DEC (Temperature / 100), ".", DEC2 Temperature, " ",223,"C "
    Return"
    All the codes I try change the Temperature set and Hysteresis, and the display show the temperature (ex. 24.56'C) , but useless function of thermostat...(Set temperature = 2000.00 and Hysteresis = 200.00).
    And the temperature is different (+24.67 'C) by other device (DS18B20 + PIC 12F675 + LCD Nokia = 23.1'C ; LM35DZ + mV = 23.1 'C)
    It is possible to increase the accuracy of this thermometer/thermostat ?
    Can somebody help me to modify the source for using DS18B20 ?
    Thanks in advance !
    Attached Files Attached Files
    Last edited by fratello; - 30th December 2008 at 11:00.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi, Fratello

    I played a bit with your program ... Elektor won't be anymore what it was ... -cries-

    Note you'll have to comment the Easypic5/16F877A section and uncomment the Elektor section.

    This way you will be able to use the 18B20 in any resolution you like ...

    And OVERALL do not ask a +/- 0.5°C precision sensor to give 1/100° C .... !!!

    Alain
    Attached Files Attached Files
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    THANK YOU VERRY MUCH !!!! You make me happy ! I will try the code and I will keep You informed. Thanks again !
    ****** A HAPPY NEW YEAR !!!! ******
    ******* TO ALL !!!! *******
    LE : Now is great, even still remain the 1°C difference...but "OVERALL do not ask a +/- 0.5°C precision sensor to give 1/100° C .... !!!".
    Thanks again !
    B.t.w : what can I use instead of DS18B20 for more accurate measurement ?
    Last edited by fratello; - 30th December 2008 at 18:45.

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Talking The Horrible truth ...

    Quote Originally Posted by fratello View Post
    B.t.w : what can I use instead of DS18B20 for more accurate measurement ?
    Hi, Fratello

    I had a look to all the sensors you can find on the market ...

    The best "out of the box" accuracy ( all including ) will be roughly +/- 0.5 °C ... don't be sad !!!

    going further needs multipoint CALIBRATION ... with some really expensive devices.

    Note linearity is "not so bad" in our measuring range ... so, with a two points calibration ( 0 and 100°C ) , you can reach +/- 0.1 °C without too much pain.

    And remember ... DS18x20 in continuous measurement mode like here, without being fixed on a heatsink, has a 1°C self heating value ... ( a look at the Datasheet will confirm !!! )

    Just have a look to the values displayed from the power up ...

    Alain
    Last edited by Acetronics2; - 31st December 2008 at 09:58.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    You missed some Alain.

    We have Industrial Sensors that directly return 16-bit Temperature to two Decimal Places (in the range 0.00C-100.00C).

    It is however a complete waste of time... just breathing in the vicinity, or even just walking nearby create air-currents which wildly change the readings - we just end up ignoring the last digit. If you're trying to distill some moonshine for the New Year festivities, you're not really bothered in monitoring the temperature to hundredths of a degree.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi, Mel

    Happy to read from you !!!

    Of course, those sensors exist ... ( you have forgotten to give us the price ... lol ), but are totally out of our Hobbiysts galaxy ...

    Have a Happy new Year

    Regards
    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Happy New Year to you and everyone too...

    Aa a rough guide about 25 Euro's in singles, falling to below about 18 Euro's at 100 pcs, and about 10 Euro's at 1000 pcs.

    Yes of course, you can't beat the few cents a DS1820 costs, but then it's not a bare chip, but a fully enclosed product with attached leads and connectors, post sensor processor, integral noise immunity, etc etc with integral seals all ready to bolt straight into your pipework or manifold.

    If you want cheap, then just use an NTC Thermistor and plot it's curve into a PIC. You can easilly get better than 0.1C accuracy through simple interpolation across 90% of the curve. It's the way it's done in 99.9% of the cheaper Industrial and domestic Controls. I really don't see the point of DS1820's, LM35's etc, they're a waste of money for something that can be done so much simpler if only folks stopped and thought about the problem. OK, if you've only got a single I/O and a dozen items on the interconnecting bus, then fine, but otherwise why?

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Ok, Mel

    You're talking resolution while I'm talking accuracy ...

    DS already give .0625°C resolution ... but that do not mean anything because you only know you are inside the +/- 0.5 °C error gap.
    LM 335 have your ADC resolution ... but always an "out of the box" +/- 0.5 °C precision

    That is why I say ( and repeat ... ) you can't get a better reading WITHOUT a calibration ... or comparison with a known reference.

    Even the MS5534 ( 16 bits! ) which comes with its calibration coeffs ... is given for a GUARANTEED +/- .8°C accuracy ...

    For NTC's the problem is the +/- 5 to 20% value tolerance ... that need an individual curve adjustment to each sensor ( only 1 point ... yes... but one point calibration ! )


    The only **predictable** High accuracy sensors are Platinium RTD's ... But , ... How much to pay for a class A probe ??? ...

    Temp and Thermal measurements are always funny ... and make you humble !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  9. #9
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    Thank you for replays !!!
    I wish to all a happy NEW YEAR 2009 !

    I think I go crazzy with this little thermostat probleme ; I write ( based on Yours great codes) four routines ; everyone display a different temperature. Which of them is -in yours opinion - the best ?

    1.OWOut DQ, 1, [$CC, $BE]
    OWIn DQ, 2, [Temperature.Lowbyte, Temperature.Highbyte]
    Convert_Temp:
    Dummy = 625 * Temperature
    TempC = DIV32 10
    TempC = (Temperature & $7FF) >> 4
    Float = ((Temperature.Lowbyte & $0F ) * 25 )>>2
    Temperature = TempC*100 + Float

    2.OWOut DQ, 1, [$CC, $BE]
    OWIn DQ, 2, [RAWTEMP.Lowbyte, RAWTEMP.Highbyte]
    Convert_Temp:
    dummy = RAWTEMP * 625
    TempC = DIV32 100
    Temperature = TempC

    3.OWOut DQ, 1, [$CC, $BE]
    OWIn DQ, 2, [Temperature.Lowbyte, Temperature.Highbyte]
    Convert_Temp:
    TempC = (Temperature & $7FF) >> 4
    Float = ((Temperature.Lowbyte & $0F ) * 25 )>>2
    Temperature = TempC*100 + Float

    4.OWOut DQ, 1, [$CC, $BE]
    OWIn DQ, 0, [Temperature.LowByte, Temperature.HighByte, Skip 4, Count_Remain, Count_Per_C]
    Convert_Temp :
    Temperature = (((Temperature >> 1) * 100) - 25) + (((Count_Per_C - Count_Remain) * 100) / Count_Per_C)
    if Temperature > 32767 then '32767 check if BIT12=1
    Temperature= ~Temperature
    temperature=temperature>>3 ; divide by 8

    Thanks in advance for your support ; I hope I don't became boring !!!!

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi, Fratello

    Too wide a question ... It's on your own now.

    Here it's yours to take :

    1) your Datasheets, and do not mix different sensors ( ! ), see how values are coded for each.

    2) your PbP Manual, and look at how PbP can calculate and see where roundings can lead to ( small ...) outputted value differences.

    ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  11. #11
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    I use the same sensor, the same circuit, just I re-write the code...the results are never the same...

  12. #12
    Gabestarting's Avatar
    Gabestarting Guest


    Did you find this post helpful? Yes | No

    Unhappy

    I intend to start tomorrow with the same project, using the same sensor DS18S20. May i use it without changing the code?

  13. #13
    Gabestarting's Avatar
    Gabestarting Guest


    Did you find this post helpful? Yes | No

    Default

    Sorry, reading the text again i observed that i have the right sensor, i was lucky...So, the thermostat works fine, i am happy for the bas-file, however it is easier to understand than assembler. I made the circuit on a stripboard. Have a nice evening!

  14. #14
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    I want now to try to read the temperature with two sensors DS18B20 ; one for IN and other for OUT. It is possible ? How can I display both temperatures ?
    Help, please !

  15. #15
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Hi, Fratello

    some homework to do for you ...

    take the DS18B20 Datasheet out, and look at :

    1) How to get the device ID
    2) How to address the device with it's ID

    Buuuuuut, I do think ALL the answers you look for already are posted on this Maaarrrrrvellous Forum !!!

    It's called SEARCH Function ...

    Alain

    PS: HELP Function momentarily out of use : New Year update ... lol
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  16. #16
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    I try to read the serial number of my DS18B20 sensor with this code :

    TRISA= %11110000 ' RA0..3=Outputs RA4=Input
    TRISB= %00000111 ' RB0..RB2=Inputs, RB3..RB7=Outputs
    CMCON=7 ' Disable comparators

    DEFINE LCD_DREG PORTB ' LCD on port B
    DEFINE LCD_DBIT 4 ' Data bits B4..B7
    DEFINE LCD_RSREG PORTA ' RS on PORTA
    DEFINE LCD_RSBIT 1 ' RS on A1
    DEFINE LCD_EREG PORTA ' E on PORTA
    DEFINE LCD_EBIT 0 ' E on A0
    DEFINE LCD_BITS 4 ' LCD 4 bit mode
    DEFINE LCD_LINES 2 ' 2 line LCD display

    DQ Var PORTA.4 ' One-wire data pin
    i Var Byte
    Temp Var Byte
    ReadRom Con $33

    Pause 500
    LCDOUT $FE, 1, $FE, $0C ' Clear display, cursor off
    Pause 250

    Main

    OWOut DQ, 1, [ReadRom]
    for i = 0 to 7
    OWIn DQ, 0, [Temp]
    LcdOut $FE, $80, Hex Temp
    Next
    LcdOut $FE, $14
    LcdOut $FE, $14
    Pause 1000
    GoTo Main


    but on display appears only "A7". What I do wrong ? Thanks !

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    LcdOut $FE, $80, Hex Temp
    The $80 moves the cursor to Line1 Column1, and it overwrites the previous values on each loop. All you see is the last loop.
    <br>
    DT

  18. #18
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    Per aspera ad astra !!!!
    I write another code :

    DQ Var PORTA.4 ' One-wire data pin
    i Var Byte
    Temp Var Byte
    ReadRom Con $33
    ID VAR BYTE[8] ' Array storage variable for 64-bit ROM code


    Begin:
    PAUSE 500 ' Wait .5 second
    LCDOUT $FE, 1, $FE, $0C ' Clear display, cursor off

    Start_Convert
    OWOUT DQ, 1, [$33] ' Issue Read ROM command

    ID_Loop:
    OWIN DQ, 0, [STR ID\8]' Read 64-bit device data into the 8-byte array "ID"
    for i = 0 to 7
    LcdOut HEX ID[i]
    next i
    END



    Now I have on display : 28CAC648100A7
    I think now it is correct. Can You confirm ? Thanks !

  19. #19
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi, Fratello

    Looks fine

    my DS shows 7A00000190DF64

    read you soon

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Almost, but there's not enough digits.

    64-bits (8-bytes), will have 16 hex digits.

    Try it this way ...
    Code:
    LcdOut HEX2 ID[i]
    DT

  21. #21
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    Thank you all for reply !
    In this book : "PIC Microcontrollers: Know It All" from Lucio Di Jasio, Tim Wilmshurst, Dogan Ibrahim, John Morton, Martin Bates, Jack Smith, D.W. Smith, and Chuck Hellebuyck - witch is my inspiration , I read this :
    "Dallas Semiconductor’s 1-wire specifications define device serial numbers as 8 bytes (64 bits) long.The family code for 18B20 digital thermometer chips is $28. The CRC (cyclic redundancy code) is an error-checking feature, so that, should we desire, we may verify that the 56 bits of the family code and serial number have been correctly received and were not corrupted. We’ll not further consider how CRCs are calculated, as it’s a topic well beyond the level of this introductory book.
    When we run the program, we see the following output:
    28 4C D4 3E 0 0 0 D6
    ...
    The digits 4C D4 3E 0 0 0 D6 are, of course, dependent upon the particular DS18B20 chip.
    I plugged in a second DS18B20 chip and found its serial number:
    28 FE DA 3E 0 0 0 C1
    In the output, $28 is the family number and $D6 (or $C1 in the second example) is the CRC. The center six bytes represent the serial number of the chip. But, here’s a difference between the result and the serial number specification isn’t there? The definition has the CRC sent first and the family code sent last. Yet, Program 22.1 displays the family code first, and the CRC last.The explanation is that 1-wire devices store the least significant byte at the lower address and
    the most significant byte at the higher address. Bytes are transmitted and received from lowest address to highest address. Hence, the net effect is the send/receive byte order is reversed from the data sheet description. This is more confusing to describe than to use; when we wish to address a particular device, we just repeat the byte order we read with Program 22.1"

    So, I think it is enough for me these results.
    Next step is : Reading multiple sensors on the same bus.
    ... Wish me luck !
    I will keep you informed and - hope- I will receive yours advices again.
    All the best !
    Last edited by fratello; - 10th January 2009 at 11:26.

  22. #22
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi, Fratello

    From the Datasheet Organigrams ... you'll see the Bytes Order is inverted ...

    as you worked Well ...

    Code:
    '*****************************************************************************
    SensID:' Sensor Identification
    '*****************************************************************************
    
      OWOUT DQ, 1, [ $33 ]								' Read Chip code
      OWIN  DQ, 2, [ FAM,ID[6],ID[5],ID[4],ID[3],ID[2],ID[1],CRC]
      
      IF FAM = $05 THEN
      
       	LCDOUT $FE,$80, "DS 2405     "
       	
      	PAUSE 1000
      	
      	LCDOUT $FE,$80, 				" CRC: ",HEX2 CRC," FAM: ", HEX2 FAM
      	
      ENDIF
      
      IF FAM = $10 THEN
      
      	LCDOUT $FE,$80, "DS 18S20/1820"
      	
      	PAUSE 1000
      	
      	LCDOUT $FE,$80, 				" CRC: ",HEX2 CRC," FAM: ", HEX2 FAM
      	
      ENDIF
      	  	
      IF FAM = $28 THEN
      
       	LCDOUT $FE,$80, 				"DS 18B20     " 
       	
     	OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_11bit]    'Skip ROM search and write N_bits
      	'                                                 resolution to scratch pad
      	PAUSE 1000
      	
      	LCDOUT $FE,$80, 				" CRC: ",HEX2 CRC," FAM: ", HEX2 FAM
      	
      ENDIF
      
      	LCDOUT $FE,$C0," ID:",HEX2 ID[1],HEX2 ID[2],HEX2 ID[3],HEX2 ID[4],HEX2 ID[5],HEX2 ID[6]
    Here Data are shown with their signification ... Hope it will help

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  23. #23
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    Thanks for support !!!!
    First code (post #18) return this result : 28 CA C6 48 1 0 0 A7
    Second code (post # 22) return : CA C6 48 01 00 00


    In the code that I write now I use something like this :
    "Init1
    OWOut DQ, 1, [$55, $28, $FE, $DA, $3E, $0, $0, $C1, $4E, $FF, $FF, $7F]
    OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $48]
    OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $B8]
    OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $BE]
    Pause 1000
    OWOut DQ, 0, [Temperature.Byte0, Temperature.Byte1, 0, 0, DS18B20_12bit]


    Init2
    OWOut DQ, 1, [$55, $28, $FE, $DA, $3E, $0, $0, $C1, $4E, $FF, $FF, $7F] 'SENSOR 2 !!!!!!!!! not reading yet !!!!
    OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $48] 'SENSOR 2 !!!!!!!!! not reading yet !!!!
    OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $B8] 'SENSOR 2 !!!!!!!!!
    OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $BE] 'SENSOR 2 !!!!!!!!!
    Pause 1000
    OWOut DQ, 0, [Temperature.Byte0, Temperature.Byte1, 0, 0, DS18B20_12bit]


    Main
    OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $44] ' Start temperature conversion Sensor 1

    WaitLoop:
    While not DQ
    Wend

    OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $BE]
    OWIn DQ, 0, [Temperature.Byte0, Temperature.Byte1]
    GoSub Convert_Temp
    GoSub DisplayTemp

    Part2
    OWOut DQ, 1, [$55, $28, $CA, $C6, $48, $1, $0, $0, $A7, $44] ' Start temperature conversion Sensor 2

    WaitLoop2:
    While not DQ
    Wend"



    I hope it's good...will see !
    Last edited by fratello; - 10th January 2009 at 21:40.

  24. #24
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    Hello !
    Me again ......I write the code attached, but the temperature on display don't modify (IN = 91.25 'C ; OUT = 25.18 'C)... Know somebody where is the mistake ? Thanks in advance...
    Attached Files Attached Files
    Last edited by fratello; - 12th January 2009 at 11:23.

  25. #25
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    I found the mistakes ! I re-re-re...-write te code. Now works fine !
    I did it !! I am verry happy ! I take a little pause -just a few hours- and I will try to adapt this code to the old code of thermostat, for having both function : dual termometre and thermostat. I will keep you informed ! All the best !

    I know the accuracy is +/- 0.5 'C , but it is normal this ? One sensor show 25.21 'C and the other 26.18 'C... I put the sensors together, and I fix them with one earring, this is the temperatures after 15 min... Maybe i's something wrong in my code ?!
    Attached Files Attached Files
    Last edited by fratello; - 12th January 2009 at 14:01. Reason: later edit :

  26. #26
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    Hope I am not boring with this subject !
    1. I replace one sensor and now both temperatures are similar.
    2.I write the code for dual thermometer and thermostat ; works verry good !
    If somebody have idea to improve this code, please post here !
    I wish you all the best !
    Attached Files Attached Files

  27. #27
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Hi, Fratello

    What about a nice Bargraph to show what's going on ... ???

    like this one :

    Code:
    '*****************************************************************************
    '*****************************************************************************
    '                              AFFICHAGE
    '*****************************************************************************
    '*****************************************************************************
    
    'Motifs CGRAM
    
          LCDOUT  $FE,$40,$00,$00,$00,$00,$00,$04,$04,$04  ' Cust Char $0 'Small bar
          LCDOUT  $FE,$48,$00,$00,$00,$04,$04,$04,$04,$04  ' Cust Char $1 'Mid bar
          LCDOUT  $FE,$50,$04,$04,$04,$04,$04,$04,$04,$04  ' Cust Char $2 'Big bar 
          LCDOUT  $FE,$58,$04,$04,$0E,$0E,$0E,$1F,$1B,$11  ' Cust Char $3 'Arrow
          LCDOUT  $FE,$60,$11,$1B,$1F,$0E,$0E,$0E,$04,$04  ' Cust Char $4 'Inv Arrow     
          LCDOUT  $FE,$68,$04,$04,$0E,$1F,$1F,$0E,$04,$04  ' Cust Char $5 'Diamond
    
    '*****************************************************************************
    Aff:'Affichage temp
    '*****************************************************************************
    
    'préparation chiffre : sign = 1 = valeur négative
    
    Decal	= ( TempC // 5 ) << 1 
    
    IF NOT sign THEN
    
    	Loscale = ( TempC /5 ) * 5 
    	Hiscale = (( TempC /5 ) + 1) * 5
    	
    	IF Float > 25 AND Float <= 75 then Decal = Decal + 1
    	IF Float > 75 Then Decal = Decal + 2
    	
    ELSE
    
    	Loscale = (( TempC /5 + 1 ) * 5) * -1  
    	Hiscale = ((TempC /5) * 5 )* -1 
    	Decal = 10 - Decal
    	
    	IF Float > 25 AND Float <= 75 then Decal = Decal - 1
    	IF Float > 75 Then Decal = Decal - 2
    	
    		TempC = TempC * -1
    		
    ENDIF
    
    
    'Impression valeurs 1ère ligne
    
    IF Sign THEN
    
      LCDOUT	$FE, $80 ,SDEC2 Loscale,178,Unit," "
      IF TempC = 0 THEN LCDOUT "-" 
      LCDOUT SDEC TempC,".",dec2 Float
      IF ABS TempC < 10 then LCDOUT " "
      LCDOUT $FE,$80 + 11,SDEC2 Hiscale,178,Unit
      
    ELSE
      
      LCDOUT	$FE, $81 ,SDEC2 Loscale,178,Unit," ",SDEC TempC,".",dec2 Float
      IF TempC < 10 then LCDOUT " "
      LCDOUT $FE,$80 + 12,SDEC2 Hiscale,178,Unit 
      
    ENDIF 
      
      
    'Impression échelle 2ème ligne
    
     LCDOUT	$FE,$C0,$01,$00,$02,$00,$01,$00,$01,$00,$01,$00,$01,$00,$02,$00,$01,$00
      
    'Impression index
    
     IF Tempeff < ( Setpoint - 5 ) THEN
     
    	LCDOUT	$FE, $C2 + Decal,$03				'Index Chauffage
    	
     ELSE
     
     	IF Tempeff > ( Setpoint + 5 ) THEN
     	
    		LCDOUT	$FE, $C2 + Decal,$04				' Index Refroidissement
    	
    	ELSE
    	
    		LCDOUT	$FE, $C2 + Decal,$05				' Index Zone neutre
    		
    	ENDIF
    	
    ENDIF
    Better shown on attachment
    Attached Files Attached Files
    Last edited by Acetronics2; - 13th January 2009 at 12:38.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  28. #28
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    Thanks for reply !
    Sorry, but my LCD is 2 x 16 ; at first line I display "In" and at second "Out" values of temperatures. Otherwise, nice code are You writing .

  29. #29
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    New problem :
    -the thermometer PIC 12F675 + DS18B20 + Nokia LCD = 24.5 'C
    -the thermometer LM 35DZ + Fluke 830DM = 24.5 'C
    -the thermometer PIC 16F628A + DS18B20 = 25.5 ' C !!!!!!!!!!!

    I try to write in PIC the same code of themperature conversion like Mr.Novakovic Ivica.
    Check for similarity !!!! Why this diference ? I thing I go crazy, soon ....
    Attached Files Attached Files

  30. #30
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    Code:
    count_remain, count_per_c
    DO NOT use that with DS 18B20 ....

    That's a first step.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  31. #31
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    Anything code I write in thermo that I made, the temperatures are NOT similar with those measured with other devices (mentioned). I try to change the sensor (I use three !) but nothing change. I don't know what to believe : which of temperature is - more- accurate ?

  32. #32
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    I found this on forum :
    "OSCCON = %01100000 'Internal clock set to 4-MHz (MUST DO THIS!!!)"
    I added in my code, but PBP say "Error : Undefined Symbol 'OSCCON'.
    Maybe this is the error that shows different temperatures ?

  33. #33
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Have you checked your PICs DATASHEET to see if it has an OSCCON register?

  34. #34
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    My mistake...mea culpa...

  35. #35
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    Based on the book mentioned at post #21, I re-write the code for this project. I implement a new procedure for initializing the sensors. The results are verry good. Want somebody to improve this ? I wish You all the best !
    Thanks again for Your support !
    Attached Files Attached Files

  36. #36
    Join Date
    Mar 2006
    Location
    Hyderabad (India)
    Posts
    123


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Fratello

    I played a bit with your program ... Elektor won't be anymore what it was ... -cries-

    Note you'll have to comment the Easypic5/16F877A section and uncomment the Elektor section.

    This way you will be able to use the 18B20 in any resolution you like ...

    And OVERALL do not ask a +/- 0.5°C precision sensor to give 1/100° C .... !!!

    Alain
    But DS18B20 is capable of giving a better resolution??
    Regards,
    Sarma

  37. #37
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default

    Its resolution (its step in other words) is 0.0625 but its accuracy is +/-0.5C

    Ioannis

  38. #38
    Join Date
    Mar 2006
    Location
    Hyderabad (India)
    Posts
    123


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by fratello View Post
    Based on the book mentioned at post #21, I re-write the code for this project. I implement a new procedure for initializing the sensors. The results are verry good. Want somebody to improve this ? I wish You all the best !
    Thanks again for Your support !
    @Fratello,
    is your latest software working in the range 0 to 100 deg Celsius at least?
    When I tried for that and with one sensor, it shows -0.06 Celsius. and the sensor would not respond for variation
    We have presently temperatures around 33.5 Celsius, as we entered summer season in India.
    Last edited by mvs_sarma; - 3rd April 2009 at 17:17.
    Regards,
    Sarma

  39. #39
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default

    The code is ok ! Check the DS18B20 serials numbers ! I don't know if the thermostat work with just one sensor ! Good luck !

  40. #40
    Join Date
    Mar 2006
    Location
    Hyderabad (India)
    Posts
    123


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by fratello View Post
    The code is ok ! Check the DS18B20 serials numbers ! I don't know if the thermostat work with just one sensor ! Good luck !
    as long as a working project of elektor is modded by adding another sensor, it should work for a single sensor also. I have just disabled all lines pertaining to sensor2.
    I am asking for practical test result, not the program being OK as per our assumption, please. whether you are able to read temperature like normal room and and a piece of ice ? with one of the sensors, with other sensor reading just room temp?
    Regards,
    Sarma

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

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