wow we have two separate per-cylinder trims?! fix #5237

refactoring: bringing two offsets much closer together, no change in overall logic
This commit is contained in:
Andrey 2023-04-12 15:04:04 -04:00
parent d57c7293f3
commit 588bf77492
7 changed files with 14 additions and 17 deletions

View File

@ -194,9 +194,12 @@ angle_t getAdvance(int rpm, float engineLoad) {
#endif
}
angle_t getCylinderIgnitionTrim(size_t cylinderNumber, int rpm, float ignitionLoad) {
// wow we have two separate per-cylinder trims?! #5237
return interpolate3d(
angle_t getCombinedCylinderIgnitionTrim(size_t cylinderNumber, int rpm, float ignitionLoad) {
// we have two separate per-cylinder trims, that's a feature
// Plus or minus any adjustment if this is an odd-fire engine
auto adjustment = engineConfiguration->timing_offset_cylinder[cylinderNumber];
return adjustment + interpolate3d(
config->ignTrims[cylinderNumber].table,
config->ignTrimLoadBins, ignitionLoad,
config->ignTrimRpmBins, rpm

View File

@ -10,7 +10,7 @@
#pragma once
angle_t getAdvance(int rpm, float engineLoad);
angle_t getCylinderIgnitionTrim(size_t cylinderNumber, int rpm, float ignitionLoad);
angle_t getCombinedCylinderIgnitionTrim(size_t cylinderNumber, int rpm, float ignitionLoad);
/**
* this method is used to build default advance map
*/

View File

@ -181,7 +181,7 @@ void EngineState::periodicFastCallback() {
// Apply both per-bank and per-cylinder trims
engine->engineState.injectionMass[i] = injectionMass * bankTrim * cylinderTrim;
timingAdvance[i] = advance + getCylinderIgnitionTrim(i, rpm, ignitionLoad);
timingAdvance[i] = advance + getCombinedCylinderIgnitionTrim(i, rpm, ignitionLoad);
}
// TODO: calculate me from a table!

View File

@ -99,7 +99,7 @@ expected<float> InjectionEvent::computeInjectionAngle(int cylinderIndex) const {
assertAngleRange(openingAngle, "openingAngle_r", CUSTOM_ERR_6554);
// Convert from cylinder-relative to cylinder-1-relative
openingAngle += getCylinderAngle(cylinderIndex, cylinderNumber);
openingAngle += getPerCylinderFiringOrderOffset(cylinderIndex, cylinderNumber);
efiAssert(CUSTOM_ERR_ASSERT, !cisnan(openingAngle), "findAngle#3", false);
assertAngleRange(openingAngle, "findAngle#a33", CUSTOM_ERR_6544);

View File

@ -102,7 +102,7 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_
// Negate because timing *before* TDC, and we schedule *after* TDC
- getEngineState()->timingAdvance[event->cylinderNumber]
// Offset by this cylinder's position in the cycle
+ getCylinderAngle(event->cylinderIndex, event->cylinderNumber)
+ getPerCylinderFiringOrderOffset(event->cylinderIndex, event->cylinderNumber)
// Pull any extra timing for knock retard
+ engine->module<KnockController>()->getKnockRetard()
// Degrees of timing REMOVED from actual timing during soft RPM limit window

View File

@ -418,20 +418,14 @@ void prepareOutputSignals() {
engine->injectionEvents.invalidate();
}
angle_t getCylinderAngle(uint8_t cylinderIndex, uint8_t cylinderNumber) {
angle_t getPerCylinderFiringOrderOffset(uint8_t cylinderIndex, uint8_t cylinderNumber) {
// base = position of this cylinder in the firing order.
// We get a cylinder every n-th of an engine cycle where N is the number of cylinders
auto firingOrderOffset = engine->engineState.engineCycle * cylinderIndex / engineConfiguration->specs.cylindersCount;
// Plus or minus any adjustment if this is an odd-fire engine
// wow we have two separate per-cylinder trims?! #5237
auto adjustment = engineConfiguration->timing_offset_cylinder[cylinderNumber];
assertAngleRange(firingOrderOffset, "getPerCylinderFiringOrderOffset", CUSTOM_ERR_6566);
auto result = firingOrderOffset + adjustment;
assertAngleRange(result, "getCylinderAngle", CUSTOM_ERR_6566);
return result;
return firingOrderOffset;
}
void setTimingRpmBin(float from, float to) {

View File

@ -66,7 +66,7 @@ void setSingleCoilDwell();
* Cylinder number is used for per-cylinder adjustment, if you have
* an odd-fire engine (v-twin, V10, some v6, etc)
*/
angle_t getCylinderAngle(uint8_t cylinderIndex, uint8_t cylinderNumber);
angle_t getPerCylinderFiringOrderOffset(uint8_t cylinderIndex, uint8_t cylinderNumber);
// Table blending helpers
struct BlendResult {