diff --git a/firmware/config/engines/test_engine.cpp b/firmware/config/engines/test_engine.cpp index 2519fab13a..893da16cae 100644 --- a/firmware/config/engines/test_engine.cpp +++ b/firmware/config/engines/test_engine.cpp @@ -68,7 +68,10 @@ void setTestVVTEngineConfiguration(DECLARE_ENGINE_PARAMETER_F) { boardConfiguration->triggerInputPins[1] = GPIO_UNASSIGNED; engineConfiguration->camInput = GPIOA_5; - // set_global_trigger_offset_angle - engineConfiguration->globalTriggerAngleOffset = 545; + // set_global_trigger_offset_angle 0 + engineConfiguration->globalTriggerAngleOffset = 0; + + engineConfiguration->vvtMode = VVT_SECOND_HALF; + engineConfiguration->debugMode = VVT; } diff --git a/firmware/config/engines/toyota_jzs147.cpp b/firmware/config/engines/toyota_jzs147.cpp index 6ec33a7e5b..9456c530bc 100644 --- a/firmware/config/engines/toyota_jzs147.cpp +++ b/firmware/config/engines/toyota_jzs147.cpp @@ -108,6 +108,9 @@ void setToyota_2jz_vics(DECLARE_ENGINE_PARAMETER_F) { boardConfiguration->triggerInputPins[0] = GPIOA_5; // crank sensor boardConfiguration->triggerInputPins[1] = GPIO_UNASSIGNED; // cam sensor will he handled by custom vtti code + engineConfiguration->camInput = GPIOC_6; + engineConfiguration->vvtMode = VVT_2GZ; + // set_global_trigger_offset_angle 155 engineConfiguration->globalTriggerAngleOffset = 155; // todo diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index dfff19bf1d..1915dcb591 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -30,7 +30,7 @@ #include "adc_inputs.h" #if EFI_WAVE_ANALYZER || defined(__DOXYGEN__) #include "wave_analyzer.h" -#endif +#endif /* EFI_WAVE_ANALYZER */ // see RUS_EFI_VERSION_TAG in console source code #define RUS_EFI_VERSION_TAG "rusEfiVersion" @@ -336,17 +336,18 @@ static void printInfo(systime_t nowSeconds) { #if EFI_PROD_CODE || defined(__DOXYGEN__) printOutPin(CRANK1, boardConfiguration->triggerInputPins[0]); printOutPin(CRANK2, boardConfiguration->triggerInputPins[1]); + printOutPin(VVT_NAME, engineConfiguration->camInput); #if EFI_WAVE_ANALYZER || defined(__DOXYGEN__) printOutPin(WA_CHANNEL_1, boardConfiguration->logicAnalyzerPins[0]); printOutPin(WA_CHANNEL_2, boardConfiguration->logicAnalyzerPins[1]); -#endif +#endif /* EFI_WAVE_ANALYZER */ for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { printOutPin(enginePins.coils[i].name, boardConfiguration->ignitionPins[i]); printOutPin(enginePins.injectors[i].name, boardConfiguration->injectionPins[i]); } -#endif +#endif /* EFI_PROD_CODE */ } diff --git a/firmware/controllers/trigger/rpm_calculator.h b/firmware/controllers/trigger/rpm_calculator.h index 78d36c519a..04c66b8a85 100644 --- a/firmware/controllers/trigger/rpm_calculator.h +++ b/firmware/controllers/trigger/rpm_calculator.h @@ -24,6 +24,8 @@ #define CRANK2 "t2" #define CRANK3 "t3" +#define VVT_NAME "VVT" + #define NOISY_RPM -1 #define UNREALISTIC_RPM 30000 diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index f6397f3df1..f68092e661 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -25,7 +25,9 @@ #if EFI_PROD_CODE || defined(__DOXYGEN__) #include "rfiutil.h" #include "pin_repository.h" -#endif +#include "tunerstudio.h" +extern TunerStudioOutputChannels tsOutputChannels; +#endif /* EFI_PROD_CODE */ #if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__) #include "engine_sniffer.h" @@ -75,8 +77,18 @@ uint32_t triggerMaxDuration = 0; extern bool isInsideTriggerHandler; void hwHandleVvtCamSignal(trigger_value_e front) { + if (ENGINE(isEngineChartEnabled)) { + // this is a performance optimization - array index is cheaper then invoking a method with 'switch' + addEngineSniffferEvent(VVT_NAME, front == TV_RISE ? WC_UP : WC_DOWN); + } - efitick_t offsetNt = getTimeNowNt() - engine->triggerCentral.timeAtVirtualZeroNt; + if (boardConfiguration->vvtCamSensorUseRise && front == TV_FALL) { + return; + } + + TriggerCentral *tc = &engine->triggerCentral; + + efitick_t offsetNt = getTimeNowNt() - tc->timeAtVirtualZeroNt; angle_t vvtPosition = NT2US(offsetNt) / engine->rpmCalculator.oneDegreeUs; @@ -84,12 +96,35 @@ void hwHandleVvtCamSignal(trigger_value_e front) { vvtPosition -= tdcPosition(); fixAngle(vvtPosition); - engine->triggerCentral.vvtPosition = vvtPosition; + tc->vvtPosition = vvtPosition; + if (engineConfiguration->vvtMode == VVT_FIRST_HALF) { + bool isEven = tc->triggerState.isEvenRevolution(); + if (!isEven) { + /** + * we are here if we've detected the cam sensor within the wrong crank phase + * let's increase the trigger event counter, that would adjust the state of + * virtual crank-based trigger + */ + tc->triggerState.intTotalEventCounter(); +#if EFI_PROD_CODE || defined(__DOXYGEN__) + if (engineConfiguration->debugMode == VVT) { + tsOutputChannels.debugIntField1++; + } +#endif /* EFI_PROD_CODE */ + } + } else if (engineConfiguration->vvtMode == VVT_SECOND_HALF) { + bool isEven = tc->triggerState.isEvenRevolution(); + if (isEven) { + // see above comment +#if EFI_PROD_CODE || defined(__DOXYGEN__) + tc->triggerState.intTotalEventCounter(); + if (engineConfiguration->debugMode == VVT) { + tsOutputChannels.debugIntField1++; + } +#endif /* EFI_PROD_CODE */ + } - if (ENGINE(isEngineChartEnabled)) { - // this is a performance optimization - array index is cheaper then invoking a method with 'switch' - addEngineSniffferEvent("VVT", front == TV_RISE ? WC_UP : WC_DOWN); } } @@ -186,7 +221,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal DECLARE_ENGINE_PAR // That's easy - trigger cycle matches engine cycle triggerIndexForListeners = triggerState.getCurrentIndex(); } else { - bool isEven = triggerState.getTotalRevolutionCounter() & 1; + bool isEven = triggerState.isEvenRevolution(); triggerIndexForListeners = triggerState.getCurrentIndex() + (isEven ? 0 : TRIGGER_SHAPE(size)); } diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 3025e7888d..8260ef3d15 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -303,5 +303,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20160822; + return 20160823; } diff --git a/firmware/tunerstudio/rusefi.ini b/firmware/tunerstudio/rusefi.ini index bd9427c53a..df8050b099 100644 --- a/firmware/tunerstudio/rusefi.ini +++ b/firmware/tunerstudio/rusefi.ini @@ -42,7 +42,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Tue Aug 23 21:52:05 EDT 2016 +; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Tue Aug 23 22:54:36 EDT 2016 pageSize = 16376 page = 1 @@ -866,6 +866,7 @@ fileVersion = { 20160702 } warningCounter = scalar,U32, 236, "count", 1, 0 lastErrorCode = scalar,U32, 240, "error", 1, 0 internalMcuTemperature = scalar,F32, 244, "C", 1, 0 + vvtPosition = scalar,F32, 248, "deg", 1, 0 egoCorrection = { 100 } time = { timeNow } @@ -1158,6 +1159,7 @@ fileVersion = { 20160702 } warningCounterGauge = warningCounter, "warn", "", 0, 100, 0, 0, 100, 100, 0, 0 lastErrorCodeGauge = lastErrorCode, "error", "", 0, 100, 0, 0, 100, 100, 0, 0 internalMcuTemperatureGauge = internalMcuTemperature, "internal temperature", "C", 0, 100, 0, 0, 100, 100, 0, 0 + vvtPositionGauge = vvtPosition, "VVT position", "deg", 0, 100, 0, 0, 720, 720, 0, 0 [FrontPage] @@ -1457,8 +1459,8 @@ cmd_test_idle_valve = "w\x00\x17\x00\x01" field = "Primary input channel", triggerInputPins1 field = "Secondary channel", triggerInputPins2 field = "CAM input", camInput - field = "VVT mode", vvtMode - field = "VVT use rise front", vvtCamSensorUseRise + field = "VVT mode", vvtMode, {trigger_type != 80} + field = "VVT use rise front", vvtCamSensorUseRise, {trigger_type != 80} field = "Trigger error LED", triggerErrorPin field = "Trigger error LED mode", triggerErrorPinMode dialog = triggerConfiguration diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 1190ec9783..96500cfe36 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -848,6 +848,7 @@ fileVersion = { 20160702 } warningCounter = scalar,U32, 236, "count", 1, 0 lastErrorCode = scalar,U32, 240, "error", 1, 0 internalMcuTemperature = scalar,F32, 244, "C", 1, 0 + vvtPosition = scalar,F32, 248, "deg", 1, 0 egoCorrection = { 100 } time = { timeNow } @@ -1140,6 +1141,7 @@ fileVersion = { 20160702 } warningCounterGauge = warningCounter, "warn", "", 0, 100, 0, 0, 100, 100, 0, 0 lastErrorCodeGauge = lastErrorCode, "error", "", 0, 100, 0, 0, 100, 100, 0, 0 internalMcuTemperatureGauge = internalMcuTemperature, "internal temperature", "C", 0, 100, 0, 0, 100, 100, 0, 0 + vvtPositionGauge = vvtPosition, "VVT position", "deg", 0, 100, 0, 0, 720, 720, 0, 0 [FrontPage] @@ -1439,8 +1441,8 @@ cmd_test_idle_valve = "w\x00\x17\x00\x01" field = "Primary input channel", triggerInputPins1 field = "Secondary channel", triggerInputPins2 field = "CAM input", camInput - field = "VVT mode", vvtMode - field = "VVT use rise front", vvtCamSensorUseRise + field = "VVT mode", vvtMode, {trigger_type != 80} + field = "VVT use rise front", vvtCamSensorUseRise, {trigger_type != 80} field = "Trigger error LED", triggerErrorPin field = "Trigger error LED mode", triggerErrorPinMode dialog = triggerConfiguration