From 41ab29428122cdd0e71060b29c50ad77cec64648 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 1 Feb 2022 16:04:20 -0800 Subject: [PATCH] fix sequential mode cranking (#2919) * fix * use the right enum * do it for fuel too * earlier * s --- firmware/controllers/engine_cycle/fuel_schedule.cpp | 11 +++++++++-- firmware/controllers/engine_cycle/spark_logic.cpp | 7 ++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/firmware/controllers/engine_cycle/fuel_schedule.cpp b/firmware/controllers/engine_cycle/fuel_schedule.cpp index ab9b8ba2a2..827742b019 100644 --- a/firmware/controllers/engine_cycle/fuel_schedule.cpp +++ b/firmware/controllers/engine_cycle/fuel_schedule.cpp @@ -60,11 +60,17 @@ bool FuelSchedule::addFuelEventsForCylinder(int i ) { injection_mode_e mode = engine->getCurrentInjectionMode(); + // We need two outputs if: + // - we are running batch fuel, and have "use two wire batch" enabled + // - running mode is sequential, but cranking mode is batch, so we should run two wire batch while cranking + // (if we didn't, only half of injectors would fire while cranking) + bool isTwoWireBatch = engineConfiguration->twoWireBatchInjection || (engineConfiguration->injectionMode == IM_SEQUENTIAL); + int injectorIndex; if (mode == IM_SIMULTANEOUS || mode == IM_SINGLE_POINT) { // These modes only have one injector injectorIndex = 0; - } else if (mode == IM_SEQUENTIAL || (mode == IM_BATCH && engineConfiguration->twoWireBatchInjection)) { + } else if (mode == IM_SEQUENTIAL || (mode == IM_BATCH && isTwoWireBatch)) { // Map order index -> cylinder index (firing order) injectorIndex = getCylinderId(i) - 1; } else if (mode == IM_BATCH) { @@ -76,7 +82,8 @@ bool FuelSchedule::addFuelEventsForCylinder(int i ) { } InjectorOutputPin *secondOutput; - if (mode == IM_BATCH && engineConfiguration->twoWireBatchInjection) { + + if (mode == IM_BATCH && isTwoWireBatch) { /** * also fire the 2nd half of the injectors so that we can implement a batch mode on individual wires */ diff --git a/firmware/controllers/engine_cycle/spark_logic.cpp b/firmware/controllers/engine_cycle/spark_logic.cpp index 1576f05302..7312beb67d 100644 --- a/firmware/controllers/engine_cycle/spark_logic.cpp +++ b/firmware/controllers/engine_cycle/spark_logic.cpp @@ -89,7 +89,12 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_ IgnitionOutputPin *output = &enginePins.coils[coilIndex]; IgnitionOutputPin *secondOutput; - if (getCurrentIgnitionMode() == IM_WASTED_SPARK && engineConfiguration->twoWireBatchIgnition) { + + // We need two outputs if: + // - we are running wasted spark, and have "two wire" mode enabled + // - We are running sequential mode, but we're cranking, so we should run in two wire wasted mode (not one wire wasted) + bool isTwoWireWasted = engineConfiguration->twoWireBatchIgnition || (engineConfiguration->ignitionMode == IM_INDIVIDUAL_COILS); + if (getCurrentIgnitionMode() == IM_WASTED_SPARK && isTwoWireWasted) { int secondIndex = index + engineConfiguration->specs.cylindersCount / 2; int secondCoilIndex = ID2INDEX(getCylinderId(secondIndex)); secondOutput = &enginePins.coils[secondCoilIndex];