From 86a40aa711d6827f3aa5c09084e16f7e6339022f Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sat, 12 Sep 2015 16:01:43 -0400 Subject: [PATCH] auto-sync --- .../controllers/trigger/trigger_decoder.cpp | 2 +- .../controllers/trigger/trigger_decoder.h | 22 +++++++++++++------ .../models/src/com/rusefi/config/Fields.java | 4 ++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 91a7f834fa..4cc4245ddc 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -76,7 +76,7 @@ static trigger_wheel_e eventIndex[6] = { T_PRIMARY, T_PRIMARY, T_SECONDARY, T_SE #define nextTriggerEvent() \ { \ - efitime_t prevTime = currentCycle.timeOfPreviousEventNt[triggerWheel]; \ + uint32_t prevTime = currentCycle.timeOfPreviousEventNt[triggerWheel]; \ if (prevTime != 0) { \ /* even event - apply the value*/ \ currentCycle.totalTimeNt[triggerWheel] += (nowNt - prevTime); \ diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index 92af69154a..ec3208d452 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -20,21 +20,28 @@ class TriggerState; typedef void (*TriggerStateCallback)(TriggerState *); typedef struct { - /** - * Here we accumulate the amount of time this signal was ON within current trigger cycle - */ - int totalTimeNt[PWM_PHASE_MAX_WAVE_PER_PWM]; /** * index within trigger revolution, from 0 to trigger event count */ uint32_t current_index; /** - * Number of actual events within current trigger cycle + * Number of actual events of each channel within current trigger cycle, these + * values are used to detect trigger signal errors. * see TriggerShape */ uint32_t eventCount[PWM_PHASE_MAX_WAVE_PER_PWM]; - efitime_t timeOfPreviousEventNt[PWM_PHASE_MAX_WAVE_PER_PWM]; - + /** + * This array is used to calculate duty cycle of each trigger channel. + * Current implementation is a bit funny - it does not really consider if an event + * is a rise or a fall, it works based on the event order within synchronization cycle. + * + * 32 bit value is good enough here, overflows will happen but they would work just fine. + */ + uint32_t timeOfPreviousEventNt[PWM_PHASE_MAX_WAVE_PER_PWM]; + /** + * Here we accumulate the amount of time this signal was ON within current trigger cycle + */ + uint32_t totalTimeNt[PWM_PHASE_MAX_WAVE_PER_PWM]; } current_cycle_state_s; class TriggerState { @@ -65,6 +72,7 @@ public: current_cycle_state_s currentCycle; /** * Total time result for previous trigger cycle + * See totalTimeNt */ uint32_t prevTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM]; int expectedTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM]; diff --git a/java_console/models/src/com/rusefi/config/Fields.java b/java_console/models/src/com/rusefi/config/Fields.java index 8692645998..7e1a42778b 100644 --- a/java_console/models/src/com/rusefi/config/Fields.java +++ b/java_console/models/src/com/rusefi/config/Fields.java @@ -1,6 +1,6 @@ package com.rusefi.config; -// this file was generated automatically by ConfigDefinition.jar Mon Aug 31 13:06:37 EDT 2015 +// this file was generated automatically by ConfigDefinition.jar Sat Sep 12 14:31:14 EDT 2015 public class Fields { public static final Field ENGINETYPE = new Field("ENGINETYPE", 0, FieldType.INT); public static final Field HEADERMAGICVALUE = new Field("HEADERMAGICVALUE", 4, FieldType.INT); @@ -76,7 +76,7 @@ public class Fields { public static final Field TPSADCCHANNEL = new Field("TPSADCCHANNEL", 524, FieldType.INT, adc_channel_e); public static final Field OVERRIDECRANKINGIGNITION = new Field("OVERRIDECRANKINGIGNITION", 528, FieldType.INT); public static final Field SENSORCHARTFREQUENCY = new Field("SENSORCHARTFREQUENCY", 532, FieldType.INT); - public static final String[] trigger_type_e = {"custom toothed wheel", "ford aspire", "dodge neon", "Miata NA", "Miata NB", "GM_7X", "Cooper", "Mazda SOHC 4", "60/2", "36/1", "Accord CD", "MITSU", "ACCORD 2", "ACCORD DIP", "Neon 2003", "MAZDA D 1+4", "1+1", "1+60/2", "Single Tooth", "Dodge Ram 1+16", "60/2 VW", "Accord 1+24", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID"}; + public static final String[] trigger_type_e = {"custom toothed wheel", "ford aspire", "dodge neon", "Miata NA", "Miata NB", "GM_7X", "Cooper", "Mazda SOHC 4", "60/2", "36/1", "Accord CD", "MITSU", "ACCORD 2", "ACCORD DIP", "Neon 2003", "MAZDA D 1+4", "1+1", "1+60/2", "Single Tooth", "Dodge Ram 1+16", "60/2 VW", "Accord 1+24", "DODGE STRATUS", "36_2_2_2", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID"}; public static final Field TRIGGER_TYPE = new Field("TRIGGER_TYPE", 536, FieldType.INT, trigger_type_e); public static final Field TRIGGER_CUSTOMISSYNCHRONIZATIONNEEDED = new Field("TRIGGER_CUSTOMISSYNCHRONIZATIONNEEDED", 540, FieldType.BIT, 0); public static final Field TRIGGER_CUSTOMNEEDSECONDTRIGGERINPUT = new Field("TRIGGER_CUSTOMNEEDSECONDTRIGGERINPUT", 540, FieldType.BIT, 1);