Serin serout problem


Closed Thread
Results 1 to 40 of 337

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    putting the 2,s compliment just befire works best:
    but the temperature seems to cut in half,, showing -5C when it is -10C

    Just getting +655 when I get to zero degrees.

    Zerotemp: '------------- cases when zero celcius and positive Fahrenheit
    temp1 = temperature
    temperature = ((( temperature >>1 ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)

    if tempF <= 0 then goto ZeroF

    temperature = ( ~ temperature ) + 1 ': tempf = ( ~ tempF ) + 1 ' added this
    tempF = 3200 - ((temperature /5) * 9)

    ZeroF: '---------------- cases when zero celcius and 0 Fahrenheit
    tempF = 3200 - ((temperature /5) * 9)

    goto loop

    end
    Why are you using:tempF = 3200 - ((temperature /5) * 9)
    instead of tempF = ( ( ( temperature / 5 ) * 9 ) + 3200 ) ?

    The positive case (the only one that's working) uses the +3200, the negative cases are using the 3200-.....

    What's the deal there?

  2. #2
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    simple I need to take the difference. I believe pic basic pro can only handle unsigned numbers. So but keeking the original forula we get negative number for zero temperature. So by putting the 3200 in front , we get a positive number and add a minus sign.

    for -15 degrees celcius
    we have 15*100 =1500 in the euqation
    =3200 - (1500/5*9) = 500
    = 500/100 ------divide by hundred caus ewe multiplied by a 100 initially
    =5
    = -5 ----- here we just add the minus

    but anyway , remember when i said my decimal values was going reverse. I was thinking and that is similar from doing 2,s compliment . so i decided to do 2,s compliment on everything..

    Zerotemp: '------------- cases when zero celcius and positive Fahrenheit
    temperature = ( ~ temperature ) + 1
    count_per_c = ( ~ count_per_c) + 1
    count_remain= ( ~count_remain) + 1
    temp1 = temperature

    temperature = ((( temperature >>1 ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    if tempF <= 0 then goto ZeroF

    ': tempf = ( ~ tempF ) + 1 ' added this
    tempF = (((temperature /5) *9 ) + 3200)
    lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
    goto loop

    ZeroF: '---------------- cases when zero celcius and 0 Fahrenheit
    tempF = 3200 - ((temperature /5) * 9)

    lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"

    goto loop

    end
    Last edited by lerameur; - 30th December 2006 at 18:35.

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I thought that would work, but nope

    look at his thread, last couple of posts,
    seems like I am not the only one having his problem .
    Last edited by lerameur; - 30th December 2006 at 20:31.

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    simple I need to take the difference. I believe pic basic pro can only handle unsigned numbers. So but keeking the original forula we get negative number for zero temperature. So by putting the 3200 in front , we get a positive number and add a minus sign.

    for -15 degrees celcius
    we have 15*100 =1500 in the euqation
    =3200 - (1500/5*9) = 500
    = 500/100 ------divide by hundred caus ewe multiplied by a 100 initially
    =5
    = -5 ----- here we just add the minus

    but anyway , remember when i said my decimal values was going reverse. I was thinking and that is similar from doing 2,s compliment . so i decided to do 2,s compliment on everything..

    Zerotemp: '------------- cases when zero celcius and positive Fahrenheit
    temperature = ( ~ temperature ) + 1
    count_per_c = ( ~ count_per_c) + 1
    count_remain= ( ~count_remain) + 1
    temp1 = temperature

    temperature = ((( temperature >>1 ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    if tempF <= 0 then goto ZeroF

    ': tempf = ( ~ tempF ) + 1 ' added this
    tempF = (((temperature /5) *9 ) + 3200)
    lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
    goto loop

    ZeroF: '---------------- cases when zero celcius and 0 Fahrenheit
    tempF = 3200 - ((temperature /5) * 9)

    lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"

    goto loop

    end
    I'm thinking that the easiest way to solve this whole mess is to add an offset to the original C value.
    The 1820 will only handle temps up to +85C and has an operating range of -55 -> +125C. So, that's a total range of 180C. So, add, say 200 to the original Celsius input. You still have 3 cases to deal with (+C/F , -C/+F and -C/-F), but it might be easier to deal with this way... (and it will still work in the confines of a word value, 200 + 125 = 325 , 20000 + 12500 = 32500).

    At the receiving end,
    If C temp is => 200 (20000) , then subtract 200 (20000) and handle it like normal, which already works fine. +C and +F

    If the C temp is => 182.22 (18222) AND < 20000....handle it for -C and +F

    If the C temp is < 182.22 (18222).....handle it for -C and -F.

    In the last 2 cases when you have a negative temp, I think setting a display flag and converting the temp's to a positive range, then displaying them is the way to go (flip them back over the zero, i.e. -10 = 10 with a display flag), but you're already doing that (even though it isn't working at the moment).

  5. #5
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    thanks , I decided to take a short cut, I just realize that the equation they gave in the spec sheet is only good for positive Celsius degrees. I lokked how count_per_C and Count_Remain worked . I will try and come up with a formula for negative values with thse featuer, I will need to invert the Count remain, and flip the last two . .

    anyway here is the program that works, but with only 0.5 Degrees off in the negative region.
    BUT frpm 0 to -0.5 I stil get +655 C....



    loop:
    '23
    waitfor55:
    serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

    waitforaa:
    serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

    serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
    serin portb.2, n2400, encoded22.HighBYTE : serin portb.2, n2400, encoded22.LowBYTE
    serin portb.2, n2400, encoded33.HighBYTE : serin portb.2, n2400, encoded33.LowBYTE
    serin portb.2, n2400, encoded44.HighBYTE : serin portb.2, n2400, encoded44.LowBYTE

    For counter=0 TO 7 'decoding
    encoded1.0[counter]=encoded11.0[counter*2] : encoded2.0[counter]=encoded22.0[counter*2]
    encoded3.0[counter]=encoded33.0[counter*2] : encoded4.0[counter]=encoded44.0[counter*2]
    Next counter
    '41
    temperature= encoded1 ' putting back together as the original temperature
    For counter=0 TO 7
    temperature.0[counter+8]=encoded2.0[counter+8]
    Next counter

    temperature.LowBYTE = encoded1
    temperature.HighBYTE = encoded2
    count_remain = encoded3
    count_per_c = encoded4

    IF temperature.11 = 1 Then goto Zerotemp
    temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = (((temperature /5) *9 ) +3200)

    lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", "+", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
    goto loop

    Zerotemp: '------------- cases when zero celcius and positive Fahrenheit

    temperature = ( ~ temperature ) + 1

    if temperature.0 =0 then
    tempbit = 0
    else
    tempbit = 5 : tempf0 = ((temperature>>1) *10 )+5
    endif

    tempF = (3200 - (((tempf0*10) /5) *9 ) )
    if temperature => 18 then goto ZeroF

    lcdout $FE,1, "TempC: ", "-", dec (temperature >>1) , ".", dec tempbit," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", "+", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
    'lcdout $FE,$C0, "T: ", dec tempf0 , ".", dec tempF ," ",$DF,"F"
    goto loop

    ZeroF: '---------------- cases when zero celcius and 0 Fahrenheit

    tempF = ((((tempf0*10) /5) *9 ) -3200 )
    lcdout $FE,1, "TempC: ", "-", dec (temperature >>1) , ".", dec tempbit," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", "-", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
    goto loop

    end
    Last edited by lerameur; - 30th December 2006 at 23:38.

  6. #6
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    ahhhhhhh, look on page 3 of the ds18s20 spec sheet.
    0 celcius = 0000 0000 0000 0000
    -0.5 celcius = 1111 1111 1111 1111
    see, there is no formula for temperature in between these two, the calculation is done only ( by default with COUNT PER COUNT and COUNT REMAIN. which is obviously not good, not sure yet how I am going to fix that, working on it...

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    ahhhhhhh, look on page 3 of the ds18s20 spec sheet.
    0 celcius = 0000 0000 0000 0000
    -0.5 celcius = 1111 1111 1111 1111
    see, there is no formula for temperature in between these two, the calculation is done only ( by default with COUNT PER COUNT and COUNT REMAIN. which is obviously not good, not sure yet how I am going to fix that, working on it...
    Sounds like it's time for one of those cases where you just ignore it!
    After all, how much information do you really need between 0 and -.5 C ?

  8. #8
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    y amaybe , but the +655 is annoying, I'm almost there,
    OK it stick the whole unit outside, Its giving a steady -7 C

    Got rid of the +655:
    added this:

    IF temperature.11 = 1 Then goto Zerotemp
    if temperature = 0 then goto Special
    .
    .
    .
    Special:
    lcdout $FE,1, "TempC: ", dec 0 , ".", dec 0," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", dec 32 , ".", dec 0," ",$DF,"F"
    goto loop
    Last edited by lerameur; - 31st December 2006 at 00:45.

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. PIC16f877 code crosses boundary @800h
    By inventosrl in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th April 2009, 22:03
  3. serout and serin problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th April 2006, 19:44
  4. Replies: 11
    Last Post: - 13th July 2005, 19:26
  5. SerIn and SerOut
    By Dwayne in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 21st July 2004, 15:54

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