did we mention FP Math?


Closed Thread
Results 1 to 10 of 10
  1. #1
    mslaney's Avatar
    mslaney Guest

    Default did we mention FP Math?

    I would gladly take the money I saved for Proton Plus and purchase PBP Pro.

    Is FP math in the works? When is the next version due to come out?

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    mslaney's Avatar
    mslaney Guest


    Did you find this post helpful? Yes | No

    Default

    I'm using 2.45. Don't get me wrong, it's a great compiler! However, it'd be great to type something like this:

    myfloat = (2.45 * 299.95)
    myfloat = (myfloat / 2.46)

    and that's it. No includes, no background conversions etc...

    Think of how much easier it would be to convert C to F, read a pot, measure time etc...


    I was just kidding about Proton - kind of a low blow, sorry :-)

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    well in some case it's more easy to do them in integer...

    2.45 * 1.45 will become (245 * 145)

    and then you do the the rest with DIG and DEC to display as you want.

    something like LCDOUT $fe,1, DEC DIG 1 MyVar,".",Myvar DEC4

    but i have to agree that it can be usefull to have built-in floating point maths... in some case

    as built in real SIN,COS,LOG or many else other.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    mytekcontrols's Avatar
    mytekcontrols Guest


    Did you find this post helpful? Yes | No

    Cool I totally agree with you on including FP Math

    Hi Mike,

    Yes I too would love to see this as a built-in option for PBP, but only if it can be done in a more memory efficient way than using Microchip's FP Routines. Speaking of which I just tried to implement this and was surprised out how much memory it took on my 18F252 to include these routines (3000 bytes for 24Bit Math and 4194 bytes for 32Bit Math). I don't really think I have the room to spare on my current project, so I'll have to do it another way, which is unfortunate.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Floating point with pretty much any PIC compiler just isn't very efficient.
    It's handy to have, but I try to avoid using fp unless it's just absolutely
    necessary.

    CCS C compiler with 16F876a target.
    Code:
    void main()
    {
        float a;
    
        a = 2.45 * 299.95;
        a /= 2.46;
        printf("a = %3.3f\r\n",a);
    }  /* returns a = 298.730 */
    ROM used: 670 words (8%)
    Largest free fragment is 2048
    RAM used: 11 (6%) at main() level
    29 (17%) worst case

    ==========

    Proton BASIC compiler, same target;
    Code:
        Dim a As Float
    
        a = 2.45 * 299.95;
        a = a / 2.46;
        HRSOut "a = ",Dec a,13,10
        ' returns a = 298.730
    Eats-up 487 words 5.94% code space, 47 bytes 12.5% RAM.

    C is a little more efficient at managing RAM, but they both chew up a gob
    of resources even for simple fp calculations.

    If you move up to the 18F series, it's a lot more bearable, but might still be
    a challenge squeezing a bunch of fp calcs in there.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    mytekcontrols's Avatar
    mytekcontrols Guest


    Did you find this post helpful? Yes | No

    Default

    C is a little more efficient at managing RAM, but they both chew up a gob
    of resources even for simple fp calculations.

    If you move up to the 18F series, it's a lot more bearable, but might still be
    a challenge squeezing a bunch of fp calcs in there.
    I agree with you Bruce, but as you said, the 18F series would be a better fit for floating point. Especially if you used either the 18F252 or 18F452, which have 1536 bytes of ram available (which is nothing to sneeze about). It would be nice if PBP would have floating point available for at least these particular processors.

    As always, thanks again for your valuable insight.

  8. #8
    Join Date
    Jul 2005
    Posts
    65


    Did you find this post helpful? Yes | No

    Smile

    Hello

    I agree with all you guys

    Its the matter of, Do I really need floating point.

    I have written a code to control PGA2311 and view the volume reading on LCD. At first place I was very sad, when I looked to the datasheets, the formula to calculate the decible value was a hell:

    dB = 31.5 - ( 0.5 * ( 255- vol ) )

    I thought the only solution was the floating point, any way, thanks to a friend who told me to use * 10 and * 100 approach :

    dB_VALUE : ' Calculations for decible equivalent values
    IF ( VOL_L >= 192 ) Then
    DB_SIGN = 1
    DB = 3150 - ( 5 * ( 2550 - ( vol_l * 10 ) ) )
    DB10 = DB / 100
    dB1 = DB // 100
    DB1 = DB1 / 10
    Else
    DB_SIGN = 0
    dB = ( 5 * ( 2550 - ( vol_l * 10 ) ) ) - 3150
    DB10 = DB / 100
    dB1 = DB // 100
    DB1 = DB1 / 10
    EndIF
    Return

    dB_LCD : ' Show volume on the LCD
    FLAG = 1
    if ( db10 == 0 ) AND ( DB1 == 0 ) THEN
    LCDOut I, clr, " Volume ", DEC DB10, " dB"', DEC VOL_L
    FLAG = 0
    ENDIF
    IF ( flag == 1 ) and ( DB_SIGN == 1 ) Then
    LCDOut I, clr, " Volume ", DEC DB10, ".", DEC DB1, " dB"', DEC VOL_L
    ENDIF
    IF ( flag == 1 ) and ( DB_SIGN == 0 ) Then
    LCDOut I, clr, " Volume -", DEC DB10, ".", DEC DB1, " dB"', DEC VOL_L
    ENDIF
    Return



    The compiled code was 970.


    When I used PICBasic Plus, and used floating pint stuff, the code was 1680 words. I now really know the Pros and Cons of floating point stuff, so, as an advice, don't ever use it, unless you badly need it

    See ya

  9. #9


    Did you find this post helpful? Yes | No

    Default Need code example for PGA2311

    Hi:Would you have some code to share regarding the PGA2311 chip,I would like to try to experiment with this device.I just purchased picBasic pro.

    Thanks Bob C.

  10. #10
    BertMan's Avatar
    BertMan Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rcbandwidth
    Hi:Would you have some code to share regarding the PGA2311 chip,I would like to try to experiment with this device.I just purchased picBasic pro.

    Thanks Bob C.
    Great first post location choice there Bob. Back to the subject....You also have to keep in mind that some devices are preinterfaced with float32 out, which means you have to come up with some kind of solution if you want to use a pic.

Similar Threads

  1. Line Graph, math problem...
    By TerdRatchett in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th May 2009, 05:20
  2. PBPL Math...new math takes more cycles...Always?
    By skimask in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2008, 11:22
  3. Why can't PIC's support fp math
    By jheissjr in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 3rd August 2006, 09:09
  4. not quite understanding the MATH function
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th January 2006, 21:20
  5. Double (or Quad) Precision and FP math
    By NavMicroSystems in forum PBP Wish List
    Replies: 1
    Last Post: - 24th January 2005, 20:25

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