FP routines with PBP


Closed Thread
Results 1 to 6 of 6
  1. #1
    skimask's Avatar
    skimask Guest

    Default FP routines with PBP

    I finally got a project that I need to use some floating point math in.
    So, I did what everybody should do... I did a search here, found out that on MeLabs site, there's an FP package just waiting to get compiled with PBP and work for me. Also downloaded AN575 (? I think that's what it was) from Microchip.

    Question---the files in the FP.ZIP are dated 3/25/04. That's a bit old. Does anybody know if the FP package still works with PBP 2.47 and MPLAB 7.51 (or whatever is the latest version)?

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


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by skimask View Post
    I finally got a project that I need to use some floating point math in.
    Unfortunately, I have never used FP with a PIC - I have been lucky enough to always get by with Fixed Point Math (for the "hard" math). I know some things are better solved with FP but would be curious to know what you are trying to do?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by paul borgmeier View Post
    Unfortunately, I have never used FP with a PIC - I have been lucky enough to always get by with Fixed Point Math (for the "hard" math). I know some things are better solved with FP but would be curious to know what you are trying to do?
    Quite frankly:

    AFR x 6.17 x 454 x .621371 x VSS
    --------------------------------
    3600 x ( MAF / 100 )

    I know most of it can be combined ahead of time, and that's what I'll do obviously.
    AFR will be one of 2 values (maybe more), 12.5 or 14.7
    6.17 = average density of gasoline in lbs/gallong
    454 = grams in 1 pound
    .621371 = miles in 1 kilometer
    VSS - byte value for speed in kph
    MAF - word value for mass air flow grams/second
    3600 & 100 - time and decimal point unit conversions

    Any guesses as to what I'm building?

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


    Did you find this post helpful? Yes | No

    Smile

    Skimask,

    Although it is late now, here is something I would try ...

    Bash out all the constants as you noted ( 604.365, 710.734). You are left with

    604.365VSS/MAF and 710.734VSS/MAF

    Multiply these by 10 and keep the integer part (for added accuracy).

    Const = 6044 or 7107

    ANS = CONST * VSS
    ANS = DIV32 MAF

    Then use Darrel's trick to retrieve the remainder

    http://www.picbasic.co.uk/forum/showthread.php?t=48

    Put it back together as needed (Darrel shows this in his thread). This skips even the pain of Fixed Point if it works for you.

    Do you need to use the answer in additional math or just display it?
    What accuracy do you need?
    If you want to pursue Fixed Point then the standard 24.8 format would work (2 word variables)

    Oh, it's too late to guess - I'll try that tomorrow - over and out


    EDIT: MAF would have to be greater than or equal to 23 or 27 (depending on 6044 or 7107, respectively) in order for the DIV32 result to be less than 65536 - if they were not, you would have to tweak the math or check the ratio of VSS/MAF before the mult / DIV32 - clear as mud?
    Last edited by paul borgmeier; - 15th January 2007 at 08:34.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by paul borgmeier View Post
    Skimask,
    Although it is late now, here is something I would try ...
    Bash out all the constants as you noted ( 604.365, 710.734). You are left with
    604.365VSS/MAF and 710.734VSS/MAF
    Multiply these by 10 and keep the integer part (for added accuracy).
    Const = 6044 or 7107
    ANS = CONST * VSS
    ANS = DIV32 MAF
    Then use Darrel's trick to retrieve the remainder
    http://www.picbasic.co.uk/forum/showthread.php?t=48
    Put it back together as needed (Darrel shows this in his thread). This skips even the pain of Fixed Point if it works for you.
    Do you need to use the answer in additional math or just display it?
    What accuracy do you need?
    If you want to pursue Fixed Point then the standard 24.8 format would work (2 word variables)
    Oh, it's too late to guess - I'll try that tomorrow - over and out

    EDIT: MAF would have to be greater than or equal to 23 or 27 (depending on 6044 or 7107, respectively) in order for the DIV32 result to be less than 65536 - if they were not, you would have to tweak the math or check the ratio of VSS/MAF before the mult / DIV32 - clear as mud?
    That Darrel trick is fairly slick. I'm going to use that one in the future.
    I'd like it accurate down to +/- .01, but +/- .1 will do for now. In the end, like everything, I'd like as much accuracy as I can get as these results will be accumulated over time (don't we all hate tolerance stack-up).

    And I thought of the MAF/VSS ratios and overflowing out of 16 bits thing. I might end up having to divide the 2 parts down or multiply them up a bit before the final DIV32. If I have any code space left over, I'm going to throw a couple of checks in there. If MAF/VSS won't overflow the end result, I go here, if they will, I go there.

    I'm still looking over the FP routines to see if they're what I need or if I get to reinvent the wheel again

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Hi, Skimask

    You can also remember Every number can be close-rounded as the division of two integers ... ( PI = 22/7 i.e. )

    That give some brain work to find the couple of the year ... but a small GWBASIC ( LOL !!! ) program can easily sort them.

    With the use of the DIV32 function ... that enables more than you ever dreamed !!!

    Alain

    PS: About Basics that include "High level" Functions : remember you do not have to twist your brain ... but must have a lot of Program memory; say, JUST for really "basic" GLCD functions ... no less than 2K !!!
    No secret nor mystery !!!
    Last edited by Acetronics2; - 16th January 2007 at 09:09.
    ************************************************** ***********************
    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 " !!!
    *****************************************

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. Extensions to PBP variables
    By John_Mac in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 23rd October 2009, 05:21
  3. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30
  5. PBP / XP Crash
    By pondindustrial in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 27th November 2005, 03:16

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