validating firing order length

This commit is contained in:
rusefi 2017-03-23 22:01:10 -04:00
parent 59032fec07
commit 3648a1f651
4 changed files with 64 additions and 10 deletions

View File

@ -1698,8 +1698,8 @@ typedef enum {
CUSTOM_OBD_INJECTION_NO_PIN_ASSIGNED = 6020, CUSTOM_OBD_INJECTION_NO_PIN_ASSIGNED = 6020,
CUSTOM_OBD_UNEXPECTED_INJECTION_MODE = 6021, CUSTOM_OBD_UNEXPECTED_INJECTION_MODE = 6021,
CUSTOM_OBD_ANGLE_CONSTRAINT_VIOLATION = 6022, CUSTOM_OBD_ANGLE_CONSTRAINT_VIOLATION = 6022,
CUSTOM_OBD_23 = 6023, CUSTOM_OBD_UNKNOWN_FIRING_ORDER = 6023,
CUSTOM_OBD_24 = 6024, CUSTOM_OBD_WRONG_FIRING_ORDER = 6024,
CUSTOM_OBD_25 = 6025, CUSTOM_OBD_25 = 6025,
CUSTOM_OBD_26 = 6026, CUSTOM_OBD_26 = 6026,
CUSTOM_UNEXPECTED_ENGINE_TYPE = 6027, CUSTOM_UNEXPECTED_ENGINE_TYPE = 6027,

View File

@ -134,7 +134,7 @@ bool FuelSchedule::addFuelEventsForCylinder(int i DECLARE_ENGINE_PARAMETER_S) {
if (mode == IM_SIMULTANEOUS) { if (mode == IM_SIMULTANEOUS) {
index = 0; index = 0;
} else if (mode == IM_SEQUENTIAL) { } else if (mode == IM_SEQUENTIAL) {
index = getCylinderId(engineConfiguration->specs.firingOrder, i) - 1; index = getCylinderId(i PASS_ENGINE_PARAMETER) - 1;
} else if (mode == IM_BATCH) { } else if (mode == IM_BATCH) {
// does not look exactly right, not too consistent with IM_SEQUENTIAL // does not look exactly right, not too consistent with IM_SEQUENTIAL
index = i % (engineConfiguration->specs.cylindersCount / 2); index = i % (engineConfiguration->specs.cylindersCount / 2);
@ -320,13 +320,67 @@ static int order_1_10_9_4_3_6_5_8_7_2[] = {1, 10, 9, 4, 3, 6, 5, 8, 7, 2};
// 12 cyliner // 12 cyliner
static int order_1_7_5_11_3_9_6_12_2_8_4_10[] = {1, 7, 5, 11, 3, 9, 6, 12, 2, 8, 4, 10}; static int order_1_7_5_11_3_9_6_12_2_8_4_10[] = {1, 7, 5, 11, 3, 9, 6, 12, 2, 8, 4, 10};
static int getFiringOrderLength(DECLARE_ENGINE_PARAMETER_F) {
switch (CONFIG(specs.firingOrder)) {
case FO_1:
return 1;
// 2 cylinder
case FO_1_2:
return 2;
// 3 cylinder
case FO_1_2_3:
return 3;
// 4 cylinder
case FO_1_3_4_2:
case FO_1_2_4_3:
case FO_1_3_2_4:
return 4;
// 5 cylinder
case FO_1_2_4_5_3:
return 5;
// 6 cylinder
case FO_1_5_3_6_2_4:
case FO_1_4_2_5_3_6:
case FO_1_2_3_4_5_6:
case FO_1_6_3_2_5_4:
return 6;
// 8 cylinder
case FO_1_8_4_3_6_5_7_2:
case FO_1_8_7_2_6_5_4_3:
case FO_1_5_4_2_6_3_7_8:
return 8;
// 10 cylinder
case FO_1_10_9_4_3_6_5_8_7_2:
return 10;
// 12 cylinder
case FO_1_7_5_11_3_9_6_12_2_8_4_10:
return 12;
default:
warning(CUSTOM_OBD_UNKNOWN_FIRING_ORDER, "getCylinderId not supported for %d", CONFIG(specs.firingOrder));
}
return 1;
}
/** /**
* @param index from zero to cylindersCount - 1 * @param index from zero to cylindersCount - 1
* @return cylinderId from one to cylindersCount * @return cylinderId from one to cylindersCount
*/ */
int getCylinderId(firing_order_e firingOrder, int index) { int getCylinderId(int index DECLARE_ENGINE_PARAMETER_S) {
switch (firingOrder) { const int foLength = getFiringOrderLength(PASS_ENGINE_PARAMETER);
if (engineConfiguration->specs.cylindersCount != foLength) {
warning(CUSTOM_OBD_WRONG_FIRING_ORDER, "Wrong firing order %d/%d", engineConfiguration->specs.cylindersCount, foLength);
return 1;
}
switch (CONFIG(specs.firingOrder)) {
case FO_1: case FO_1:
return 1; return 1;
// 2 cylinder // 2 cylinder
@ -373,7 +427,7 @@ int getCylinderId(firing_order_e firingOrder, int index) {
return order_1_7_5_11_3_9_6_12_2_8_4_10[index]; return order_1_7_5_11_3_9_6_12_2_8_4_10[index];
default: default:
warning(CUSTOM_OBD_23, "getCylinderId not supported for %d", firingOrder); warning(CUSTOM_OBD_UNKNOWN_FIRING_ORDER, "getCylinderId not supported for %d", CONFIG(specs.firingOrder));
} }
return 1; return 1;
} }
@ -392,7 +446,7 @@ static int getIgnitionPinForIndex(int i DECLARE_ENGINE_PARAMETER_S) {
break; break;
default: default:
warning(CUSTOM_OBD_24, "unsupported ignitionMode %d in initializeIgnitionActions()", engineConfiguration->ignitionMode); warning(CUSTOM_OBD_25, "unsupported ignitionMode %d in initializeIgnitionActions()", engineConfiguration->ignitionMode);
return 0; return 0;
} }
} }

View File

@ -69,7 +69,7 @@ float getEngineLoadT(DECLARE_ENGINE_PARAMETER_F);
floatms_t getSparkDwell(int rpm DECLARE_ENGINE_PARAMETER_S); floatms_t getSparkDwell(int rpm DECLARE_ENGINE_PARAMETER_S);
int getCylinderId(firing_order_e firingOrder, int index); int getCylinderId(int index DECLARE_ENGINE_PARAMETER_S);
void setFuelRpmBin(float from, float to DECLARE_ENGINE_PARAMETER_S); void setFuelRpmBin(float from, float to DECLARE_ENGINE_PARAMETER_S);
void setFuelLoadBin(float from, float to DECLARE_ENGINE_PARAMETER_S); void setFuelLoadBin(float from, float to DECLARE_ENGINE_PARAMETER_S);

View File

@ -223,13 +223,13 @@ void prepareIgnitionSchedule(IgnitionEvent *event DECLARE_ENGINE_PARAMETER_S) {
// change of sign here from 'before TDC' to 'after TDC' // change of sign here from 'before TDC' to 'after TDC'
const angle_t localAdvance = -ENGINE(engineState.timingAdvance) + ENGINE(angleExtra[event->cylinderIndex]) + CONFIG(timing_offset_cylinder[event->cylinderIndex]); const angle_t localAdvance = -ENGINE(engineState.timingAdvance) + ENGINE(angleExtra[event->cylinderIndex]) + CONFIG(timing_offset_cylinder[event->cylinderIndex]);
const int index = ENGINE(ignitionPin[event->cylinderIndex]); const int index = ENGINE(ignitionPin[event->cylinderIndex]);
const int coilIndex = ID2INDEX(getCylinderId(CONFIG(specs.firingOrder), index)); const int coilIndex = ID2INDEX(getCylinderId(index PASS_ENGINE_PARAMETER));
IgnitionOutputPin *output = &enginePins.coils[coilIndex]; IgnitionOutputPin *output = &enginePins.coils[coilIndex];
IgnitionOutputPin *secondOutput; IgnitionOutputPin *secondOutput;
if (CONFIG(ignitionMode) == IM_WASTED_SPARK && CONFIG(twoWireBatchIgnition)) { if (CONFIG(ignitionMode) == IM_WASTED_SPARK && CONFIG(twoWireBatchIgnition)) {
int secondIndex = index + CONFIG(specs.cylindersCount) / 2; int secondIndex = index + CONFIG(specs.cylindersCount) / 2;
int secondCoilIndex = ID2INDEX(getCylinderId(CONFIG(specs.firingOrder), secondIndex)); int secondCoilIndex = ID2INDEX(getCylinderId(secondIndex PASS_ENGINE_PARAMETER));
secondOutput = &enginePins.coils[secondCoilIndex]; secondOutput = &enginePins.coils[secondCoilIndex];
assertPinAssigned(secondOutput); assertPinAssigned(secondOutput);
} else { } else {