simplify cylinder phasing (#3650)

This commit is contained in:
Matthew Kennedy 2021-12-05 07:46:35 -08:00 committed by GitHub
parent 3b1b5c085e
commit 555a8d5f43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 18 deletions

View File

@ -330,11 +330,6 @@ public:
void resetEngineSnifferIfInTestMode();
/**
* pre-calculated offset for given sequence index within engine cycle
* (not cylinder ID)
*/
angle_t ignitionPositionWithinEngineCycle[MAX_CYLINDER_COUNT];
/**
* pre-calculated reference to which output pin should be used for
* given sequence index within engine cycle

View File

@ -107,9 +107,7 @@ bool FuelSchedule::addFuelEventsForCylinder(int i ) {
warning(CUSTOM_OBD_INJECTION_NO_PIN_ASSIGNED, "no_pin_inj #%s", output->name);
}
angle_t ignitionPositionWithinEngineCycle = engine->ignitionPositionWithinEngineCycle[i];
float angle = baseAngle + ignitionPositionWithinEngineCycle;
float angle = baseAngle + getCylinderAngle(i, ev->cylinderNumber);
if (TRIGGER_WAVEFORM(getSize()) < 1) {
warning(CUSTOM_ERR_NOT_INITIALIZED_TRIGGER, "uninitialized TriggerWaveform");

View File

@ -73,12 +73,14 @@ static void prepareCylinderIgnitionSchedule(angle_t dwellAngleDuration, floatms_
// let's save planned duration so that we can later compare it with reality
event->sparkDwell = sparkDwell;
// change of sign here from 'before TDC' to 'after TDC'
angle_t ignitionPositionWithinEngineCycle = engine->ignitionPositionWithinEngineCycle[event->cylinderIndex];
assertAngleRange(ignitionPositionWithinEngineCycle, "aPWEC", CUSTOM_ERR_6566);
// this correction is usually zero (not used)
float perCylinderCorrection = engineConfiguration->timing_offset_cylinder[event->cylinderIndex];
const angle_t sparkAngle = -engine->engineState.timingAdvance + engine->knockController.getKnockRetard() + ignitionPositionWithinEngineCycle + perCylinderCorrection;
const angle_t sparkAngle =
// Negate because timing *before* TDC, and we schedule *after* TDC
- engine->engineState.timingAdvance
// Offset by this cylinder's position in the cycle
+ getCylinderAngle(event->cylinderIndex, event->cylinderNumber)
// Pull any extra timing for knock retard
+ engine->knockController.getKnockRetard();
efiAssertVoid(CUSTOM_SPARK_ANGLE_9, !cisnan(sparkAngle), "findAngle#9");
efiAssertVoid(CUSTOM_SPARK_ANGLE_1, !cisnan(sparkAngle), "sparkAngle#1");

View File

@ -440,10 +440,6 @@ void prepareOutputSignals() {
}
#endif /* EFI_UNIT_TEST */
for (size_t i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
engine->ignitionPositionWithinEngineCycle[i] = engine->engineCycle * i / engineConfiguration->specs.cylindersCount;
}
prepareIgnitionPinIndices(engineConfiguration->ignitionMode);
TRIGGER_WAVEFORM(prepareShape(&engine->triggerCentral.triggerFormDetails));
@ -452,6 +448,21 @@ void prepareOutputSignals() {
engine->injectionEvents.invalidate();
}
angle_t getCylinderAngle(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 base = engine->engineCycle * cylinderIndex / engineConfiguration->specs.cylindersCount;
// Plus or minus any adjustment if this is an odd-fire engine
auto adjustment = engineConfiguration->timing_offset_cylinder[cylinderNumber];
auto result = base + adjustment;
assertAngleRange(result, "getCylinderAngle", CUSTOM_ERR_6566);
return result;
}
void setTimingRpmBin(float from, float to) {
setRpmBin(config->ignitionRpmBins, IGN_RPM_COUNT, from, to);
}

View File

@ -62,3 +62,11 @@ void setSingleCoilDwell();
// while for toothed wheels user would have to provide a value
#define tdcPosition() \
(TRIGGER_WAVEFORM(tdcPosition) + engineConfiguration->globalTriggerAngleOffset)
/** Gets phase offset for a particular cylinder's ID and number
* For example on 4 cylinder engine with firing order 1-3-4-2, this
* returns 0-180-360-540 for index 0-1-2-3
* 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);