From 2ff394e3e9cd8fbf13e8d58633fead04acd48c21 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 4 Sep 2024 22:38:12 -0700 Subject: [PATCH] tach sweep experiment --- .../modules/tachometer/tachometer.cpp | 33 ++++++++++++++++++- .../modules/tachometer/tachometer.h | 19 +++++++++-- firmware/integration/rusefi_config.txt | 3 +- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/firmware/controllers/modules/tachometer/tachometer.cpp b/firmware/controllers/modules/tachometer/tachometer.cpp index 43aa4be559..bc96910a88 100644 --- a/firmware/controllers/modules/tachometer/tachometer.cpp +++ b/firmware/controllers/modules/tachometer/tachometer.cpp @@ -41,7 +41,7 @@ void TachometerModule::onFastCallback() { } // What is the angle per tach output period? - float cycleTimeMs = 60000.0f / Sensor::getOrZero(SensorType::Rpm); + float cycleTimeMs = 60000.0f / getRpm(); float periodTimeMs = cycleTimeMs / periods; tachFreq = 1000.0f / periodTimeMs; @@ -62,6 +62,37 @@ void TachometerModule::onFastCallback() { tachControl.setFrequency(tachFreq); } +float TachometerModule::getRpm() { + float trueRpm = Sensor::getOrZero(SensorType::Rpm); + + if (!m_doTachSweep) { + return trueRpm; + } + + float elapsed = m_stateChangeTimer.getElapsedSeconds(); + float sweepPosition = elapsed / engineConfiguration->tachSweepTime; + + if (sweepPosition > 1) { + // We've done a full sweep time, we're done! + m_doTachSweep = false; + return trueRpm; + } else if (sweepPosition < 0.5f) { + // First half of the ramp, ramp up from 0 -> max + return interpolateClamped(0, 0.5f, 0, engineConfiguration->tachSweepMax, sweepPosition); + } else { + // Use y2 = trueRpm instead of 0 so that it ramps back down smoothly + // to the current RPM if the engine started during ther ramp + return interpolateClamped(0.5f, 1, engineConfiguration->tachSweepMax, trueRpm, sweepPosition); + } +} + +void TachometerModule::onIgnitionStateChanged(bool ignitionOn) { + if (ignitionOn && engineConfiguration->tachSweepTime != 0) { + m_stateChangeTimer.reset(); + m_doTachSweep = true; + } +} + void initTachometer() { tachHasInit = false; diff --git a/firmware/controllers/modules/tachometer/tachometer.h b/firmware/controllers/modules/tachometer/tachometer.h index e96be542ed..53a49403cc 100644 --- a/firmware/controllers/modules/tachometer/tachometer.h +++ b/firmware/controllers/modules/tachometer/tachometer.h @@ -9,8 +9,23 @@ void initTachometer(); -struct TachometerModule : public EngineModule { - +class TachometerModule : public EngineModule { +public: // TODO: can/should this be slow callback instead? void onFastCallback() override; + void onIgnitionStateChanged(bool ignitionOn) override; + +private: + float getRpm(); + + bool m_doTachSweep = false; + + enum class TachState { + Normal, + RampUp, + RampDown, + }; + + TachState m_state = TachState::Normal; + Timer m_stateChangeTimer; }; diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 3a3781cdee..9917b3c49d 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -744,7 +744,8 @@ output_pin_e acFanPin;Optional Radiator Fan used with A/C Gpio[EGT_CHANNEL_COUNT iterate] max31855_cs; brain_input_pin_e flexSensorPin;Continental/GM flex fuel sensor, 50-150hz type; - uint16_t unused720 + uint8_t autoscale tachSweepTime;Total time for the tach to sweep up then back down at startup. Set to 0 to disable sweep.;"s", 0.1, 0, 0, 10, 1 + uint8_t autoscale tachSweepMax;Maximum RPM for the startup tach sweep.;"rpm", 50, 9, 0, 12500, 0 pin_output_mode_e stepperDirectionPinMode; spi_device_e mc33972spiDevice;