This commit is contained in:
parent
57ebbb1a0b
commit
62b5e87393
|
@ -264,63 +264,6 @@ floatms_t getSparkDwell(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
return dwellMs;
|
||||
}
|
||||
|
||||
/**
|
||||
* this method is only used on initialization
|
||||
*/
|
||||
int TriggerShape::findAngleIndex(float target DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
int engineCycleEventCount = TRIGGER_SHAPE(getLength());
|
||||
|
||||
efiAssert(CUSTOM_ERR_ASSERT, engineCycleEventCount > 0, "engineCycleEventCount", 0);
|
||||
|
||||
uint32_t left = 0;
|
||||
uint32_t right = engineCycleEventCount - 1;
|
||||
|
||||
/**
|
||||
* Let's find the last trigger angle which is less or equal to the desired angle
|
||||
* todo: extract binary search as template method?
|
||||
*/
|
||||
while (left <= right) {
|
||||
int middle = (left + right) / 2;
|
||||
angle_t eventAngle = TRIGGER_SHAPE(eventAngles[middle]);
|
||||
|
||||
if (eventAngle < target) {
|
||||
left = middle + 1;
|
||||
} else if (eventAngle > target) {
|
||||
right = middle - 1;
|
||||
} else {
|
||||
// Values are equal
|
||||
return middle; // Key found
|
||||
}
|
||||
}
|
||||
return left - 1;
|
||||
}
|
||||
|
||||
void TriggerShape::findTriggerPosition(event_trigger_position_s *position, angle_t angleOffset DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
efiAssertVoid(CUSTOM_ERR_6574, !cisnan(angleOffset), "findAngle#1");
|
||||
assertAngleRange(angleOffset, "findAngle#a1", CUSTOM_ERR_6545);
|
||||
|
||||
efiAssertVoid(CUSTOM_ERR_6575, !cisnan(TRIGGER_SHAPE(tdcPosition)), "tdcPos#1")
|
||||
assertAngleRange(TRIGGER_SHAPE(tdcPosition), "tdcPos#a1", CUSTOM_ERR_6546);
|
||||
|
||||
efiAssertVoid(CUSTOM_ERR_6576, !cisnan(CONFIG(globalTriggerAngleOffset)), "tdcPos#2")
|
||||
assertAngleRange(CONFIG(globalTriggerAngleOffset), "tdcPos#a2", CUSTOM_ERR_6547);
|
||||
|
||||
// convert engine cycle angle into trigger cycle angle
|
||||
angleOffset += tdcPosition();
|
||||
efiAssertVoid(CUSTOM_ERR_6577, !cisnan(angleOffset), "findAngle#2");
|
||||
fixAngle(angleOffset, "addFuel#2", CUSTOM_ERR_6555);
|
||||
|
||||
int index = triggerIndexByAngle[(int)angleOffset];
|
||||
angle_t eventAngle = eventAngles[index];
|
||||
if (angleOffset < eventAngle) {
|
||||
warning(CUSTOM_OBD_ANGLE_CONSTRAINT_VIOLATION, "angle constraint violation in findTriggerPosition(): %.2f/%.2f", angleOffset, eventAngle);
|
||||
return;
|
||||
}
|
||||
|
||||
position->eventIndex = index;
|
||||
position->eventAngle = eventAngle;
|
||||
position->angleOffset = angleOffset - eventAngle;
|
||||
}
|
||||
|
||||
static int order_1_2[] = {1, 2};
|
||||
|
||||
|
@ -520,7 +463,7 @@ ignition_mode_e getIgnitionMode(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
void TriggerShape::prepareShape(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
int engineCycleInt = (int) getEngineCycle(CONFIG(operationMode));
|
||||
for (int angle = 0; angle < engineCycleInt; angle++) {
|
||||
int triggerShapeIndex = findAngleIndex(angle PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
int triggerShapeIndex = findAngleIndex(angle);
|
||||
if (engineConfiguration->useOnlyRisingEdgeForTrigger) {
|
||||
// we need even index for front_only mode - so if odd indexes are rounded down
|
||||
triggerShapeIndex = triggerShapeIndex & 0xFFFFFFFE;
|
||||
|
|
|
@ -55,7 +55,7 @@ void initializeMazdaMiataNaShape(TriggerShape *s, bool useOnlyRisingEdgeForTrigg
|
|||
* by alexander-n8hgeg5e
|
||||
* See https://rusefi.com/forum/viewtopic.php?f=5&t=1447
|
||||
*/
|
||||
void initialize_Mazda_Engine_z5_Shape(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
void initialize_Mazda_Engine_z5_Shape(TriggerShape *s) {
|
||||
s->initialize(FOUR_STROKE_CAM_SENSOR, false);
|
||||
/**
|
||||
* My Signal is: 60, 60, 102, 60
|
||||
|
@ -86,7 +86,7 @@ void initialize_Mazda_Engine_z5_Shape(TriggerShape *s DECLARE_ENGINE_PARAMETER_S
|
|||
}
|
||||
|
||||
// TT_MIATA_VVT
|
||||
void initializeMazdaMiataNb2Crank(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
void initializeMazdaMiataNb2Crank(TriggerShape *s) {
|
||||
s->initialize(FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR, false);
|
||||
|
||||
float o = 160;
|
||||
|
@ -100,7 +100,7 @@ void initializeMazdaMiataNb2Crank(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFI
|
|||
s->addEvent720(o + 4 * 140.0f, T_PRIMARY, TV_RISE);
|
||||
}
|
||||
|
||||
static void initializeMazdaMiataNb1ShapeWithOffset(TriggerShape *s, float offset DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
static void initializeMazdaMiataNb1ShapeWithOffset(TriggerShape *s, float offset) {
|
||||
s->initialize(FOUR_STROKE_CAM_SENSOR, true);
|
||||
s->setTriggerSynchronizationGap(0.11f);
|
||||
s->useRiseEdge = false;
|
||||
|
@ -141,15 +141,15 @@ static void initializeMazdaMiataNb1ShapeWithOffset(TriggerShape *s, float offset
|
|||
s->useOnlyPrimaryForSync = true;
|
||||
}
|
||||
|
||||
void initializeMazdaMiataNb1Shape(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
initializeMazdaMiataNb1ShapeWithOffset(s, 0 PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
void initializeMazdaMiataNb1Shape(TriggerShape *s) {
|
||||
initializeMazdaMiataNb1ShapeWithOffset(s, 0);
|
||||
}
|
||||
|
||||
void initializeMazdaMiataVVtTestShape(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
initializeMazdaMiataNb1ShapeWithOffset(s, -22 PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
void initializeMazdaMiataVVtTestShape(TriggerShape *s) {
|
||||
initializeMazdaMiataNb1ShapeWithOffset(s, -22);
|
||||
}
|
||||
|
||||
void configureMazdaProtegeSOHC(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
void configureMazdaProtegeSOHC(TriggerShape *s) {
|
||||
|
||||
// todo: move to into configuration definition s->needSecondTriggerInput = FALSE;
|
||||
|
||||
|
@ -177,7 +177,7 @@ void configureMazdaProtegeSOHC(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX)
|
|||
s->isSynchronizationNeeded = false;
|
||||
}
|
||||
|
||||
void configureMazdaProtegeLx(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
void configureMazdaProtegeLx(TriggerShape *s) {
|
||||
// todo: move to into configuration definition s->needSecondTriggerInput = FALSE;
|
||||
s->initialize(FOUR_STROKE_CAM_SENSOR, true);
|
||||
s->useOnlyPrimaryForSync = true;
|
||||
|
|
|
@ -14,11 +14,11 @@
|
|||
#define MIATA_NA_GAP 1.4930f
|
||||
|
||||
void initializeMazdaMiataNaShape(TriggerShape *s, bool useOnlyRisingEdgeForTrigger);
|
||||
void initializeMazdaMiataNb1Shape(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void initializeMazdaMiataNb2Crank(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void initializeMazdaMiataVVtTestShape(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void configureMazdaProtegeSOHC(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void configureMazdaProtegeLx(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void initialize_Mazda_Engine_z5_Shape(TriggerShape *s DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void initializeMazdaMiataNb1Shape(TriggerShape *s);
|
||||
void initializeMazdaMiataNb2Crank(TriggerShape *s);
|
||||
void initializeMazdaMiataVVtTestShape(TriggerShape *s);
|
||||
void configureMazdaProtegeSOHC(TriggerShape *s);
|
||||
void configureMazdaProtegeLx(TriggerShape *s);
|
||||
void initialize_Mazda_Engine_z5_Shape(TriggerShape *s);
|
||||
|
||||
#endif /* TRIGGER_MAZDA_H_ */
|
||||
|
|
|
@ -183,12 +183,16 @@ void TriggerState::onSynchronizationLost(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
* @param nowNt current time
|
||||
*/
|
||||
void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
bool useOnlyRisingEdgeForTrigger = CONFIG(useOnlyRisingEdgeForTrigger);
|
||||
// todo: use 'triggerShape' instead of TRIGGER_SHAPE in order to decouple this method from engine #635
|
||||
TriggerShape *triggerShape = &ENGINE(triggerCentral.triggerShape);
|
||||
|
||||
efiAssertVoid(CUSTOM_ERR_6640, signal <= SHAFT_3RD_RISING, "unexpected signal");
|
||||
|
||||
trigger_wheel_e triggerWheel = eventIndex[signal];
|
||||
trigger_value_e type = eventType[signal];
|
||||
|
||||
if (!CONFIG(useOnlyRisingEdgeForTrigger) && curSignal == prevSignal) {
|
||||
if (!useOnlyRisingEdgeForTrigger && curSignal == prevSignal) {
|
||||
orderingErrorCounter++;
|
||||
}
|
||||
|
||||
|
@ -250,7 +254,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no
|
|||
|
||||
bool isSynchronizationPoint;
|
||||
|
||||
if (TRIGGER_SHAPE(isSynchronizationNeeded)) {
|
||||
if (triggerShape->isSynchronizationNeeded) {
|
||||
// this is getting a little out of hand, any ideas?
|
||||
|
||||
if (CONFIG(debugMode) == DBG_TRIGGER_SYNC) {
|
||||
|
@ -264,8 +268,8 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no
|
|||
bool isGapCondition[GAP_TRACKING_LENGTH];
|
||||
|
||||
for (int i = 0;i<GAP_TRACKING_LENGTH;i++) {
|
||||
isGapCondition[i] = cisnan(TRIGGER_SHAPE(syncronizationRatioFrom[i])) || (toothDurations[i] > toothDurations[i + 1] * TRIGGER_SHAPE(syncronizationRatioFrom[i])
|
||||
&& toothDurations[i] < toothDurations[i + 1] * TRIGGER_SHAPE(syncronizationRatioTo[i]));
|
||||
isGapCondition[i] = cisnan(triggerShape->syncronizationRatioFrom[i]) || (toothDurations[i] > toothDurations[i + 1] * TRIGGER_SHAPE(syncronizationRatioFrom[i])
|
||||
&& toothDurations[i] < toothDurations[i + 1] * triggerShape->syncronizationRatioTo[i]);
|
||||
}
|
||||
|
||||
bool isSync = isGapCondition[0];
|
||||
|
@ -498,19 +502,19 @@ void TriggerShape::initializeTriggerShape(Logging *logger, bool useOnlyRisingEdg
|
|||
break;
|
||||
|
||||
case TT_MAZDA_MIATA_NB1:
|
||||
initializeMazdaMiataNb1Shape(this PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
initializeMazdaMiataNb1Shape(this);
|
||||
break;
|
||||
|
||||
case TT_MAZDA_MIATA_VVT_TEST:
|
||||
initializeMazdaMiataVVtTestShape(this PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
initializeMazdaMiataVVtTestShape(this);
|
||||
break;
|
||||
|
||||
case TT_MAZDA_Z5:
|
||||
initialize_Mazda_Engine_z5_Shape(this PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
initialize_Mazda_Engine_z5_Shape(this);
|
||||
break;
|
||||
|
||||
case TT_MIATA_VVT:
|
||||
initializeMazdaMiataNb2Crank(this PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
initializeMazdaMiataNb2Crank(this);
|
||||
break;
|
||||
|
||||
case TT_DODGE_NEON_1995:
|
||||
|
@ -543,7 +547,7 @@ void TriggerShape::initializeTriggerShape(Logging *logger, bool useOnlyRisingEdg
|
|||
break;
|
||||
|
||||
case TT_MAZDA_DOHC_1_4:
|
||||
configureMazdaProtegeLx(this PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
configureMazdaProtegeLx(this);
|
||||
break;
|
||||
|
||||
case TT_ONE_PLUS_ONE:
|
||||
|
@ -563,7 +567,7 @@ void TriggerShape::initializeTriggerShape(Logging *logger, bool useOnlyRisingEdg
|
|||
break;
|
||||
|
||||
case TT_MAZDA_SOHC_4:
|
||||
configureMazdaProtegeSOHC(this PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
configureMazdaProtegeSOHC(this);
|
||||
break;
|
||||
|
||||
case TT_MINI_COOPER_R50:
|
||||
|
|
|
@ -449,6 +449,64 @@ void TriggerShape::setTriggerSynchronizationGap3(int gapIndex, float syncRatioFr
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* this method is only used on initialization
|
||||
*/
|
||||
int TriggerShape::findAngleIndex(float target) {
|
||||
int engineCycleEventCount = getLength();
|
||||
|
||||
efiAssert(CUSTOM_ERR_ASSERT, engineCycleEventCount > 0, "engineCycleEventCount", 0);
|
||||
|
||||
uint32_t left = 0;
|
||||
uint32_t right = engineCycleEventCount - 1;
|
||||
|
||||
/**
|
||||
* Let's find the last trigger angle which is less or equal to the desired angle
|
||||
* todo: extract binary search as template method?
|
||||
*/
|
||||
while (left <= right) {
|
||||
int middle = (left + right) / 2;
|
||||
angle_t eventAngle = eventAngles[middle];
|
||||
|
||||
if (eventAngle < target) {
|
||||
left = middle + 1;
|
||||
} else if (eventAngle > target) {
|
||||
right = middle - 1;
|
||||
} else {
|
||||
// Values are equal
|
||||
return middle; // Key found
|
||||
}
|
||||
}
|
||||
return left - 1;
|
||||
}
|
||||
|
||||
void TriggerShape::findTriggerPosition(event_trigger_position_s *position, angle_t angleOffset DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
efiAssertVoid(CUSTOM_ERR_6574, !cisnan(angleOffset), "findAngle#1");
|
||||
assertAngleRange(angleOffset, "findAngle#a1", CUSTOM_ERR_6545);
|
||||
|
||||
efiAssertVoid(CUSTOM_ERR_6575, !cisnan(TRIGGER_SHAPE(tdcPosition)), "tdcPos#1")
|
||||
assertAngleRange(TRIGGER_SHAPE(tdcPosition), "tdcPos#a1", CUSTOM_ERR_6546);
|
||||
|
||||
efiAssertVoid(CUSTOM_ERR_6576, !cisnan(CONFIG(globalTriggerAngleOffset)), "tdcPos#2")
|
||||
assertAngleRange(CONFIG(globalTriggerAngleOffset), "tdcPos#a2", CUSTOM_ERR_6547);
|
||||
|
||||
// convert engine cycle angle into trigger cycle angle
|
||||
angleOffset += tdcPosition();
|
||||
efiAssertVoid(CUSTOM_ERR_6577, !cisnan(angleOffset), "findAngle#2");
|
||||
fixAngle(angleOffset, "addFuel#2", CUSTOM_ERR_6555);
|
||||
|
||||
int index = triggerIndexByAngle[(int)angleOffset];
|
||||
angle_t eventAngle = eventAngles[index];
|
||||
if (angleOffset < eventAngle) {
|
||||
warning(CUSTOM_OBD_ANGLE_CONSTRAINT_VIOLATION, "angle constraint violation in findTriggerPosition(): %.2f/%.2f", angleOffset, eventAngle);
|
||||
return;
|
||||
}
|
||||
|
||||
position->eventIndex = index;
|
||||
position->eventAngle = eventAngle;
|
||||
position->angleOffset = angleOffset - eventAngle;
|
||||
}
|
||||
|
||||
void TriggerShape::setTriggerSynchronizationGap(float syncRatio) {
|
||||
setTriggerSynchronizationGap3(/*gapIndex*/0, syncRatio * 0.75f, syncRatio * 1.25f);
|
||||
}
|
||||
|
|
|
@ -212,7 +212,8 @@ public:
|
|||
|
||||
private:
|
||||
trigger_shape_helper h;
|
||||
int findAngleIndex(float target DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
int findAngleIndex(float angle);
|
||||
|
||||
/**
|
||||
* index of synchronization event within TriggerShape
|
||||
|
|
Loading…
Reference in New Issue