devin wrote:please note: if X>0 & 0/X=error then this code won't work and the 9/28/17 12:25 (12 lines) code post will be necessary to use. if X>0 & 0/X=0 then this code should still work.

Here I believe is a solution in theory to the potential error caused by zero division and division by zero in the control loop algorithm:

-----------------------------------

K= 90 = Desired Efficiency % Setting

L= 500 = Desired Min Watts Available Setting

P= 4500 = Desired Max Watts Available Setting

M= 100 = Throttle % Setting (min value: 0.000001) <------Negligible minimum value, yet always M>0 (for 0% throttle)

G= 48.2 = Battery Voltage

F= 0.025 = Winding Resistance Ohms

D= 16.94 = Back EMF Voltage (min value: 0.000001) <------Negligible minimum value, yet always D>0 (for standstill)

Y= 120 = Max Motor Amps

Z= 95 = Max Duty Cycle %

N= XX.XXX = Desired Full Throttle Wattage

C= XX.XXX = Duty Cycle %

Where:

N=L

&

if D>((sqrt(F)*K*sqrt(L))/(10*sqrt(100-K))) then N=(-1)*((100*(D^2)*(K-100))/(F*(K^2)))

&

if N>P then N=P

&

if ((1/10)*((sqrt((25*(D^2))+(F*M*N))/F)-((5*D)/F)))>Y then C=(100*((Y*F)+D))/G

&

if ((1/10)*((sqrt((25*(D^2))+(F*M*N))/F)-((5*D)/F)))<=Y then C=10*((sqrt((25*(D^2))+(F*M*N))/G)+((5*D)/G))

&

if C>Z then C=Z

&

repeat

Therefore:

M= 100% = Throttle % Setting <------ Wildly Dynamic Variable

K= 90% = Desired Efficiency % Setting <------ Adjustable Static Variable

L= 500w = Desired Min Watts Available Setting <------ Adjustable Static Variable

P= 4500w = Desired Max Watts Available Setting <------ Adjustable Static Variable

G= 48.2v = Battery Voltage <------ Wildly Dynamic Variable

D= 16.94v = Back EMF Voltage <------ Wildly Dynamic Variable

F= 0.025ohm = Winding Resistance <------ Adjustable Static Variable

Y= 120a = Max Motor Amps <------ Adjustable Static Variable

Z= 95% = Max Duty Cycle % <------ Adjustable Static Variable

N= 1417.10w = Desired Full Throttle Wattage <------ Wildly Dynamic Variable

C= 39.049% = Duty Cycle <------ Wildly Dynamic Variable

Total: (5) Wildly Dynamic Variables & (6) Adjustable Static Variables

----------------------------------

Simply in theory to avoid mathematical logical errors as a result of dividing zero by another number or dividing a number by 0, we must define a negligible but greater than 0 minimum value for the throttle % and back emf voltage variables when inputting them into the control loop algorithm.

The best analogy I can make is to traditional gas powered cars when we release the brake pedal at a green light, but before we manage to push down on the gas pedal, the engine is supplying a small (and in this case minuscule) amount of torque to the wheels at "0% throttle & standstill."