From 908493cfe523705e9e3e6541faae764d52f2fd6a Mon Sep 17 00:00:00 2001 From: rusEfi Date: Wed, 29 Oct 2014 16:03:10 -0500 Subject: [PATCH] auto-sync --- firmware/controllers/trigger/trigger_chrysler.cpp | 2 ++ firmware/controllers/trigger/trigger_decoder.cpp | 15 ++++++++++++--- firmware/controllers/trigger/trigger_decoder.h | 1 + firmware/controllers/trigger/trigger_structure.h | 7 +++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/firmware/controllers/trigger/trigger_chrysler.cpp b/firmware/controllers/trigger/trigger_chrysler.cpp index 7f44b99111..600290ad7b 100644 --- a/firmware/controllers/trigger/trigger_chrysler.cpp +++ b/firmware/controllers/trigger/trigger_chrysler.cpp @@ -13,6 +13,8 @@ void configureNeon2003TriggerShape(trigger_shape_s *s) { // voodoo magic - we always need 720 at the end int base = 10; + s->gapBothDirections = true; + setTriggerSynchronizationGap(s, 2.5); s->addEvent(base + 26, T_PRIMARY, TV_HIGH); diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index f89f5f4492..2e9cab75a8 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -55,7 +55,7 @@ static inline bool isSynchronizationGap(TriggerState const *shaftPositionState, } #if ! EFI_PROD_CODE - if(printGapRatio) { + if (printGapRatio) { float gap = 1.0 * currentDuration / shaftPositionState->toothed_previous_duration; print("current gap %f\r\n", gap); @@ -89,6 +89,12 @@ float TriggerState::getTriggerDutyCycle(int index) { static trigger_wheel_e eventIndex[6] = { T_PRIMARY, T_PRIMARY, T_SECONDARY, T_SECONDARY, T_CHANNEL_3, T_CHANNEL_3 }; static trigger_value_e eventType[6] = { TV_LOW, TV_HIGH, TV_LOW, TV_HIGH, TV_LOW, TV_HIGH }; +uint64_t TriggerState::getCurrentGapDuration(uint64_t nowUs) { + int64_t currentDuration = isFirstEvent ? 0 : nowUs - toothed_previous_time; + isFirstEvent = false; + return currentDuration; +} + /** * @brief Trigger decoding happens here * This method changes the state of trigger_state_s data structure according to the trigger event @@ -110,11 +116,14 @@ void TriggerState::decodeTriggerEvent(trigger_shape_s const*triggerShape, trigge * For less important events we simply increment the index. */ nextTriggerEvent(triggerWheel, nowUs); + if (triggerShape->gapBothDirections) { +// toothed_previous_duration = getCurrentGapDuration(nowUs); +// toothed_previous_time = nowUs; + } return; } - int64_t currentDuration = isFirstEvent ? 0 : nowUs - toothed_previous_time; - isFirstEvent = false; + int64_t currentDuration = getCurrentGapDuration(nowUs); efiAssertVoid(currentDuration >= 0, "decode: negative duration?"); // todo: skip a number of signal from the beginning diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index d9cfe1ebf8..4b54cf61bb 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -50,6 +50,7 @@ public: private: void clear(); + uint64_t getCurrentGapDuration(uint64_t nowUs); /** * index within trigger revolution, from 0 to trigger event count */ diff --git a/firmware/controllers/trigger/trigger_structure.h b/firmware/controllers/trigger/trigger_structure.h index 79771e082f..6fa4bd467a 100644 --- a/firmware/controllers/trigger/trigger_structure.h +++ b/firmware/controllers/trigger/trigger_structure.h @@ -39,7 +39,14 @@ public: float syncRatioFrom; float syncRatioTo; + /** + * Should we use falls or rises for gap ratio detection? + */ bool_t useRiseEdge; + /** + * Should we measure gaps with events of both kinds? + */ + bool_t gapBothDirections; /** * This is used for signal validation