Help!! Integer Math?


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Mar 2005
    Posts
    37

    Default Help!! Integer Math?

    I have been racking my brain for the past two weeks with the following!

    I have a PIC12F675 reading an AD595 thermocouple IC. The AD595 provides 10mV/C. In order to read the temp below 0 I have added a voltage divider to the ground pin of the AD595. I have also power the AD595 via a -5V to +5V power supply. I read the output of the AD595 on GPIO.0 and the Virtual Ground voltage via GPIO.1.

    To read the temperature above 0C I basically subtract GPIO.1 from GPIO.0. I cannot get the math correct for any thing below 0C or 32F.

    Here is some of the code:
    'celsius
    'farenheit
    'adval = GPIO.0
    'adval1 = GPIO.1

    if adval > adval1 then 'this is correct down to 32F or 0C
    celsius = adval - adval1
    farenheit = (celsius * 18) / 10
    farenheit = farenheit + 32
    else
    celsius = adval1 - adval 'Here is were my problems start
    celsius = celsius - adval
    farenheit = (celsius * 18) / 10
    farenheit = farenheit + 32
    endif

    I will handle the sign output later!

    Can anyone point me in the right direction with the math?

    Thanks in advance,

    Scott

  2. #2
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    Try removing the "celsius = celsius - adval" line.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    As I understand it...

    Subtracting adval-adval1 gives you positive Celcius.

    Therefore adval1-adval would give you negative Celcius. The math is the same. Conversion to Farenheit is more tricky. But stop and think before you go any further...

    If you Reference everything to a single numeric value... say a value of 0 in a BYTE (or WORD) variable, equals the lowest Temperature you are likely to encounter (example -100C). Do your (positive or negative math) so you have ONE positive going linear scale, from that lowest Temperature reference point. Then it's a simple matter of calculating C or F using that one variable.
    Example.

    Say a count of ONE of (adval-adval1) equals 1C positive then.

    So...

    If adval>adval1 then
    TEMP=100+(adval-adval1)
    else
    TEMP=100-(adval1-adval)
    endif

    Now we have a single variable TEMP which holds a linear representation of our whole Temperature range. Now from this variable we can calculate C or F easily.

    In our above example a count of 100 is 0C. Anything over 100 is positive, and anything lower than 100 is negative.

    If TEMP<100 then
    TEMPB=100-TEMP
    LCDOut "-",#TEMPB," C"
    else
    TEMPB=TEMP-100
    LCDOut #TEMPB, "C"
    endif

  4. #4
    Join Date
    Mar 2005
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    Hi Melanie,

    I have been out of the office today! I was working on this late last night and come up with the following:

    if adval > adval1 then
    celsius = adval - adval1
    farenheit = (celsius * 18)/10
    farenheit = farenheit + 32
    status = 0
    else
    celsius = adval1 - adval
    farenheit = (celsius * 9)/5
    farenheit = 32 - farenheit
    status = 1
    endif

    if (status = 1) & (celsius > 32) then
    sign = "-"
    else
    sign = "+"
    endif

    I will try your code tonight!

    Thanks for your help,

    Scott

  5. #5
    Join Date
    Jun 2005
    Location
    Mumbai,India
    Posts
    43


    Did you find this post helpful? Yes | No

    Question Integer Maths

    Quote Originally Posted by scottl
    I have been racking my brain for the past two weeks with the following!

    I have a PIC12F675 reading an AD595 thermocouple IC. The AD595 provides 10mV/C. In order to read the temp below 0 I have added a voltage divider to the ground pin of the AD595. I have also power the AD595 via a -5V to +5V power supply. I read the output of the AD595 on GPIO.0 and the Virtual Ground voltage via GPIO.1.

    To read the temperature above 0C I basically subtract GPIO.1 from GPIO.0. I cannot get the math correct for any thing below 0C or 32F.

    I will handle the sign output later!

    Can anyone point me in the right direction with the math?

    Thanks in advance,

    Scott

    I saw the AD595 datasheet and for temp below 0 degrees Celecius the
    output -ve. As U have stated that that U have added voltage devider to gnd
    pin of ad595 but whether the input to PIC is above 0V or not? U must have
    output of AD595 at 2.5V or half the reference supply of PIC. Then 0 degrees
    would correspond to 128 in 8bit mode. this way may be Ur maths will work if U are gng to add - sign later

Similar Threads

  1. Resolution integer math assistance?
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th January 2010, 03:01
  2. Replies: 5
    Last Post: - 28th May 2008, 10:20
  3. Pulsin Math question
    By ruijc in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 2nd April 2008, 16:15
  4. PBPL Math...new math takes more cycles...Always?
    By skimask in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2008, 10:22
  5. Help!! Integer Math?
    By scottl in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th June 2006, 13:47

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