Thanks! I think that will work.
Mark
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
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
That's why I said to use LONG variable types in post #2.
Even that might overflow a 31bit signed variable.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
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?
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...
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
Bookmarks