Adition of float spark math
Add some spark math, fix some code too
This commit is contained in:
parent
9134ea70a7
commit
6d8714e035
|
@ -150,6 +150,7 @@ struct statuses {
|
|||
volatile int loopsPerSecond;
|
||||
boolean launchingSoft; //True when in launch control soft limit mode
|
||||
boolean launchingHard; //True when in launch control hard limit mode
|
||||
float adv;
|
||||
int freeRAM;
|
||||
|
||||
//Helpful bitwise operations:
|
||||
|
|
|
@ -201,18 +201,18 @@ void setup()
|
|||
//Need to check early on whether the coil charging is inverted. If this is not set straight away it can cause an unwanted spark at bootup
|
||||
if(configPage2.IgInv == 1) { coilHIGH = LOW, coilLOW = HIGH; }
|
||||
else { coilHIGH = HIGH, coilLOW = LOW; }
|
||||
digitalWrite(pinCoil1, coilLOW);
|
||||
digitalWrite(pinCoil2, coilLOW);
|
||||
digitalWrite(pinCoil3, coilLOW);
|
||||
digitalWrite(pinCoil4, coilLOW);
|
||||
digitalWrite(pinCoil5, coilLOW);
|
||||
endCoil1Charge(); //digitalWrite(pinCoil1, coilLOW);
|
||||
endCoil2Charge(); //digitalWrite(pinCoil2, coilLOW);
|
||||
endCoil3Charge(); //digitalWrite(pinCoil3, coilLOW);
|
||||
endCoil4Charge(); //digitalWrite(pinCoil4, coilLOW);
|
||||
endCoil5Charge(); //digitalWrite(pinCoil5, coilLOW);
|
||||
|
||||
//Similar for injectors, make sure they're turned off
|
||||
digitalWrite(pinInjector1, LOW);
|
||||
digitalWrite(pinInjector2, LOW);
|
||||
digitalWrite(pinInjector3, LOW);
|
||||
digitalWrite(pinInjector4, LOW);
|
||||
digitalWrite(pinInjector5, LOW);
|
||||
closeInjector1(); //digitalWrite(pinInjector1, HIGH);
|
||||
closeInjector2(); //digitalWrite(pinInjector2, HIGH);
|
||||
closeInjector3(); //digitalWrite(pinInjector3, HIGH);
|
||||
closeInjector4(); //digitalWrite(pinInjector4, HIGH);
|
||||
closeInjector5(); //digitalWrite(pinInjector5, HIGH);
|
||||
|
||||
//Set the tacho output default state
|
||||
digitalWrite(pinTachOut, HIGH);
|
||||
|
@ -924,6 +924,7 @@ void loop()
|
|||
currentStatus.VE = get3DTableValue(&fuelTable, currentStatus.MAP, currentStatus.RPM); //Perform lookup into fuel map for RPM vs MAP value
|
||||
currentStatus.PW = PW_SD(req_fuel_uS, currentStatus.VE, currentStatus.MAP, currentStatus.corrections, inj_opentime_uS);
|
||||
currentStatus.advance = get3DTableValue(&ignitionTable, currentStatus.MAP, currentStatus.RPM); //As above, but for ignition advance
|
||||
currentStatus.adv = get3DTableValue2(&ignitionTable, currentStatus.MAP, currentStatus.RPM); //As above, but for ignition advance
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -931,6 +932,7 @@ void loop()
|
|||
currentStatus.VE = get3DTableValue(&fuelTable, currentStatus.TPS, currentStatus.RPM); //Perform lookup into fuel map for RPM vs TPS value
|
||||
currentStatus.PW = PW_AN(req_fuel_uS, currentStatus.VE, currentStatus.TPS, currentStatus.corrections, inj_opentime_uS); //Calculate pulsewidth using the Alpha-N algorithm (in uS)
|
||||
currentStatus.advance = get3DTableValue(&ignitionTable, currentStatus.TPS, currentStatus.RPM); //As above, but for ignition advance
|
||||
currentStatus.adv = get3DTableValue2(&ignitionTable, currentStatus.MAP, currentStatus.RPM); //As above, but for ignition advance
|
||||
}
|
||||
|
||||
//Check for fixed ignition angles
|
||||
|
@ -1450,7 +1452,7 @@ void loop()
|
|||
inline void endCoil4Charge() { digitalWrite(pinCoil4, coilLOW); }
|
||||
|
||||
inline void openInjector5() { digitalWrite(pinInjector5, HIGH); }
|
||||
inline void closeInjector5() { digitalWrite(pinInjector5, LOW); }
|
||||
inline void closeInjector5() { digitalWrite(pinInjector5, LOW); }
|
||||
inline void beginCoil5Charge() { digitalWrite(pinCoil5, coilHIGH); digitalWrite(pinTachOut, LOW); }
|
||||
inline void endCoil5Charge() { digitalWrite(pinCoil5, coilLOW); }
|
||||
|
||||
|
|
46
table.ino
46
table.ino
|
@ -213,7 +213,51 @@ int table2D_getValue(struct table2D *fromTable, int X)
|
|||
}
|
||||
|
||||
|
||||
//This function pulls a value from a 3D table given a target for X and Y coordinates.
|
||||
//It fix a 2D linear interpolation as descibred in: http://www.megamanual.com/v22manual/ve_tuner.pdf
|
||||
float get3DTableValue2(struct table3D *fromTable, int Y, int X)
|
||||
{
|
||||
float m, n, o ,p, q, r;
|
||||
byte xMin, xMax;
|
||||
byte yMin, yMax;
|
||||
|
||||
for (xMin = fromTable->xSize-1; xMin>=0; xMin--) if(X>fromTable->axisX[xMin]) break;
|
||||
for (yMin = fromTable->ySize-1; yMin>=0; yMin--) if(Y>fromTable->axisY[yMin]) break;
|
||||
if (xMin>fromTable->xSize-1) xMin = fromTable->xSize-1; //Overflow protection
|
||||
if (yMin>fromTable->ySize-1) yMin = fromTable->ySize-1; //Overflow protection
|
||||
|
||||
xMax = xMin + 1;
|
||||
yMax = yMin + 1;
|
||||
if (xMax>fromTable->xSize-1) xMax = fromTable->xSize-1; //Overflow protection
|
||||
if (yMax>fromTable->ySize-1) yMax = fromTable->ySize-1; //Overflow protection
|
||||
|
||||
p = float(X-fromTable->axisX[xMin]) / float(fromTable->axisX[xMax] - fromTable->axisX[xMin]);
|
||||
q = float(Y-fromTable->axisY[yMin]) / float(fromTable->axisY[yMax] - fromTable->axisY[yMin]);
|
||||
|
||||
/* On http://www.megamanual.com/v22manual/ve_tuner.pdf the interpolation image is fliped
|
||||
Eg: | ve_turner.pdf | | should be | cause y and x axis is in that order
|
||||
VE(1,1) VE(1,2) VE(2,1) VE(2,2) ^
|
||||
y|
|
||||
|
|
||||
VE(2,1) VE(2,2) VE(1,1) VE(1,2) +------------> x
|
||||
|
||||
At this point we have the 4 corners of the map where the interpolated value will fall in
|
||||
Eg: A=(yMax,xMin) B=(yMax,xMax)
|
||||
|
||||
C=(yMin,xMin) D=(yMin,xMax)
|
||||
*/
|
||||
int A = fromTable->values[yMax][xMin];
|
||||
int B = fromTable->values[yMax][xMax];
|
||||
int C = fromTable->values[yMin][xMin];
|
||||
int D = fromTable->values[yMin][xMax];
|
||||
|
||||
m = (1.0-p) * (1.0-q);
|
||||
n = p * (1-q);
|
||||
o = (1-p) * q;
|
||||
r = p * q;
|
||||
|
||||
return ( (A * m) + (B * n) + (C * o) + (D * r) );
|
||||
}
|
||||
|
||||
//This function pulls a value from a 3D table given a target for X and Y coordinates.
|
||||
//It performs a 2D linear interpolation as descibred in: http://www.megamanual.com/v22manual/ve_tuner.pdf
|
||||
|
@ -358,7 +402,7 @@ int get3DTableValue(struct table3D *fromTable, int Y, int X)
|
|||
int B = fromTable->values[yMin][xMax];
|
||||
int C = fromTable->values[yMax][xMin];
|
||||
int D = fromTable->values[yMax][xMax];
|
||||
|
||||
|
||||
//Create some normalised position values
|
||||
//These are essentially percentages (between 0 and 1) of where the desired value falls between the nearest bins on each axis
|
||||
|
||||
|
|
Loading…
Reference in New Issue