Floating point expression looking for integer math solution


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2008
    Location
    Berlin, Germany
    Posts
    14

    Default Floating point expression looking for integer math solution

    This is for a temperature mesurement aplication. The expression I'm trying to figure out using integer math is R2=R1/[(Vcc/V2)-1]. R2 is a thermistor. It changes it's internal resistence with temperature so i need to calculate it's resistence to figure out the temperature.

    R1=10K
    Vcc=5V
    V2 is 0 to 4096 (quantisized output from a a/d converter); where 456=0.456V and 2345=2.345V
    so the actual expression comes to:

    R2=10.000/[(5000/ad_res)-1]

    Code:
    ad_res var word
    temp0 var word
    temp1 var word
    temp2 var word
    final1 var word
    final2 var word
    final3 var word
    
    temp0=5000/ad_res
    temp1=5000//ad_res
    temp2=temp0*100+temp1-1
    final1=10000/temp2
    final2=10000//temp2
    final3=final1*100+final2
    overflow and imprecise result

    VCC
    o
    |
    # R1
    #
    |
    |-------oV2
    |
    # R2
    #
    |
    |
    GND

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Lightbulb a good hard ... allows easy soft !!!

    Hi, Castor

    May be there would be a smart turnaround ...

    if , instead of R1, you use a constant current generator ...

    say a PNP trans, with a red led between VCC and base, a resistor between emitter and VCC to fix your current ...
    and another resistor between base and GND to allow, say, 1 mA into the led + trans base.

    good idea, no ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    Short on time but this might get you started

    Rewrite this
    R2=10.000/[(5000/ad_res)-1]
    to look like this
    R2=10.000*ad_res/[5000-ad_res]

    calculate the denominator and keep (5000 - ad_res)
    Calculate the numerator (10.000*ad_res)
    Use Div32 to divide the numerator by the denominator

    Use Darrel's method to get the remainder

    http://www.picbasic.co.uk/forum/showthread.php?t=1942
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Or even easier (I think) to use a DS1820 type sensor.
    There has to be at least a dozen examples here on the forums.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi, Ski

    Good idea ...

    and if being really time-short a LM 35/335 ... could also do it !

    But what replacement for my .5 mm dia thermistors ( from aerospace industry ) ??? didn't find yet ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Apr 2008
    Location
    Berlin, Germany
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    I used Paul's sollution and it works great !

Similar Threads

  1. Strugling without floating point
    By pjsmith in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 27th March 2011, 06:29
  2. Floating point math
    By Glenn in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th January 2009, 03:47
  3. Floating Point Display Problem (serial string out)
    By Cash Olsen in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th December 2007, 02:03
  4. Microchip Floating Point Routines
    By Joe Rocci in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 12th October 2006, 19:51
  5. DIV32 instead of floating point routines?
    By Tomasm in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd April 2004, 07:50

Members who have read this thread : 1

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