Math Help Please


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Feb 2006
    Location
    Ohio
    Posts
    29

    Default Math Help Please

    Hi all,

    I’m using an 18F452 Pic for a Dynamometer project. I have an amplifier feeding the a/d input on the Pic 0-5 volts. A count of 70 equals a foot-pound of torque. The problem I’m having is the torque is going to be less than 1 foot-pound and the RPM’s will be low most of the time. This means that the output and the formula will need to have decimal points in it.

    Formula for Horse Power is: Horse Power = RPM x Torque (In Foot Pounds) / 5252

    The example below is for 1500 RPM’s at a ½ pound of torque.
    Example: (1500 rpm’s) x (35 x .0143) / 5252 = .1428 H.P.

    What would be the best way to approach the Math for this application?

    Thanks,
    Mark

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Example: (1500 rpm’s) x (35 x .0143) / 5252 = .1428 H.P.
    What would be the best way to approach the Math for this application?
    Use LONG's...to keep the precision...and you'll want it to keep it simple-ish.
    Instead of .0143, which PBP won't handle, use 143.
    1500 x 35 x 143 / 5252 = 1428
    When displaying, just put a decimal point in front of this bunch.
    Ok, RPMs are 8000 and torque is 300...
    8000 x 35 x 300 / 5252 = 15993
    Divide by 10000, display that number, put a decimal point, get the remainder (modulus), display that number

  3. #3
    Join Date
    Feb 2006
    Location
    Ohio
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    Thanks! I think that will work.

    Mark

  4. #4
    Join Date
    Feb 2006
    Location
    Ohio
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    When I use the example below I get a results of 1019 instead of 15993.

    Ok, RPMs are 8000 and torque is 300...
    8000 x 35 x 300 / 5252 = 15993
    Divide by 10000, display that number, put a decimal point, get the remainder (modulus), display that number

    My code is below:

    Include "modedefs.bas"
    define OSC 20
    define LOADER_USED 1 ' bootloader

    RPM VAR WORD
    STRAIN VAR WORD
    TORQUE VAR WORD
    A VAR WORD
    C VAR WORD


    A = 5252


    RPM = 8000
    STRAIN = 35
    TORQUE = 300


    C = RPM * STRAIN * TORQUE
    C = DIV32 A

    SEROUT PORTC.5,N2400,[12]
    SEROUT PORTC.5,N2400,[".",#C," HP ",10,13,14]

    STOP

    Mark

  5. #5


    Did you find this post helpful? Yes | No

    Default Break the equation in two

    I think your problem is a result of the triple multiplication. None of the PBP examples I have seen allow this.

    PBP does allow
    x = a*b
    y = div32 c

    Your constant, 5252, has 6 factors, namely 1, 2, 4, 13, 26, and 52.

    Break the equation in two with divisors say 52 and 101 and see how you go. Beware the integer division truncation problem where 201/101 = 1.

    The new LONG variable type (PBP 2.50 and up) MIGHT solve your problem but only after some gymnastics as the LONG type appears to allow big multiplicands but retains integer division so you probably need to scale all your numbers UP by factors of 100 or so.

    HTH
    BrianT

  6. #6
    Join Date
    Feb 2006
    Location
    Ohio
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    Thanks Brian.

    Mark

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    That's why I said to use LONG variable types in post #2.
    Code:
    Include "modedefs.bas"
    define OSC 20
    define LOADER_USED 1            ' bootloader
    RPM VAR WORD : STRAIN VAR WORD : TORQUE VAR WORD : A VAR WORD : C VAR LONG
    A = 5252 : RPM = 8000
    STRAIN = 35 : TORQUE = 300 : C = A * RPM * STRAIN * TORQUE
    SEROUT PORTC.5,N2400,[12,".",#C," HP   ",10,13,14]
    END
    Even that might overflow a 31bit signed variable.
    A fits in 13 bits
    RPM might take up to 14 bits
    Strain (in your example) another 6 bits
    Torque (in your example) another 9 bits
    Multiply those all together and you could get a 42 bit answer.
    What do you suppose your MAXimum values would be for each variable?

  8. #8
    Join Date
    Feb 2006
    Location
    Ohio
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    RPM Max = 12,000
    STRAIN Max = 210
    TORQUE Max = 143

    I have version 2.44 of PicBasic Pro. Will 'LONG' work with this version? Should I upgrade?

    Mark

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by markcadcam View Post
    RPM Max = 12,000
    STRAIN Max = 210
    TORQUE Max = 143

    I have version 2.44 of PicBasic Pro. Will 'LONG' work with this version? Should I upgrade?

    Mark
    Upgrade yes... Check the website for more info...

    12000 x 5252 x 210 x 143 = 1,892,610,720,000
    Way too big for long's...
    Like BrianT said, you'll have to figure out how to do some mathematic gymnastics to keep your numbers low enough to fit in 31/32 bits...
    Or you could do it the old fashioned way, like back in 2nd grade...one number at a time, carry the result if needed...and so on and so on...

    I guess it's up to you to figure out how much accuracy you really need/want...

  10. #10
    Join Date
    Feb 2006
    Location
    Ohio
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    Divide by 5252, not multiply it.

    RPM = 12000
    STRAIN = 210
    TORQUE = 140
    VALUE = 5252

    A = STRAIN * TORQUE
    B = RPM
    C= A * B
    C= C DIV32 VALUE

  11. #11
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by markcadcam View Post
    Divide by 5252, not multiply it.
    I knew that
    Ok,
    12000 x 210 x 143 = 360,360,000 which will fit into 31/32 bits.
    but that result x 100 won't...so...
    x100 /5252 is the same as x25 /1313
    rpm x strain x torque / 1313 x 25 = result (with decimal point shifted over)
    assuming you've used LONG variables.

  12. #12
    Join Date
    Feb 2006
    Location
    Ohio
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    Where is the x100 coming from?

  13. #13
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by markcadcam View Post
    Where is the x100 coming from?
    Another...'OH YEAH' moment just happened.
    You've already got the 'torque' value multiplied up for the decimal point.
    Disregard the stuff about x100/5252.

    12000 x 210 x 143 = 360,360,000 which will fit into 31/32 bits even when getting maximum values.
    Divide that by 5252 and you get 68613, which is 100x too much, right?
    So divide that by 100, gives you 686, take the remainder (modulus) and you get 13.
    Should be easy enough to display that (until you get to the leading zeros...PBP CAN handle that too if you read far enough into the LCDOUT and/or SEROUT section of the manual).

  14. #14
    Join Date
    Feb 2006
    Location
    Ohio
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    I think I got it now. Thanks for the help.

    Mark

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. Line Graph, math problem...
    By TerdRatchett in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th May 2009, 04: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. not quite understanding the MATH function
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th January 2006, 20:20

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