ds18s20 reads incorectly


Results 1 to 40 of 43

Threaded View

  1. #30
    Join Date
    May 2008
    Location
    Florida
    Posts
    64


    Did you find this post helpful? Yes | No

    Default

    Jack

    The reason your PBP version did not work was because:

    You attempted to convert C to F using the RAW temp from the DS18S20.

    TEMP = ((TEMP*9/5)+32 )

    Then tried to calculate the temp from the results.

    Lcdout $fe, 1, dec (temp >> 1),".",dec(temp.0 * 5)," degrees C"

    For the fun of it lets plug some numbers in assume 27.5 C is the temp today.

    From the datasheet : The temperature sensor output has 9-bit resolution, which corresponds to 0.5°C steps.

    so 27.5*2 = 55

    Temp = (55*9/5) + 32 = 131
    So Temp now is equal to 131.

    Next we shift right 131>>1 same as temp/2 = 65.5

    Hmmm 65.535 does that number ring a bell?

    Wonder what would happen if you were to shift first then convert C to F like all of the other code posted does?

    temp = (temp>>1*9/5) +32 = (27.5*9/5)+32 = 81.5 F

    Hopefully this explains to you why it works in MikroBasic and not in PBP. The math is not broken, just the order of operation.

    That is why I said check math, simple change would fix it.

    Acetronic: I ask because you posted for jcleaver, would not take without asking first.
    Last edited by manwolf; - 24th July 2008 at 20:21.

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