support odd cyl wasted spark

This commit is contained in:
Matthew Kennedy 2024-08-31 01:17:40 -07:00
parent f3f7e5a380
commit f9733eef30
1 changed files with 45 additions and 7 deletions

View File

@ -104,6 +104,14 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_
event->sparkAngle = sparkAngle;
auto ignitionMode = getCurrentIgnitionMode();
// On an odd cylinder 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)) {
ignitionMode = IM_INDIVIDUAL_COILS;
}
engine->outputChannels.currentIgnitionMode = static_cast<uint8_t>(ignitionMode);
const int index = getIgnitionPinForIndex(event->cylinderIndex, ignitionMode);
@ -462,6 +470,14 @@ void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPha
* See initializeIgnitionActions()
*/
// Only apply odd cylinder count wasted logic if:
// - odd cyl count
// - current mode is wasted spark
// - four stroke
bool enableOddCylinderWastedSpark =
(engineConfiguration->cylindersCount % 2 == 1)
&& getCurrentIgnitionMode() == IM_WASTED_SPARK
&& engine->engineState.engineCycle == 720;
// scheduleSimpleMsg(&logger, "eventId spark ", eventIndex);
if (engine->ignitionEvents.isReady) {
@ -469,7 +485,35 @@ void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPha
IgnitionEvent *event = &engine->ignitionEvents.elements[i];
angle_t dwellAngle = event->dwellAngle;
if (!isPhaseInRange(dwellAngle, currentPhase, nextPhase)) {
angle_t sparkAngle = event->sparkAngle;
if (std::isnan(sparkAngle)) {
warning(ObdCode::CUSTOM_ADVANCE_SPARK, "NaN advance");
continue;
}
bool isOddCylWastedEvent = false;
if (enableOddCylinderWastedSpark) {
auto dwellAngleWastedEvent = dwellAngle + 360;
if (dwellAngleWastedEvent > 720) {
dwellAngleWastedEvent -= 720;
}
// Check whether this event hits 360 degrees out from now (ie, wasted spark),
// and if so, twiddle the dwell and spark angles so it happens now instead
isOddCylWastedEvent = isPhaseInRange(dwellAngleWastedEvent, currentPhase, nextPhase);
if (isOddCylWastedEvent) {
dwellAngle = dwellAngleWastedEvent;
sparkAngle += 360;
if (sparkAngle > 720) {
sparkAngle -= 720;
}
}
}
if (!isOddCylWastedEvent && !isPhaseInRange(dwellAngle, currentPhase, nextPhase)) {
continue;
}
@ -494,12 +538,6 @@ void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPha
engine->ALSsoftSparkLimiter.setTargetSkipRatio(ALSSkipRatio);
#endif // EFI_ANTILAG_SYSTEM
angle_t sparkAngle = event->sparkAngle;
if (std::isnan(sparkAngle)) {
warning(ObdCode::CUSTOM_ADVANCE_SPARK, "NaN advance");
continue;
}
scheduleSparkEvent(limitedSpark, event, rpm, dwellMs, dwellAngle, sparkAngle, edgeTimestamp, currentPhase, nextPhase);
}
}