Skip to content

Commit

Permalink
change to log base timing
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed May 31, 2023
1 parent 32882c6 commit 41339c5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
4 changes: 0 additions & 4 deletions firmware/console/status_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,6 @@ static void updateFuelInfo() {
}

static void updateIgnition(int rpm) {
float timing = engine->engineState.timingAdvance[0];
// that's weird logic. also seems broken for two stroke?
engine->outputChannels.ignitionAdvance = timing > FOUR_STROKE_CYCLE_DURATION / 2 ? timing - FOUR_STROKE_CYCLE_DURATION : timing;

engine->outputChannels.coilDutyCycle = getCoilDutyCycle(rpm);

engine->outputChannels.knockCount = engine->module<KnockController>()->getKnockCount();
Expand Down
3 changes: 3 additions & 0 deletions firmware/controllers/algo/engine2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ void EngineState::periodicFastCallback() {
float ignitionLoad = getIgnitionLoad();
float advance = getAdvance(rpm, ignitionLoad) * engine->ignitionState.luaTimingMult + engine->ignitionState.luaTimingAdd;

// that's weird logic. also seems broken for two stroke?
engine->outputChannels.ignitionAdvance = (float)(advance > FOUR_STROKE_CYCLE_DURATION / 2 ? advance - FOUR_STROKE_CYCLE_DURATION : advance);

// compute per-bank fueling
for (size_t i = 0; i < STFT_BANK_COUNT; i++) {
float corr = clResult.banks[i];
Expand Down
22 changes: 13 additions & 9 deletions firmware/controllers/engine_cycle/spark_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,30 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_
// 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 = getEngineState()->timingAdvance[event->cylinderNumber]
// Pull any extra timing for knock retard
- engine->module<KnockController>()->getKnockRetard();

// TODO: Log "true" per-cylinder timing here #76
//engine->outputChannels......[event->cylinderNumber] = finalIgnitionTiming;

angle_t sparkAngle =
// Negate because timing *before* TDC, and we schedule *after* TDC
- getEngineState()->timingAdvance[event->cylinderNumber]
- finalIgnitionTiming
// Offset by this cylinder's position in the cycle
+ getCylinderAngle(event->cylinderIndex, event->cylinderNumber)
// Pull any extra timing for knock retard
+ engine->module<KnockController>()->getKnockRetard();
+ getCylinderAngle(event->cylinderIndex, event->cylinderNumber);

efiAssertVoid(ObdCode::CUSTOM_SPARK_ANGLE_1, !cisnan(sparkAngle), "sparkAngle#1");
wrapAngle2(sparkAngle, "findAngle#2", ObdCode::CUSTOM_ERR_6550, getEngineCycle(getEngineRotationState()->getOperationMode()));
event->sparkAngle = sparkAngle;

auto ignitionMode = getCurrentIgnitionMode();
engine->outputChannels.currentIgnitionMode = static_cast<uint8_t>(ignitionMode);

const int index = getIgnitionPinForIndex(event->cylinderIndex, ignitionMode);
const int coilIndex = ID2INDEX(getCylinderId(index));
IgnitionOutputPin *output = &enginePins.coils[coilIndex];

event->outputs[0] = &enginePins.coils[coilIndex];
IgnitionOutputPin *secondOutput;

// If wasted spark, find the paired coil in addition to "main" output for this cylinder
Expand All @@ -108,11 +115,8 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_
secondOutput = nullptr;
}

event->outputs[0] = output;
event->outputs[1] = secondOutput;

wrapAngle2(sparkAngle, "findAngle#2", ObdCode::CUSTOM_ERR_6550, getEngineCycle(getEngineRotationState()->getOperationMode()));
event->sparkAngle = sparkAngle;
// Stash which cylinder we're scheduling so that knock sensing knows which
// cylinder just fired
event->cylinderNumber = coilIndex;
Expand Down
2 changes: 1 addition & 1 deletion firmware/integration/rusefi_config_shared.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
#define GAUGE_NAME_LAMBDA2 "Lambda 2"
#define GAUGE_NAME_IAC "Idle: Position"

#define GAUGE_NAME_TIMING_ADVANCE "Ign: Timing"
#define GAUGE_NAME_TIMING_ADVANCE "Ign: Timing Base"
#define GAUGE_NAME_DWELL_DUTY "Ign: Coil duty cycle"
#define GAUGE_COIL_DWELL_TIME "Ign: Dwell"
#define GAUGE_NAME_IGNITION_LOAD "Ign: Load"
Expand Down

0 comments on commit 41339c5

Please sign in to comment.