Math Help Please


Closed Thread
Results 1 to 14 of 14

Hybrid View

  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

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 : 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