From b09091774a4c7ddfb6f238b3394547a9c90aa62e Mon Sep 17 00:00:00 2001 From: rusefi Date: Tue, 25 Aug 2020 12:45:18 -0400 Subject: [PATCH] VVT support for VAG trigger #883 --- firmware/controllers/math/engine_math.cpp | 2 +- .../controllers/trigger/decoders/trigger_structure.cpp | 4 +++- .../controllers/trigger/decoders/trigger_structure.h | 2 +- firmware/controllers/trigger/trigger_decoder.cpp | 9 +++++++-- firmware/controllers/trigger/trigger_decoder.h | 1 + 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index bdcd7a16e1..a2fbc8e7cc 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -414,7 +414,7 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_SIGNATURE) { prepareIgnitionPinIndices(CONFIG(ignitionMode) PASS_ENGINE_PARAMETER_SUFFIX); - TRIGGER_WAVEFORM(prepareShape(&ENGINE(triggerCentral.triggerFormDetails))); + TRIGGER_WAVEFORM(prepareShape(&ENGINE(triggerCentral.triggerFormDetails) PASS_ENGINE_PARAMETER_SUFFIX)); } void setTimingRpmBin(float from, float to DECLARE_CONFIG_PARAMETER_SUFFIX) { diff --git a/firmware/controllers/trigger/decoders/trigger_structure.cpp b/firmware/controllers/trigger/decoders/trigger_structure.cpp index d9e736fc8f..4c81c0cafa 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.cpp +++ b/firmware/controllers/trigger/decoders/trigger_structure.cpp @@ -406,8 +406,10 @@ void findTriggerPosition(TriggerWaveform *triggerShape, position->angleOffsetFromTriggerEvent = angle - triggerEventAngle; } -void TriggerWaveform::prepareShape(TriggerFormDetails *details) { +void TriggerWaveform::prepareShape(TriggerFormDetails *details DECLARE_ENGINE_PARAMETER_SUFFIX) { #if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT + prepareEventAngles(this, details PASS_ENGINE_PARAMETER_SUFFIX); + int engineCycleInt = (int) getEngineCycle(operationMode); for (int angle = 0; angle < engineCycleInt; angle++) { int triggerShapeIndex = findAngleIndex(details, angle); diff --git a/firmware/controllers/trigger/decoders/trigger_structure.h b/firmware/controllers/trigger/decoders/trigger_structure.h index 35d57de71c..38c996b09e 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.h +++ b/firmware/controllers/trigger/decoders/trigger_structure.h @@ -235,7 +235,7 @@ public: size_t getSize() const; int getTriggerWaveformSynchPointIndex() const; - void prepareShape(TriggerFormDetails *details); + void prepareShape(TriggerFormDetails *details DECLARE_ENGINE_PARAMETER_SUFFIX); /** * This private method should only be used to prepare the array of pre-calculated values diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 22268fbe63..c243c7402b 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -135,12 +135,17 @@ void calculateTriggerSynchPoint(TriggerWaveform *shape, shape->setShapeDefinitionError(true); return; } +} +void prepareEventAngles(TriggerWaveform *shape, + TriggerFormDetails *details DECLARE_ENGINE_PARAMETER_SUFFIX) { float firstAngle = shape->getAngle(shape->triggerShapeSynchPointIndex); - assertAngleRange(shape->triggerShapeSynchPointIndex, "firstAngle", CUSTOM_TRIGGER_SYNC_ANGLE); + assertAngleRange(firstAngle, "firstAngle", CUSTOM_TRIGGER_SYNC_ANGLE); int riseOnlyIndex = 0; + int length = shape->getLength(); + memset(details->eventAngles, 0, sizeof(details->eventAngles)); for (int eventIndex = 0; eventIndex < length; eventIndex++) { @@ -151,7 +156,7 @@ void calculateTriggerSynchPoint(TriggerWaveform *shape, details->eventAngles[1] = 0; } else { assertAngleRange(shape->triggerShapeSynchPointIndex, "triggerShapeSynchPointIndex", CUSTOM_TRIGGER_SYNC_ANGLE2); - unsigned int triggerDefinitionCoordinate = (shape->triggerShapeSynchPointIndex + eventIndex) % engine->engineCycleEventCount; + unsigned int triggerDefinitionCoordinate = (shape->triggerShapeSynchPointIndex + eventIndex) % length; efiAssertVoid(CUSTOM_TRIGGER_CYCLE, engine->engineCycleEventCount != 0, "zero engineCycleEventCount"); int triggerDefinitionIndex = triggerDefinitionCoordinate >= shape->privateTriggerDefinitionSize ? triggerDefinitionCoordinate - shape->privateTriggerDefinitionSize : triggerDefinitionCoordinate; float angle = shape->getAngle(triggerDefinitionCoordinate) - firstAngle; diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index ab5944f448..9cc134de49 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -194,3 +194,4 @@ void calculateTriggerSynchPoint(TriggerWaveform *shape, TriggerFormDetails *details, TriggerState *state DECLARE_ENGINE_PARAMETER_SUFFIX); +void prepareEventAngles(TriggerWaveform *shape, TriggerFormDetails *details DECLARE_ENGINE_PARAMETER_SUFFIX);