Skip to content

Commit

Permalink
wow, it's easy to support odd-fire too
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Aug 31, 2024
1 parent b23a6f8 commit e755e4b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions firmware/controllers/algo/engine_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class EngineState : public engine_state_s {
*/
angle_t engineCycle;

bool useOddFireWastedSpark = false;

/**
* this is based on sensorChartMode and sensorSnifferRpmThreshold settings
*/
Expand Down
9 changes: 4 additions & 5 deletions firmware/controllers/engine_cycle/spark_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_

auto ignitionMode = getCurrentIgnitionMode();

// On an odd cylinder wasted spark engine, map outputs as if in sequential.
// On an odd cylinder (or odd fire) wasted spark engine, map outputs as if in sequential.
// During actual scheduling, the events just get scheduled every 360 deg instead
// of every 720 deg.
if (ignitionMode == IM_WASTED_SPARK && (engineConfiguration->cylindersCount % 2 == 1)) {
if (ignitionMode == IM_WASTED_SPARK && engine->engineState.useOddFireWastedSpark) {
ignitionMode = IM_INDIVIDUAL_COILS;
}

Expand Down Expand Up @@ -475,9 +475,8 @@ void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPha
// - current mode is wasted spark
// - four stroke
bool enableOddCylinderWastedSpark =
(engineConfiguration->cylindersCount % 2 == 1)
&& getCurrentIgnitionMode() == IM_WASTED_SPARK
&& engine->engineState.engineCycle == 720;
engine->engineState.useOddFireWastedSpark
&& getCurrentIgnitionMode() == IM_WASTED_SPARK;

if (engine->ignitionEvents.isReady) {
for (size_t i = 0; i < engineConfiguration->cylindersCount; i++) {
Expand Down
15 changes: 14 additions & 1 deletion firmware/controllers/math/engine_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,20 @@ ignition_mode_e getCurrentIgnitionMode() {
* This heavy method is only invoked in case of a configuration change or initialization.
*/
void prepareOutputSignals() {
getEngineState()->engineCycle = getEngineCycle(getEngineRotationState()->getOperationMode());
auto operationMode = getEngineRotationState()->getOperationMode();
getEngineState()->engineCycle = getEngineCycle(operationMode);

bool isOddFire = false;
for (size_t i = 0; i < engineConfiguration->cylindersCount; i++) {
if (engineConfiguration->timing_offset_cylinder[i] != 0) {
isOddFire = true;
break;
}
}

// Use odd fire wasted spark logic if not two stroke, and an odd fire or odd cylinder # engine
getEngineState()->useOddFireWastedSpark = operationMode != TWO_STROKE
&& (isOddFire | (engineConfiguration->cylindersCount % 2 == 1));

#if EFI_UNIT_TEST
if (verboseMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ TEST(ignition, oddCylinderWastedSpark) {
// dwell should start at 15 degrees ATDC and firing at 25 deg ATDC
engine->ignitionState.dwellAngle = 10;
engine->engineState.timingAdvance[0] = -25;
engine->engineState.useOddFireWastedSpark = true;
engineConfiguration->minimumIgnitionTiming = -25;

// expect to schedule the on-phase dwell and spark (not the wasted spark copy)
Expand Down

0 comments on commit e755e4b

Please sign in to comment.