auto-sync

This commit is contained in:
rusEfi 2016-12-18 23:01:40 -05:00
parent 39fd428e0d
commit a4d6033c72
4 changed files with 27 additions and 28 deletions

View File

@ -223,11 +223,11 @@ floatms_t getSparkDwell(int rpm DECLARE_ENGINE_PARAMETER_S) {
return dwellMs;
}
static int findAngleIndex(float target DECLARE_ENGINE_PARAMETER_S) {
/**
* Here we rely on this to be pre-calculated, that's a performance optimization
*/
int engineCycleEventCount = engine->engineCycleEventCount;
/**
* this method is only used on initialization
*/
int TriggerShape::findAngleIndex(float target DECLARE_ENGINE_PARAMETER_S) {
int engineCycleEventCount = engine->triggerShape.getLength();
efiAssert(engineCycleEventCount > 0, "engineCycleEventCount", 0);
@ -252,7 +252,6 @@ static int findAngleIndex(float target DECLARE_ENGINE_PARAMETER_S) {
}
}
return left - 1;
}
void TriggerShape::findTriggerPosition(event_trigger_position_s *position, angle_t angleOffset DECLARE_ENGINE_PARAMETER_S) {
@ -358,6 +357,16 @@ static int getIgnitionPinForIndex(int i DECLARE_ENGINE_PARAMETER_S) {
}
}
void TriggerShape::prepareShape(DECLARE_ENGINE_PARAMETER_F) {
int engineCycleInt = (int) getEngineCycle(CONFIG(operationMode));
for (int angle = 0; angle < engineCycleInt; angle++) {
int triggerShapeIndex = findAngleIndex(angle PASS_ENGINE_PARAMETER);
if (engineConfiguration->useOnlyRisingEdgeForTrigger)
triggerShapeIndex = triggerShapeIndex & 0xFFFFFFFE; // we need even index for front_only
triggerIndexByAngle[angle] = triggerShapeIndex;
}
}
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
/**
@ -406,13 +415,9 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) {
}
}
printf("max dwell angle %f/%d/%d\r\n", maxDwellAngle, (int)maxAdvance, (int)maxIatAdvanceCorr);
#endif
#if EFI_UNIT_TEST
printf("prepareOutputSignals %d onlyEdge=%s %s\r\n", engineConfiguration->trigger.type, boolToString(engineConfiguration->useOnlyRisingEdgeForTrigger),
getIgnition_mode_e(engineConfiguration->ignitionMode));
@ -420,18 +425,10 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) {
for (int i = 0; i < CONFIG(specs.cylindersCount); i++) {
ENGINE(angleExtra[i])= ENGINE(engineCycle) * i / CONFIG(specs.cylindersCount);
ENGINE(ignitionPin[i]) = getIgnitionPinForIndex(i PASS_ENGINE_PARAMETER);
}
int engineCycleInt = (int) ENGINE(engineCycle);
for (int angle = 0; angle < engineCycleInt; angle++) {
int triggerShapeIndex = findAngleIndex(angle PASS_ENGINE_PARAMETER);
if (engineConfiguration->useOnlyRisingEdgeForTrigger)
triggerShapeIndex = triggerShapeIndex & 0xFFFFFFFE; // we need even index for front_only
TRIGGER_SHAPE(triggerIndexByAngle[angle]) = triggerShapeIndex;
}
TRIGGER_SHAPE(prepareShape(PASS_ENGINE_PARAMETER_F));
}
#endif

View File

@ -170,9 +170,11 @@ public:
int getSize() const;
int getTriggerShapeSynchPointIndex();
void prepareShape(DECLARE_ENGINE_PARAMETER_F);
private:
trigger_shape_helper h;
int findAngleIndex(float target DECLARE_ENGINE_PARAMETER_S);
/**
* index of synchronization event within TriggerShape

View File

@ -182,32 +182,32 @@ void testAngleResolver(void) {
event_trigger_position_s injectionStart;
printf("*************************************************** testAngleResolver 0\r\n");
findTriggerPosition(&injectionStart, -122 PASS_ENGINE_PARAMETER);
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, -122 PASS_ENGINE_PARAMETER));
assertEqualsM("eventIndex@0", 2, injectionStart.eventIndex);
assertEquals(0.24, injectionStart.angleOffset);
printf("*************************************************** testAngleResolver 0.1\r\n");
findTriggerPosition(&injectionStart, -80 PASS_ENGINE_PARAMETER);
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, -80 PASS_ENGINE_PARAMETER));
assertEqualsM("eventIndex@0", 2, injectionStart.eventIndex);
assertEquals(42.24, injectionStart.angleOffset);
printf("*************************************************** testAngleResolver 0.2\r\n");
findTriggerPosition(&injectionStart, -54 PASS_ENGINE_PARAMETER);
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, -54 PASS_ENGINE_PARAMETER));
assertEqualsM("eventIndex@0", 2, injectionStart.eventIndex);
assertEquals(68.2400, injectionStart.angleOffset);
printf("*************************************************** testAngleResolver 0.3\r\n");
findTriggerPosition(&injectionStart, -53 PASS_ENGINE_PARAMETER);
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, -53 PASS_ENGINE_PARAMETER));
assertEquals(2, injectionStart.eventIndex);
assertEquals(69.24, injectionStart.angleOffset);
printf("*************************************************** testAngleResolver 1\r\n");
findTriggerPosition(&injectionStart, 0 PASS_ENGINE_PARAMETER);
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, 0 PASS_ENGINE_PARAMETER));
assertEquals(2, injectionStart.eventIndex);
assertEquals(122.24, injectionStart.angleOffset);
printf("*************************************************** testAngleResolver 2\r\n");
findTriggerPosition(&injectionStart, 56 PASS_ENGINE_PARAMETER);
TRIGGER_SHAPE(findTriggerPosition(&injectionStart, 56 PASS_ENGINE_PARAMETER));
assertEquals(2, injectionStart.eventIndex);
assertEquals(178.24, injectionStart.angleOffset);

View File

@ -131,13 +131,13 @@ void test1995FordInline6TriggerDecoder(void) {
event_trigger_position_s position;
assertEqualsM("globalTriggerAngleOffset", 0, engineConfiguration->globalTriggerAngleOffset);
findTriggerPosition(&position, 0 PASS_ENGINE_PARAMETER);
TRIGGER_SHAPE(findTriggerPosition(&position, 0 PASS_ENGINE_PARAMETER));
assertTriggerPosition(&position, 0, 0);
findTriggerPosition(&position, 200 PASS_ENGINE_PARAMETER);
TRIGGER_SHAPE(findTriggerPosition(&position, 200 PASS_ENGINE_PARAMETER));
assertTriggerPosition(&position, 3, 20);
findTriggerPosition(&position, 360 PASS_ENGINE_PARAMETER);
TRIGGER_SHAPE(findTriggerPosition(&position, 360 PASS_ENGINE_PARAMETER));
assertTriggerPosition(&position, 6, 0);
eth.applyTriggerShape();