From 046ad7436fab1853621d5823b45d3505e40cfdb9 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 25 Apr 2024 15:06:11 -0700 Subject: [PATCH] use timer instead of home spun time math --- firmware/controllers/algo/event_registry.h | 7 +++---- firmware/controllers/engine_cycle/spark_logic.cpp | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/firmware/controllers/algo/event_registry.h b/firmware/controllers/algo/event_registry.h index 64af3a7989..ef93f825f6 100644 --- a/firmware/controllers/algo/event_registry.h +++ b/firmware/controllers/algo/event_registry.h @@ -70,10 +70,9 @@ public: */ angle_t sparkAngle = NAN; floatms_t sparkDwell = 0; - /** - * this timestamp allows us to measure actual dwell time - */ - uint32_t actualStartOfDwellNt = 0; + + // this timer allows us to measure actual dwell time + Timer actualDwellTimer; float dwellAngle = 0; diff --git a/firmware/controllers/engine_cycle/spark_logic.cpp b/firmware/controllers/engine_cycle/spark_logic.cpp index e0ea2b2586..7915bc9e3a 100644 --- a/firmware/controllers/engine_cycle/spark_logic.cpp +++ b/firmware/controllers/engine_cycle/spark_logic.cpp @@ -208,11 +208,12 @@ void fireSparkAndPrepareNextSchedule(IgnitionEvent *event) { #if !EFI_UNIT_TEST if (engineConfiguration->debugMode == DBG_DWELL_METRIC) { #if EFI_TUNER_STUDIO - uint32_t actualDwellDurationNt = getTimeNowLowerNt() - event->actualStartOfDwellNt; + float actualDwellMs = event->actualDwellTimer.getElapsedSeconds(nowNt) * 1e3; + /** * ratio of desired dwell duration to actual dwell duration gives us some idea of how good is input trigger jitter */ - float ratio = NT2US(actualDwellDurationNt) / 1000.0 / event->sparkDwell; + float ratio = actualDwellMs / event->sparkDwell; // todo: smarted solution for index to field mapping switch (event->cylinderIndex) {