Skip to content

Commit

Permalink
use real cylinder number instead of mislabeled coil number
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Jan 18, 2025
1 parent a99251d commit 7ff6ece
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions firmware/controllers/engine_cycle/spark_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ static int getIgnitionPinForIndex(int cylinderIndex, ignition_mode_e ignitionMod
static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_t sparkDwell, IgnitionEvent *event) {
// todo: clean up this implementation? does not look too nice as is.

const int realCylinderNumber = getCylinderNumberAtIndex(event->cylinderIndex);

// let's save planned duration so that we can later compare it with reality
event->sparkDwell = sparkDwell;

// Compute the final ignition timing including all "late" adjustments
angle_t finalIgnitionTiming = engine->cylinders[event->cylinderNumber].getIgnitionTimingBtdc()
angle_t finalIgnitionTiming = engine->cylinders[realCylinderNumber].getIgnitionTimingBtdc()
// Pull any extra timing for knock retard
- engine->module<KnockController>()->getKnockRetard();

Expand All @@ -82,7 +84,7 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_
// maximumIgnitionTiming limits maximum advance
finalIgnitionTiming = clampF(engineConfiguration->minimumIgnitionTiming, finalIgnitionTiming, engineConfiguration->maximumIgnitionTiming);

engine->outputChannels.ignitionAdvanceCyl[event->cylinderNumber] = finalIgnitionTiming;
engine->outputChannels.ignitionAdvanceCyl[realCylinderNumber] = finalIgnitionTiming;

angle_t sparkAngle =
// Negate because timing *before* TDC, and we schedule *after* TDC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TEST(OddFireRunningMode, hd) {
eth.setTriggerType(trigger_type_e::TT_ONE);
// end of configuration

// send fake crank signal events so that trigger handler schedules actuators
// send fake crank signal events so that ignition events are updated
eth.fireTriggerEvents2(2 /* count */ , 60 /* ms */);
LimpState limitedSparkState = getLimpManager()->allowIgnition();
ASSERT_TRUE(limitedSparkState.value);
Expand All @@ -46,4 +46,7 @@ TEST(OddFireRunningMode, hd) {

angle_t expectedAngle7 = -180 + cylinderOne - timing;
eth.assertEvent5("spark down#5", 5, (void*)fireSparkAndPrepareNextSchedule, eth.angleToTimeUs(expectedAngle7));

EXPECT_EQ(engine->ignitionEvents.elements[0].sparkAngle, 18);
EXPECT_EQ(engine->ignitionEvents.elements[1].sparkAngle, 198);
}

0 comments on commit 7ff6ece

Please sign in to comment.