Serin serout problem


Closed Thread
Results 1 to 40 of 337

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I made these formulas and tested them on a calculator. it works. I dont know hy it do not work on the pogram I wrote.
    So
    ZeroF: ' cases when zero celcius and 0 Fahrenheit
    temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = 3200 -((temperature /5) * 9)

    --- SO if I need to do the conversion : -17C to 1.4F
    so I take 1700 (17 *100) put it in the formula (temperature) I get 140, just divide by 100 to get the answer..

    k
    Last edited by lerameur; - 29th December 2006 at 02:44.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    I made these formulas and tested them on a calculator. it works. I dont know hy it do not work on the pogram I wrote.
    So
    ZeroF: ' cases when zero celcius and 0 Fahrenheit
    temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = 3200 -((temperature /5) * 9)

    --- SO if I need to do the conversion : -17C to 1.4F
    so I take 1700 (17 *100) put it in the formula (temperature) I get 140, just divide by 100 to get the answer..

    k

    Zerotemp: ' cases when zero celcius and positive Fahrenheit
    temperature = temperature >> 1 'removing lowest bit
    temperature1 = temperature
    for counter = 0 to 6
    if temperature.0[counter] = 1 then
    temperature.0[counter] = 0
    else
    temperature.0[counter] = 1
    endif
    next counter



    ------------------------------------temp value right here not set up
    temp = temp + 1 ' 2,s compliment ends by adding a one
    temp = temp >> 5

    temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = 3200 -((temperature /5) * 9)
    if tempF = 0 then goto ZeroF

    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
    temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    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

    Where is the first temp getting set at? I don't think it is. I think it's always $ab (left over $aa from the serin with 1 added).

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I just got up, looked at the program , wow , a mess I did yesterday....
    I have to go be back working on it this afternoon.

  4. #4
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    ok I changed it a bit, but it is still getting confused about the zero mark.
    stll showing +655.XX celcius
    another thing, the decimal values are going the opposite way in the negative ,
    meaning, -1.96 to -1.90 instead of -1.90 to -1.96
    I have dec2 temperature for the decimal I tried
    1- dec2 temperature but it do not work ...

    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
    '63
    temperature = ((( temperature >>1 ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = 3200 -((temperature /5) * 9)
    if tempF <= 0 then goto ZeroF

    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

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    ok I changed it a bit, but it is still getting confused about the zero mark.
    stll showing +655.XX celcius
    another thing, the decimal values are going the opposite way in the negative ,
    meaning, -1.96 to -1.90 instead of -1.90 to -1.96
    I have dec2 temperature for the decimal I tried
    1- dec2 temperature but it do not work ...
    end

    So, I can assume that the positive temperature readings are all correct?

    Why are the 2nd and 3rd temp conversion formula's different from the 1st?
    t = 3200 - *5 / 9 instead of t = T*5/9 + 3200 (shortened, you know what they are)

    temperature = ( ~temperature ) + 1 try that also





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

    if tempF <= 0 then goto ZeroF

    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



    Try that....

    I just did an edit... You might have to do the correction/conversion/calculation before you do the 2's complement conversion. I've modified the program for that.
    Last edited by skimask; - 29th December 2006 at 22:01. Reason: Changed program again!

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default Different software

    Found this at Rentron's site:

    '************************************************* *******
    '* Name : Temp.BAS *
    '* Author : Bruce Reynolds *
    '* Notice : Copyright (c) 2003 Reynolds Electronics *
    '* : All Rights Reserved *
    '* Date : 7/28/2003 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* *******
    DEFINE osc 20 ' We're using a 20MHz oscillator
    Comm_Pin VAR PortC.0 ' One-wire Data-Pin "DQ" on PortC.0
    Busy VAR BIT ' Busy Status-Bit
    R_Temp VAR WORD ' RAW Temperature readings
    TempC VAR WORD ' Temp in deg C
    TempF VAR WORD ' Temp in deg F
    Float VAR WORD ' Holds remainder for + temp C display
    Cold_Bit VAR R_Temp.Bit11' Sign-Bit for +/- Temp. 1 = Below 0 deg C
    Real_Cold CON 1 ' Define Real_Cold = 1
    BAUD CON 16468 ' N9600 for serial LCD
    DISP VAR PortB.0 ' Pin to drive serial LCD
    Deg CON 223 ' Data to display Deg ° symbol
    CLR CON 1 ' CLR LCD command
    LINE1 CON 128 ' LCD line #1
    LINE2 CON 192 ' LCD line #2
    LINE3 CON 148 ' LCD line #3
    LINE4 CON 212 ' LCD line #4
    INS CON 254 ' LCD command mode parameter
    Sign VAR BYTE ' +/- sign for temp display
    Dummy VAR BYTE ' Dummy for Div32

    SEROUT2 DISP,BAUD, [INS,CLR]
    Start_Convert:
    OWOUT Comm_Pin, 1, [$CC, $44]' Skip ROM search & do temp conversion

    Wait_Up:
    OWIN Comm_Pin, 4, [Busy] ' Read busy-bit
    IF Busy = 0 THEN Wait_Up ' Still busy..?, Wait_Up..!
    OWOUT Comm_Pin, 1, [$CC, $BE]' Skip ROM search & read scratchpad memory
    OWIN Comm_Pin, 2, [R_Temp.Lowbyte, R_Temp.Highbyte]' Read two bytes / end comms
    GOSUB Convert_Temp
    GOTO Start_Convert

    Convert_Temp: ' +32.0 to +257 F
    IF Cold_Bit = Real_Cold THEN Yikes ' If Cold_Bit = 1, it's below "0" deg C
    Sign = "+"
    Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value
    TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
    Dummy = 1125 * R_Temp
    TempF = DIV32 100
    IF TempF >6795 THEN ' Over 99.5 deg F..?
    TempF = TempF + 3200
    SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ",Sign,DEC TempF DIG 4,_
    DEC TempF DIG 3,DEC TempF DIG 2,".",DEC2 TempF,Deg,"F "]
    ELSE
    TempF = TempF + 3200
    SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ",Sign,DEC TempF DIG 3,_
    DEC TempF DIG 2,".",DEC2 TempF,Deg,"F "]
    ENDIF
    TempC = (R_Temp & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
    Float = ((R_Temp.Lowbyte & $0F) * 625) ' Lower 4-bits of result * 625
    SEROUT2 DISP,BAUD, [INS,LINE2, " TempC = ",Sign,DEC TempC,".",DEC Float,Deg,"C "]
    SEROUT2 DISP,BAUD, [INS,LINE4, "Raw", IBIN16 R_Temp]
    RETURN

    Yikes: ' Display full range -C to -F conversion
    Sign = "-" ' Display - symbol for negative temp
    Dummy = 625 * ~R_Temp+1' Multiply to load internal registers with 32-bit value
    TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
    TempF = ~R_Temp / 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
    SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ",Sign, DEC TempF,Deg,"F "]
    SEROUT2 DISP,BAUD, [INS,LINE2, " TempC = ",Sign,DEC TempC DIG 4,_
    DEC TempC DIG 3,".",DEC3 TempC,Deg,"C "]
    SEROUT2 DISP,BAUD, [INS,LINE4, "Raw", IBIN16 R_Temp]
    ELSE ' Else result = +deg F
    TempF = ((((-TempF + 50) * 9) /5) -58)' -C to +F below 32.0 deg F to -17 deg C
    SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ","+",DEC TempF,Deg,"F "]
    SEROUT2 DISP,BAUD, [INS,LINE2, " TempC = ",Sign,DEC TempC DIG 4,_
    DEC TempC DIG 3,".",DEC3 TempC,Deg,"C "]
    SEROUT2 DISP,BAUD, [INS,LINE4, "Raw", IBIN16 R_Temp]
    ENDIF
    RETURN

    END



    Might get some good ideas from here on how to do the job efficiently.

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

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