diff --git a/firmware/CHANGELOG.md b/firmware/CHANGELOG.md index 8d05624f9a..d7cbbb941c 100644 --- a/firmware/CHANGELOG.md +++ b/firmware/CHANGELOG.md @@ -29,6 +29,9 @@ Release template (copy/paste this for new release): ### Added - Flexible ignition adder/trim tables #4586 +### Fixed + - Slower than expected RPM information was slowing engine start #4629 + ## September 2022 Release - "Day 203" ### Added diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index 24e0596b26..4bfd2521e3 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -209,11 +209,9 @@ uint32_t RpmCalculator::getRevolutionCounterM(void) const { } void RpmCalculator::onSlowCallback() { - /** - * Update engine RPM state if needed (check timeouts). - */ - if (!checkIfSpinning(getTimeNowNt())) { - engine->rpmCalculator.setStopSpinning(); + // Stop the engine if it's been too long since we got a trigger event + if (!engine->triggerCentral.engineMovedRecently(getTimeNowNt())) { + setStopSpinning(); } } diff --git a/firmware/controllers/trigger/decoders/trigger_structure.h b/firmware/controllers/trigger/decoders/trigger_structure.h index dff0b67c18..526c15b14f 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.h +++ b/firmware/controllers/trigger/decoders/trigger_structure.h @@ -294,5 +294,3 @@ void findTriggerPosition( void setToothedWheelConfiguration(TriggerWaveform *s, int total, int skipped, operation_mode_e operationMode); #define TRIGGER_WAVEFORM(x) getTriggerCentral()->triggerShape.x - -#define getTriggerSize() TRIGGER_WAVEFORM(wave.phaseCount) diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 73106541bd..a222ba6819 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -280,6 +280,8 @@ float PrimaryTriggerDecoder::calculateInstantRpm( // now let's get precise angle for that event angle_t prevIndexAngle = triggerFormDetails->eventAngles[prevIndex]; efitick_t time90ago = timeOfLastEvent[prevIndex]; + + // No previous timestamp, instant RPM isn't ready yet if (time90ago == 0) { return prevInstantRpmValue; } @@ -293,9 +295,10 @@ float PrimaryTriggerDecoder::calculateInstantRpm( // Wrap the angle in to the correct range (ie, could be -630 when we want +90) fixAngle(angleDiff, "angleDiff", CUSTOM_ERR_6561); - // just for safety - if (time == 0) + // just for safety, avoid divide-by-0 + if (time == 0) { return prevInstantRpmValue; + } float instantRpm = (60000000.0 / 360 * US_TO_NT_MULTIPLIER) * angleDiff / time; assertIsInBoundsWithResult(current_index, instantRpmValue, "instantRpmValue", 0); diff --git a/unit_tests/tests/trigger/test_real_gm_24x.cpp b/unit_tests/tests/trigger/test_real_gm_24x.cpp index 1d7fe4d0c4..de117c4daa 100644 --- a/unit_tests/tests/trigger/test_real_gm_24x.cpp +++ b/unit_tests/tests/trigger/test_real_gm_24x.cpp @@ -12,10 +12,23 @@ TEST(crankingGm24x, gmRealCrankingFromFile) { eth.setTriggerType(TT_GM_24x); + int eventCount = 0; + bool gotRpm = false; + while (reader.haveMore()) { reader.processLine(ð); + eventCount++; engine->rpmCalculator.onSlowCallback(); + + auto rpm = Sensor::getOrZero(SensorType::Rpm); + if (!gotRpm && rpm) { + gotRpm = true; + + // We should get first RPM on exactly the first sync point - this means the instant RPM pre-sync event copy all worked OK + EXPECT_EQ(eventCount, 23); + EXPECT_NEAR(rpm, 77.0f, 0.1); + } } ASSERT_EQ( 0, eth.recentWarnings()->getCount())<< "warningCounter#vwRealCranking";