speeduino/corrections.ino

80 lines
2.6 KiB
Arduino
Raw Normal View History

2014-01-07 00:02:00 -08:00
byte correctionsTotal()
{
int sumCorrections = 100;
byte result; //temporary variable to store the result of each corrections function
//As the 'normal' case will be for each function to return 100, we only perform the division operation if the returned result is not equal to that
result = correctionWUE();
if (result != 100) { sumCorrections = div((sumCorrections * result), 100).quot; }
result = correctionASE();
if (result != 100) { sumCorrections = div((sumCorrections * result), 100).quot; }
result = correctionAccel();
//if (result != 100) { sumCorrections = div((sumCorrections * result), 100).quot; }
result = correctionFloodClear();
if (result != 100) { sumCorrections = div((sumCorrections * result), 100).quot; }
2014-09-20 15:46:04 -07:00
return (byte)sumCorrections;
2014-01-07 00:02:00 -08:00
}
byte correctionWUE()
{
//Possibly reduce the frequency this runs at (Costs about 50 loops per second)
if (currentStatus.coolant > (WUETable.axisX[9] - CALIBRATION_TEMPERATURE_OFFSET)) { return 100; } //This prevents us doing the 2D lookup if we're already up to temp
2015-01-18 14:10:01 -08:00
return table2D_getValue(WUETable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET);
2014-01-07 00:02:00 -08:00
}
byte correctionASE()
{
if (currentStatus.runSecs < configPage1.aseCount)
{
2014-12-23 15:25:51 -08:00
BIT_SET(currentStatus.engine, BIT_ENGINE_ASE); //Mark ASE as active.
return 100 + configPage1.asePct;
}
2014-12-23 15:25:51 -08:00
BIT_CLEAR(currentStatus.engine, BIT_ENGINE_ASE); //Mark ASE as inactive.
return 100;
2014-01-07 00:02:00 -08:00
}
2014-02-17 02:54:28 -08:00
/*
TPS based acceleration enrichment
Calculates the % change of the throttle over time (%/second) and performs a lookup based on this
*/
2014-01-07 00:02:00 -08:00
byte correctionAccel()
{
int rateOfChange = ldiv(1000000, (currentLoopTime - previousLoopTime)).quot * (currentStatus.TPS - currentStatus.TPSlast); //This is the % per second that the TPS has moved
//int rateOfChange = div( (1000000 * (currentStatus.TPS - currentStatus.TPSlast)), (currentLoopTime - previousLoopTime)).quot; //This is the % per second that the TPS has moved
currentStatus.tpsDOT = div(rateOfChange, 10).quot;
2014-01-07 00:02:00 -08:00
if (rateOfChange > configPage1.tpsThresh)
{
return 100 + table2D_getValue(taeTable, currentStatus.tpsDOT);
}
return 100;
}
/*
Simple check to see whether we are cranking with the TPS above the flood clear threshold
This function always returns either 100 or 0
*/
byte correctionFloodClear()
{
if(BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK))
{
//Engine is currently cranking, check what the TPS is
if(currentStatus.TPS >= configPage2.floodClear)
{
//Engine is cranking and TPS is above threshold. Cut all fuel
return 0;
}
}
return 100;
2014-01-07 00:02:00 -08:00
}