2014-01-07 00:02:00 -08:00
byte correctionsTotal ( )
{
2014-05-06 04:07:49 -07:00
int sumCorrections = 100 ;
sumCorrections = div ( ( sumCorrections * correctionWUE ( ) ) , 100 ) . quot ;
sumCorrections = div ( ( sumCorrections * correctionASE ( ) ) , 100 ) . quot ;
sumCorrections = div ( ( sumCorrections * correctionAccel ( ) ) , 100 ) . quot ;
sumCorrections = div ( ( sumCorrections * correctionFloodClear ( ) ) , 100 ) . quot ;
2014-01-07 00:02:00 -08:00
return sumCorrections ;
}
byte correctionWUE ( )
{
2014-05-08 06:01:36 -07:00
//Possibly reduce the frequency this runs at (Costs about 50 loops per second)
return 100 + table2D_getValue ( WUETable , currentStatus . coolant ) ;
2014-01-07 00:02:00 -08:00
}
byte correctionASE ( )
{
2014-01-29 21:28:21 -08:00
if ( currentStatus . runSecs < configPage1 . aseCount )
{
2014-01-29 21:56:25 -08:00
BIT_SET ( currentStatus . engine , 3 ) ; //Mark ASE as active.
2014-01-29 21:28:21 -08:00
return configPage1 . asePct ;
}
2014-05-06 04:07:49 -07:00
BIT_CLEAR ( currentStatus . engine , 3 ) ; //Mark ASE as inactive.
return 100 ;
2014-01-29 21:56:25 -08:00
2014-01-29 21:28:21 -08:00
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 ( )
{
2014-06-05 18:29:43 -07:00
int rateOfChange = ldiv ( 1000000 , ( currentLoopTime - previousLoopTime ) ) . quot * ( currentStatus . TPS - currentStatus . TPSlast ) ; //This is the % per second that the TPS has moved
2014-05-08 06:01:36 -07:00
//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
2014-05-06 04:07:49 -07:00
if ( rateOfChange > configPage1 . tpsThresh )
{
2014-05-07 05:55:15 -07:00
return 100 + table2D_getValue ( taeTable , currentStatus . tpsDOT ) ;
2014-05-06 04:07:49 -07:00
}
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
}