Faster 2nd derive prediction on RPM / crank angle

This commit is contained in:
Josh Stewart 2017-01-27 22:20:38 +11:00
parent 9011c190e0
commit 153aa32fb4
2 changed files with 14 additions and 3 deletions

View File

@ -145,7 +145,7 @@ struct statuses {
long longRPM; long longRPM;
int mapADC; int mapADC;
long MAP; //Has to be a long for PID calcs (Boost control) long MAP; //Has to be a long for PID calcs (Boost control)
int baro; //Barometric pressure is simply the inital MAP reading, taken before the engine is running byte baro; //Barometric pressure is simply the inital MAP reading, taken before the engine is running
byte TPS; //The current TPS reading (0% - 100%) byte TPS; //The current TPS reading (0% - 100%)
byte TPSlast; //The previous TPS reading byte TPSlast; //The previous TPS reading
unsigned long TPS_time; //The time the TPS sample was taken unsigned long TPS_time; //The time the TPS sample was taken
@ -197,7 +197,7 @@ struct statuses {
int freeRAM; int freeRAM;
unsigned int clutchEngagedRPM; unsigned int clutchEngagedRPM;
bool flatShiftingHard; bool flatShiftingHard;
volatile byte startRevolutions = 0; //A counter for how many revolutions have been completed since sync was achieved. volatile byte startRevolutions; //A counter for how many revolutions have been completed since sync was achieved.
//Helpful bitwise operations: //Helpful bitwise operations:
//Useful reference: http://playground.arduino.cc/Code/BitMath //Useful reference: http://playground.arduino.cc/Code/BitMath

View File

@ -252,6 +252,7 @@ void setup()
currentStatus.hasSync = false; currentStatus.hasSync = false;
currentStatus.runSecs = 0; currentStatus.runSecs = 0;
currentStatus.secl = 0; currentStatus.secl = 0;
currentStatus.startRevolutions = 0;
currentStatus.flatShiftingHard = false; currentStatus.flatShiftingHard = false;
currentStatus.launchingHard = false; currentStatus.launchingHard = false;
triggerFilterTime = 0; //Trigger filter time is the shortest possible time (in uS) that there can be between crank teeth (ie at max RPM). Any pulses that occur faster than this time will be disgarded as noise. This is simply a default value, the actual values are set in the setup() functinos of each decoder triggerFilterTime = 0; //Trigger filter time is the shortest possible time (in uS) that there can be between crank teeth (ie at max RPM). Any pulses that occur faster than this time will be disgarded as noise. This is simply a default value, the actual values are set in the setup() functinos of each decoder
@ -978,6 +979,7 @@ void loop()
//We use a 1st Deriv accleration prediction, but only when there is an even spacing between primary sensor teeth //We use a 1st Deriv accleration prediction, but only when there is an even spacing between primary sensor teeth
//Any decoder that has uneven spacing has its triggerToothAngle set to 0 //Any decoder that has uneven spacing has its triggerToothAngle set to 0
if(secondDerivEnabled && toothHistoryIndex >= 3 && currentStatus.RPM < 2000) //toothHistoryIndex must be greater than or equal to 3 as we need the last 3 entries. Currently this mode only runs below 3000 rpm if(secondDerivEnabled && toothHistoryIndex >= 3 && currentStatus.RPM < 2000) //toothHistoryIndex must be greater than or equal to 3 as we need the last 3 entries. Currently this mode only runs below 3000 rpm
//if(true)
{ {
//Only recalculate deltaV if the tooth has changed since last time (DeltaV stays the same until the next tooth) //Only recalculate deltaV if the tooth has changed since last time (DeltaV stays the same until the next tooth)
//if (deltaToothCount != toothCurrentCount) //if (deltaToothCount != toothCurrentCount)
@ -1012,7 +1014,8 @@ void loop()
} }
else else
{ {
timePerDegree = ldiv( 166666L, currentStatus.RPM ).quot; //There is a small amount of rounding in this calculation, however it is less than 0.001 of a uS (Faster as ldiv than / ) long rpm_adjust = ((long)(micros() - toothOneTime) * (long)currentStatus.rpmDOT) / 1000000; //Take into account any likely accleration that has occurred since the last full revolution completed
timePerDegree = ldiv( 166666L, currentStatus.RPM + rpm_adjust).quot; //There is a small amount of rounding in this calculation, however it is less than 0.001 of a uS (Faster as ldiv than / )
} }
//Check that the duty cycle of the chosen pulsewidth isn't too high. This is disabled at cranking //Check that the duty cycle of the chosen pulsewidth isn't too high. This is disabled at cranking
@ -1334,8 +1337,16 @@ void loop()
//if (ignition1StartAngle <= crankAngle && ignition1.schedulesSet == 0) { ignition1StartAngle += CRANK_ANGLE_MAX_IGN; } //if (ignition1StartAngle <= crankAngle && ignition1.schedulesSet == 0) { ignition1StartAngle += CRANK_ANGLE_MAX_IGN; }
if (ignition1StartAngle > crankAngle) if (ignition1StartAngle > crankAngle)
{ {
/*
long some_time = ((unsigned long)(ignition1StartAngle - crankAngle) * (unsigned long)timePerDegree);
long newRPM = (long)(some_time * currentStatus.rpmDOT) / 1000000L;
newRPM = currentStatus.RPM + (newRPM/2);
unsigned long timePerDegree_1 = ldiv( 166666L, newRPM).quot;*/
setIgnitionSchedule1(ign1StartFunction, setIgnitionSchedule1(ign1StartFunction,
((unsigned long)(ignition1StartAngle - crankAngle) * (unsigned long)timePerDegree), ((unsigned long)(ignition1StartAngle - crankAngle) * (unsigned long)timePerDegree),
//some_time -some_accel,
//((unsigned long)((unsigned long)currentStatus.dwell* currentStatus.RPM) / newRPM) + fixedCrankingOverride,
currentStatus.dwell + fixedCrankingOverride, currentStatus.dwell + fixedCrankingOverride,
ign1EndFunction ign1EndFunction
); );