diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index 105af26828..4f9fb7a5a9 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -48,7 +48,7 @@ RpmCalculator::RpmCalculator() { mockRpm = MOCK_UNDEFINED; #endif rpmValue = 0; - setRpmValue(0); + assignRpmValue(0); // we need this initial to have not_running at first invocation lastRpmEventTimeNt = (efitime_t) -10 * US2NT(US_PER_SECOND_LL); @@ -82,7 +82,9 @@ bool RpmCalculator::isRunning(DECLARE_ENGINE_PARAMETER_F) { return result; } -void RpmCalculator::setRpmValue(int value) { + +// private method +void RpmCalculator::assignRpmValue(int value) { previousRpmValue = rpmValue; rpmValue = value; if (rpmValue <= 0) { @@ -92,6 +94,17 @@ void RpmCalculator::setRpmValue(int value) { } } +void RpmCalculator::setRpmValue(int value DECLARE_ENGINE_PARAMETER_S) { + assignRpmValue(value); + if (previousRpmValue == 0 && rpmValue > 0) { + /** + * this would make sure that we have good numbers for first cranking revolution + * #275 cranking could be improved + */ + engine->periodicFastCallback(PASS_ENGINE_PARAMETER_F); + } +} + void RpmCalculator::onNewEngineCycle() { revolutionCounterSinceBoot++; revolutionCounterSinceStart++; @@ -194,11 +207,11 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, * */ if (diffNt == 0) { - rpmState->setRpmValue(NOISY_RPM); + rpmState->setRpmValue(NOISY_RPM PASS_ENGINE_PARAMETER); } else { int mult = getEngineCycle(engineConfiguration->operationMode) / 360; int rpm = (int) (60 * US2NT(US_PER_SECOND_LL) * mult / diffNt); - rpmState->setRpmValue(rpm > UNREALISTIC_RPM ? NOISY_RPM : rpm); + rpmState->setRpmValue(rpm > UNREALISTIC_RPM ? NOISY_RPM : rpm PASS_ENGINE_PARAMETER); } } rpmState->onNewEngineCycle(); diff --git a/firmware/controllers/trigger/rpm_calculator.h b/firmware/controllers/trigger/rpm_calculator.h index a3a50bdf00..78d36c519a 100644 --- a/firmware/controllers/trigger/rpm_calculator.h +++ b/firmware/controllers/trigger/rpm_calculator.h @@ -47,7 +47,7 @@ public: */ void onNewEngineCycle(); uint32_t getRevolutionCounter(void); - void setRpmValue(int value); + void setRpmValue(int value DECLARE_ENGINE_PARAMETER_S); uint32_t getRevolutionCounterSinceStart(void); float getRpmAcceleration(); /** @@ -62,6 +62,7 @@ public: volatile floatus_t oneDegreeUs; volatile efitime_t lastRpmEventTimeNt; private: + void assignRpmValue(int value); /** * This counter is incremented with each revolution of one of the shafts. Could be * crankshaft could be camshaft. diff --git a/unit_tests/test_accel_enrichment.cpp b/unit_tests/test_accel_enrichment.cpp index 4086eab86f..3ccba6326c 100644 --- a/unit_tests/test_accel_enrichment.cpp +++ b/unit_tests/test_accel_enrichment.cpp @@ -18,7 +18,7 @@ void testAccelEnrichment(void) { EngineTestHelper eth(FORD_ASPIRE_1996); EXPAND_EngineTestHelper; - engine->rpmCalculator.setRpmValue(600); + engine->rpmCalculator.setRpmValue(600 PASS_ENGINE_PARAMETER); engine->periodicFastCallback(PASS_ENGINE_PARAMETER_F); assertEqualsM("eventsCount", 4, engine->engineConfiguration2->injectionEvents->eventsCount);