Skip to content

Commit

Permalink
tach sweep experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Sep 5, 2024
1 parent 4d02171 commit 2ff394e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
33 changes: 32 additions & 1 deletion firmware/controllers/modules/tachometer/tachometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
19 changes: 17 additions & 2 deletions firmware/controllers/modules/tachometer/tachometer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
3 changes: 2 additions & 1 deletion firmware/integration/rusefi_config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2ff394e

Please sign in to comment.