Serin serout problem - Page 5


Closed Thread
Page 5 of 9 FirstFirst 123456789 LastLast
Results 161 to 200 of 337
  1. #161
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    yes the positive values works just fine,
    I dont why you are doing 2,s compliment twice in the zerotemp.
    I saw that program , but there was too many things I did not understand, like this line:
    Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value

    Why multiply by 625..


    I also tryed it as is: ( it get stuck at 0.00 C and stays there)

    loop:
    '24
    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
    '40
    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
    '58
    Zerotemp: ' cases when zero celcius and positive Fahrenheit

    Dummy = 625 * ~temperature+1' Multiply to load internal registers with 32-bit value
    TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
    TempF = ~temperature / 16 ' Begin conversion from -C to deg +/-F
    IF TempF >=18 THEN ' Check for -degrees F "-18 C = -0.4 F"
    TempF = ((((TempF + 50) * 9) /5) -122) ' -C to -F below -17 deg C
    lcdout $FE,1, "TempF: " ,"-" , DEC TempF,$DF,"F "
    lcdout $FE,$C0, "TempC: ", "-",DEC TempC DIG 4, DEC TempC DIG 3,".",DEC3 TempC, $DF,"C "

    ELSE ' Else result = +deg F
    TempF = ((((-TempF + 50) * 9) /5) -58)' -C to +F below 32.0 deg F to -17 deg C
    lcdout $FE,1, " TempF: " , "+", DEC TempF, $DF,"F "
    lcdout $FE,$C0, " TempC: ","-" ,DEC TempC DIG 4,DEC TempC DIG 3,".",DEC3 TempC,$DF,"C "

    ENDIF
    goto loop

    end
    Last edited by lerameur; - 29th December 2006 at 22:36.

  2. #162
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    yes the positive values works just fine,
    I dont why you are doing 2,s compliment twice in the zerotemp.
    I saw that program , but there was too many things I did not understand, like this line:
    Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value

    Why multiply by 625..

    end
    I'm not doing the 2's compliment twice, the first one is commented out, the 2nd is for the + case, the 3rd is for the - case. It won't get done more than once.

    Do you have your PBP manual handy by chance?
    I'm still looking at the rest of your code in your last post, I wanna show you some stuff about 32 bit math in the PBP manual that might help.
    Last edited by skimask; - 29th December 2006 at 23:20.

  3. #163
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    ya the manual is right here:

    I get this code , still not working , but better:

    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
    temp1 = temperature
    temperature = ( ~ temperature ) + 1 '----- do this later, right before displaying it
    '63
    tempc =temperature
    temperature = ((( temperature ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = ((temperature /5) * 9) + 3200

    if tempF <= 0 then goto ZeroF

    'lcdout $FE,1, bin temp1 , ".", bin temperature ," ",$DF,"C"
    'lcdout $FE,$C0, bin tempc , ".", dec tempc/2 ," ",$DF,"F"

    'temperature = ( ~ temperature ) + 1 : tempf = ( ~ tempF ) + 1 ' added this
    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 = ((temperature /5) * 9) + 3200

    temperature = ( ~ temperature ) + 1 : tempf = ( ~ tempF ) + 1 ' added this
    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

  4. #164
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    [QUOTE=lerameur;30245]ya the manual is right here:

    Page 33-35, 32 bit math, that will explain the code from Rentron.

  5. #165
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post

    temperature = ( ~ temperature ) + 1 : tempf = ( ~ tempF ) + 1 ' added this
    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
    That 2nd conversion is done twice... once after Zerotemp & once after ZeroF.

  6. #166
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    That 2nd conversion is done twice... once after Zerotemp & once after ZeroF.
    O yes, I removed it, anyway I cant test that cold yet

  7. #167
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    O yes, I removed it, anyway I cant test that cold yet
    No, but you can simulate it at the transmitter end with a loop instead of reading the temp sensor....duh!!!

    Just set up the transmitter to send out a slowly changing temperature that goes up the scale, resets to the low end, climbs back up again, whatever works for you.
    Or do it at the receiver end, put a couple of buttons in there, one button-temp goes up, another button-temp goes down.

  8. #168
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    ok , I get that now,
    I want to concentrate on the cold but not that cold part for now.. the sensor is sticking outsid now, its about -11C
    I wanted to see what was behing calculated..
    The 2's compliment, the binary value gives me a good degree (tempc)
    when I put it in the equation it then screws up, I think the 2 byte count_per_c AND count_remain and different since it is in negative mode... hummm
    Nothing is siad about this in the specsheet either, and the program on Rentron does not use that part.

    here is the code:

    Zerotemp: '------------- cases when zero celcius and positive Fahrenheit
    temp1 = temperature
    temperature = ( ~ temperature ) + 1 '----- do this later, right before displaying it
    tempc =temperature
    temperature = ((( temperature ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = ((temperature /5) * 9) + 3200
    if tempF <= 0 then goto ZeroF
    lcdout $FE,1, dec temp1 , ".", dec temperature ," ",$DF,"C"
    lcdout $FE,$C0, dec temperature, dec tempc , ".", dec tempc/2 ," ",$DF,"F"
    temperature," ",$DF,"C"

    goto loop

  9. #169
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    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.


    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
    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)
    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 01:57.

  10. #170
    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?

  11. #171
    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.

  12. #172
    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.

  13. #173
    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).

  14. #174
    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.

  15. #175
    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...

  16. #176
    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 ?

  17. #177
    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.

  18. #178
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    and lastly,

    i want to use a 9v battery to power the system. I want to add a led to signal when the battery need to be changed. would you know at what voltage this would be ?

  19. #179
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    It will depend wich regulator you use and wich voltage your PIC run.

    For battery operated device i will suggest a LDO regulator instead of those grandpa 7805.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  20. #180
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default How about solar?

    Quote Originally Posted by lerameur View Post
    and lastly,

    i want to use a 9v battery to power the system. I want to add a led to signal when the battery need to be changed. would you know at what voltage this would be ?
    Watch those sales you can get a solar yard light for < $8.00 US complete with rechargeable batteries you would have solar panel, batteries, housing and an LED to flash!, you would have to settle for 3 volts though.

  21. #181
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    and lastly,

    i want to use a 9v battery to power the system. I want to add a led to signal when the battery need to be changed. would you know at what voltage this would be ?
    For one thing, I don't know what your system is made of (I know bits and pieces, that's it, not the whole thing). And another thing, a 9v battery would be dead in a short matter of days running this system, especially if you're using a linear regulator (7805 type), even if you set it up to spend most of it's time sleeping and only waking up like once a minute or so.

    Better idea would be to go with a 4 cell (AAA or AA, doesn't matter) NiMH pack and skip the regulators altogether, then charge it up for about 12 hours using a 9v wall wart and an inline 200-ish ohm series resistor (less resistor = quicker charge at the expense of battery life). 4 2000mAh NiMH batteries would last a LOT longer than a 9v battery.

    But if you insist on a 9v battery, I'd hook it up to an unused A/D input thru a voltage divider consisting of 2 equal resistors. Get the A/D input working and displaying correctly, then turn on the 'change battery' light at about 6.5v. Anything below that and the regulator won't regulate (if you're using a 7805 type).

  22. #182
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    ok so i guess I will chucking those LM7805 out of th house...
    I have four 2300 nimh AA for my digital camera, guess I could use those for now, not need for voltage regulator right, just want to double check .
    but with this setup , how would I have a regulated voltage to compare the batteries voltage, , How would I implement my blinking led for low voltage ?

  23. #183
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    ok so i guess I will chucking those LM7805 out of th house...
    I have four 2300 nimh AA for my digital camera, guess I could use those for now, not need for voltage regulator right, just want to double check .
    but with this setup , how would I have a regulated voltage to compare the batteries voltage, , How would I implement my blinking led for low voltage ?
    What are the implications is the unit's power runs out? (might help to figure that bit out if I knew how badly the unit had to stay powered up).


    How about this? Use a 2.5v reference chip from Microchip, MCP1525. Use that as Vref+ for an A/D input on the PIC. Take your battery pack, put a v-divider on it, say 2:1 ratio, 10K & 10K, or whatever, pluck the signal off the middle of that, read that to an A/D channel, and presto...instant voltage reading...with some math of course.

    Ground on Vref-, 2.5v (from MCP1525) on Vref+.
    Batt+ to one side of 40K resistor, Batt- to one side of 10K resistor. Other 2 ends of resistor connected together and fed to A/D input (say AN0 for example).
    Do a read on AN0 A/D input. I forget what PIC you're using, but say it has a 10 bit A/D converter. That means that your 10 bit A/D converter would have a resolution (based on the 2.5v Vref+) of 2.44xxx mV. Since the voltage going into the converter is divided by 2, the real resolution of the total voltage across the battery is 4.8828125mV.
    If you're project doesn't drain much current, you could probably run it down to about 3.6v (.9v/cell). So, while reading the A/D, your reading is going down. When it hits 737 (737 x .0048828125 = 3.598v), turn on the low battery light. Actually, you'll probably want the light on sooner to give yourself some time to get them charged up. And the MCP1525 comes in TO-92 & SOT-23 packages. Easy to use.
    Last edited by skimask; - 31st December 2006 at 03:27.

  24. #184
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    my father cuts meat and has a cold room in the garage, This unit is wireless receiver that will give him the temperature. It is not crucial if there is a downtime to charge the battery, (or a downtime of a few hours if the compressot breaks down) but at least a warning that they are running low.

  25. #185
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    my father cuts meat and has a cold room in the garage, This unit is wireless receiver that will give him the temperature. It is not crucial if there is a downtime to charge the battery, (or a downtime of a few hours if the compressot breaks down) but at least a warning that they are running low.
    The transmitter is in the room and it's wireless/battery powered? And the receiver is elsewhere, plugged into the wall or something?

    Ya know for that matter, you could (and probably are but I'm not sure), transmit the transmitter's battery voltage along with temperature data to the receiver.

  26. #186
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    nope, the transmitter is in the garage, pluged into the wall, there is a 40 feet line runnin gfrom the sending module to the sensor, becasue the sensor is inside the fridge. This part is done, I installed the module up high inthe garage with the antenna sticking out, it is a straight line to the house. The receiving module is wireless, so he cantake it in his room or the kitchen etc..

  27. #187
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    nope, the transmitter is in the garage, pluged into the wall, there is a 40 feet line runnin gfrom the sending module to the sensor, becasue the sensor is inside the fridge. This part is done, I installed the module up high inthe garage with the antenna sticking out, it is a straight line to the house. The receiving module is wireless, so he cantake it in his room or the kitchen etc..


    Ok, TX, powered, garage....

    RX - portable, battery powered. Couple of notes I thought of. If the receiver doesn't get a good update for a minute or something, a light/alarm or something goes off as an indication to check on the transmitter (power went off or the transmitter got kicked over by the cat or something out there).

    Have you already tried the TX module with this 40ft of wire? Does it work?

  28. #188
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    yes the TX module is fully completed , I was doing my earlier test with it.
    well also, i wanted to add a led for the battery alarm. A led for when the temperature goes over 50 F, and a piezo buzzer that gos off for 10 sec if the temperature goes over 50 F.
    Last edited by lerameur; - 31st December 2006 at 03:47.

  29. #189
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    yes the TX module is fully completed , I was doing my earlier test with it.
    well also, i wanted to add a led for the battery alarm. A led for when the temperature goes over 50 F, and a piezo buzzer that gos off for 10 sec if the temperature goes over 50 F.
    So what's the next step?

  30. #190
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I am using a pic16F88 and I amnot sure whcih pins to use. Right now I am using pins 1, 2, 17, 18 for my lcd out and also pin 6,7 for control. Pin 5 and 14 for powering. Pin 8 for input.
    If I use the Vref, then i need to move my lcd out pins to pin 10 through 13 ( I wanted to us these for led out, piezo and other outputs i needed. I never had luck outputting on port A. Shouln't be hard to get it going.
    Also I dont have any MCP1525, I only have 7805 chips maybe use this chip for now and replace it when I get another ?...
    and use a voltage divider on the 7805 to obtain 2.5 v ?
    I assume the MCP1525 is an LDO chip ??

    also instead of using 40k and 10 K resistors, can I use 400k and 100K ? would that take up even less power ?
    Last edited by lerameur; - 31st December 2006 at 13:22.

  31. #191
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    hi , maybe i woul dneed expert advise here on wiring and soldering. I think I did an ok job, but when i move my wires a few times after soldering, they break, I use the same wire that i use on the breadboard (picture you seen )
    k

  32. #192
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    I am using a pic16F88 and I amnot sure whcih pins to use. Right now I am using pins 1, 2, 17, 18 for my lcd out and also pin 6,7 for control. Pin 5 and 14 for powering. Pin 8 for input.
    If I use the Vref, then i need to move my lcd out pins to pin 10 through 13 ( I wanted to us these for led out, piezo and other outputs i needed. I never had luck outputting on port A. Shouln't be hard to get it going.
    Also I dont have any MCP1525, I only have 7805 chips maybe use this chip for now and replace it when I get another ?...
    and use a voltage divider on the 7805 to obtain 2.5 v ?
    I assume the MCP1525 is an LDO chip ??

    also instead of using 40k and 10 K resistors, can I use 400k and 100K ? would that take up even less power ?
    Well, if you can't change the Vref pins around, then maybe use 2 A/D converters and compare your fixed reference against the total applied? In other words, if you're battery ever got down to 2.5v, then the A/D input would be at maximum. Just takes a bit of math I supose...

    And since you don't have any MCP1525 or anything like it, I know one thing you do have that does have a fixed reference...

    Or do you?
    I'll give you a little bit to think about it, then I'll give you the answer.

    And also since you don't have a fixed voltage (or do you? )...you won't need to worry about the resistors for now.

  33. #193
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    the only fix voltage I have now is my Lm7805 at 5v.

    and also, what is the lowest voltage for 4 Nmhi batteries, (when needed to be changed)

    well I removed the Lm7805, , i dont have any fox voltage reference. also, leaving the LM7805 there, i could not get enough voltage for the unit to operate
    Last edited by lerameur; - 1st January 2007 at 17:00.

  34. #194
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    the only fix voltage I have now is my Lm7805 at 5v.

    and also, what is the lowest voltage for 4 Nmhi batteries, (when needed to be changed)

    well I removed the Lm7805, , i dont have any fox voltage reference. also, leaving the LM7805 there, i could not get enough voltage for the unit to operate
    Read the datasheets for the 7805 and you'll find out why you can't get enough voltage from them, they need a couple of volts of overhead to operate correctly.

    Lowest volts for NiMH batts - really depends on the current draw, the higher the draw, the higher the end voltage. I suspect for your application, you might want to charge them up when they hit 1v/cell (4v total). That will give you some time to get to it. I wouldn't let them get much below .8v/cell, but then they're on their way out anyways. As far as charging, take them up to about 1.4v/cell depending on the charge rate, faster charge, higher voltage (up to a point of course), slower charge, lower voltage. Overall, 1.4v is a good round number.

    More on the easy voltage reference later. Here's a bit of a teaser for you: take a diode, any old diode, a resistor and a 9v battery. Hook it up as follows, +9v to resistor, resistor to one side of diode, other side (banded side) of diode to -9v. Read the voltage across the diode, just the diode and only the diode. Now change the value of the resistor, read the voltage across the diode again, change the resistor again, read the diode again, swap the 9v battery for the 4cell NiMH pack, read the diode again. Let me know your results.

  35. #195
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    yes actually, i went and read that , its like a diode, loosing 0.7 volt, so you need a bit more to compensate..
    i have been working on the a/d conversion, again this is my first time, I am reading section 12 of he pic16f88 datasheet.

    i wrote this program , bit it do not display the right inotmation:


    'RECEIVE PIC
    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7
    ANSEL = %00001100 'Put port 2 and 3 analog and otehr digital
    ADCON1 = %11000001 ' Set PORTA analog and RIGHT justify result
    ADCON0 = %00010001 ' Configure and turn on A/D Module

    DEFINE LCD_DREG PORTB ' Set LCD Data port
    DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000
    pause 1000

    ' Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS

    input1 var word : input2 var word

    TRISA = %11111111 ' Set PORTA to all input

    Pause 500

    loop: ADCIN portA.2, input1
    ADCIN portA.3, input2

    Lcdout $fe, 1 ' Clear LCD
    Lcdout "Value1: ", DEC input1 ' Display the decimal value
    lcdout $FE,$C0, "Value2: ", dec input2
    Pause 200

    Goto loop
    End

  36. #196
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    More on the easy voltage reference later. Here's a bit of a teaser for you: take a diode, any old diode, a resistor and a 9v battery. Hook it up as follows, +9v to resistor, resistor to one side of diode, other side (banded side) of diode to -9v. Read the voltage across the diode, just the diode and only the diode. Now change the value of the resistor, read the voltage across the diode again, change the resistor again, read the diode again, swap the 9v battery for the 4cell NiMH pack, read the diode again. Let me know your results.[/QUOTE]

    I will do this test a little bit later, i will give you the results.

  37. #197
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    yes actually, i went and read that , its like a diode, loosing 0.7 volt, so you need a bit more to compensate..
    i have been working on the a/d conversion, again this is my first time, I am reading section 12 of he pic16f88 datasheet.

    i wrote this program , bit it do not display the right inotmation:


    'RECEIVE PIC
    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7
    ANSEL = %00001100 'Put port 2 and 3 analog and otehr digital
    ADCON1 = %11000001 ' Set PORTA analog and RIGHT justify result
    ADCON0 = %00010001 ' Configure and turn on A/D Module

    DEFINE LCD_DREG PORTB ' Set LCD Data port
    DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000
    pause 1000

    ' Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS

    input1 var word : input2 var word

    TRISA = %11111111 ' Set PORTA to all input

    Pause 500

    loop: ADCIN portA.2, input1
    ADCIN portA.3, input2

    Lcdout $fe, 1 ' Clear LCD
    Lcdout "Value1: ", DEC input1 ' Display the decimal value
    lcdout $FE,$C0, "Value2: ", dec input2
    Pause 200

    Goto loop
    End
    What did it display? How are you hooked up?

    The thing I had in mind is keeping Vref+ and Vref- on Vdd and Vss (battery power). One A/D input is connected to the diode, .7v, which should always stay the same (give or take a bit depending on temperature). The output number from the A/D will be a ratio of that diode (.7v) to the battery voltage., the lower the number, the higher the battery voltage.

    For example, if the battery voltage was actually .7v (just for arguments sake, I know it would never be that low), and the diode voltage was .7v, the A/D output would be 1023.
    If the battery voltage was 4.8v and the diode was .7, .7 divided by 4.8 multiplied by 1024 (full scale A/D reading) would be 149 (149.3). So, 149 would be full charge.
    Taking that same train of thought, if the battery voltage was 3.6v (.9v/cell, battery dead), .7 divided by 3.6 multplied 1024 would be 199 (199.1) which would mean dead battery.

    Are ya following me here?

  38. #198
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    More on the easy voltage reference later. Here's a bit of a teaser for you: take a diode, any old diode, a resistor and a 9v battery. Hook it up as follows, +9v to resistor, resistor to one side of diode, other side (banded side) of diode to -9v. Read the voltage across the diode, just the diode and only the diode. Now change the value of the resistor, read the voltage across the diode again, change the resistor again, read the diode again, swap the 9v battery for the 4cell NiMH pack, read the diode again. Let me know your results.
    I will do this test a little bit later, i will give you the results.[/QUOTE]



    Ok, it looks like you're ahead of me a bit

  39. #199
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    well the program i wrote was initially suppose to be a simple a/d program. I never did A/D, so i wanted to write a program with just that in it, I want to read a sensor (light to voltage ) then output the value to the lcd screen, Then I will integrate this concept into my project. I am using the pic16F88,with analog input on portA.2 and A.3.
    My lcd shows about 100 at start up and goes up gradually to 980 in about a minute. obviously something is wrong
    I want to understand the A/D by that knowing how to program , before going further.
    k
    Last edited by lerameur; - 2nd January 2007 at 02:59.

  40. #200
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    another thing, I get (sometimes) wired values on the receiver. I read the temperature good, but once in a whjile, I get 2 temperature reading on one line, other ime i get +200, etc...
    does this have to do with the system being wireless, or the fact that my encoding technique is weak and prone to mistakes??

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 : 2

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