help floating Point!


Closed Thread
Results 1 to 2 of 2
  1. #1
    Eric's Avatar
    Eric Guest

    Default help floating Point!

    Hello to everybody



    I need to calculate the following formula with PBP from Melabs



    P=(1/(10*Cost*C))^(1/expo)





    Where P is pressure (mBar)

    Cost is a costant (integer i.e.1850)

    And expo is another costant (Float 1.065)



    C is the indipendent variable (integer from 0.1 to 100000)





    Thanks a lot



    Eric.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default RE help floating Point!

    Eric,

    The method below is what I use to work around the point problem.

    This example is for a 0 to 100 psi sensor with 1 to 5 volt out put.

    U=SX+Q

    "U" is the out put in the units you are using.

    "S" is the slope or scale factor.

    "X" is the input (millivolts,volts,etc).

    "Q" is the offset.

    Figure the slope. In the case above...

    (100-0) / (5-1) = 25 PSI/Volts

    Offset in this case is (-25). Calculated value of offset was 25 PSI/Volts, therefore, 1V=25.

    The above will return 0psi for 1volt and 100psi for 5 volts.

    Use the same idea when working with an ADC. The input that the PIC sees is 0 to 255, 256 span. Offset would be PSI/BITS. Full span will return 100/256=0.390625

    Now, dealing with the decimal.

    Two varibles are needed, one for the ADC and one for the out put after calculating.

    pressure VAR BYTE 'out put
    press VAR BYTE ' ADC return

    'ADC routine

    pressure = (39 * press - 39) / 100

    'Drop "point", in this case 3906 would put the return over the 65535 limit. If more accuracy is needed look at DIV32 in the manual.

    Varible "pressure" will now be within 1 psi of the actual pressure at the sensor.

    In short, drop the point and then divide by 10,100,1000 etc later.

    Hope this helps,
    Dave

Similar Threads

  1. Floating point math
    By Glenn in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th January 2009, 03:47
  2. Getting out of floating point
    By jcb344 in forum General
    Replies: 3
    Last Post: - 5th August 2008, 21:18
  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. Floating Point
    By jrudd in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th May 2005, 14:19

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