ds18s20 reads incorectly


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi, Cleaver

    I suppose you work on an easyPic 4 or 5 ...

    try this with sensor connected to PORTE2 and Pullup on porta.0 and 1.

    After power on, type of sensor and ID is displayed.

    press RA0 Button ( active low ! ) and you turn to thermo mode ( thermostat, in fact , see RA0 and RA.1 use ... )

    Alain

    PS : Fully PbP Written Program...
    Attached Files Attached Files
    Last edited by Acetronics2; - 23rd July 2008 at 21:03.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  2. #2
    Join Date
    May 2008
    Location
    Florida
    Posts
    64


    Did you find this post helpful? Yes | No

    Default

    jcleaver

    Here is a couple of files for you to play with.

    pbptc.txt is your program that correctly displays the temp C and changes when the temp changes. You will need to change the LCD port, I use an easypic5 and you are using a different port.

    I also have a program for MikroB attached, again it is for the ep5 board.

    Take a few minutes and look at how the temp is being read in both. Once you figure that out you will see where the problem is.

    BTW the formula is from the DS18S20 datasheet.





    In your Mikro file did you notice that the temp was calculated before it is converted?

    if j2 = $FF then
    tmp_sign = "-" ' temperature sign
    j1= j1 or $FF ' complement of two
    j1= j1 + $01
    else
    tmp_sign = "+"
    end if
    j2 = (j1 and $01) * 5 ' Get decimal value
    j1 = j1 >> 1 ' Get temp value
    j1 = ((j1*9/5)+32) 'Convert C to F

    And in your PBP file nothing is calculated until after the conversion.

    TEMP = ((TEMP*9/5)+32 )
    Lcdout $fe, 1, dec (temp >> 1),".",dec(temp.0 * 5)," degrees C"

    Good Luck!

    Acetronics: May I play around with the thermostat program you posted?
    Attached Files Attached Files
    Last edited by manwolf; - 23rd July 2008 at 23:18. Reason: Brain Bubble

  3. #3


    Did you find this post helpful? Yes | No

    Default Thanks

    Want To Thank All Of You For Your Help Been Great To Work With
    Will Keep You Updated

    Also Would Like To Look At The Pb Code For The Thermostat Program

    If Not Giving Away Something

    Again Thanks

    Jack

  4. #4


    Did you find this post helpful? Yes | No

    Exclamation Interesting

    Manwolf
    Worked With Your Pbp And Your Right It Is Displaying The Correct C Temperature

    Its Pb Math Thats Incorect

    Any Ideas How ?

    Also The Formula Temp = ((temp*1.8)+32) Gives Corect Answer But Wont Compile
    On Pbp

  5. #5
    Join Date
    May 2008
    Location
    Florida
    Posts
    64


    Did you find this post helpful? Yes | No

    Post

    Jack

    As Acetronics stated:

    Remember PBP works with UNSIGNED INTEGERS ...

    So 9/5 = 1.8 still won't fly in PBP

    How about something like this?

    temp = (((temp >> 1) * 100) - 25) 'calculate degrees C

    temp = (temp */ 461) + 3200 'convert degrees C to F

    And before you ask, crack open the ugly green book and figure out what '*/' does.

    Hint: it uses all unsigned integers.

    The hardest part of writing any program is learning how to handle the math. If you can not get your head around the math none of this stuff makes any sense.

    Don't be afraid to throw some output in there to see what is happening. Run Debug, output to LCD or a serial port to see what it is changing.


    For a better explaination of the math go here - http://www.rentron.com/PicBasic/one-wire3.htm

    Ted
    Last edited by manwolf; - 24th July 2008 at 04:26. Reason: Forgot to answer the question

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


    Did you find this post helpful? Yes | No

    Wink

    Hi, Manwolf

    What do you mean by that :

    " Acetronics: May I play around with the thermostat program you posted? "

    Of course YOU can play with it ...

    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,405


    Did you find this post helpful? Yes | No

    Default

    Your bit-banged read & write routines use a @ NOP for a 1uS delay, but you're running
    at 20MHz so these are only 200nS. You would need 5 x @ NOP for a 1uS delay.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. DS18B20 VS DS18S20 & multiple
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 7th February 2008, 22:43
  2. Using A Ds18s20 And Servo
    By CrazyCooter in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th September 2007, 09:41
  3. DS18S20 displays wrong temperatures
    By Shozo Kanamori in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th August 2007, 03:18
  4. DS18s20 - negative teperature
    By Ceug2005 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd February 2005, 12:40
  5. 16F877, DS18S20 and Serial Comm Problem
    By YellowTang in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th April 2004, 10:36

Members who have read this thread : 0

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