diff --git a/firmware/controllers/algo/engine2.cpp b/firmware/controllers/algo/engine2.cpp index 30a0b2317a..cedaa8dfea 100644 --- a/firmware/controllers/algo/engine2.cpp +++ b/firmware/controllers/algo/engine2.cpp @@ -82,7 +82,7 @@ bool WarningCodeState::isWarningNow(ObdCode code) const { } EngineState::EngineState() { - timeSinceLastTChargeK = getTimeNowNt(); + timeSinceLastTChargeK.reset(getTimeNowNt()); } void EngineState::updateSlowSensors() { @@ -215,14 +215,13 @@ void EngineState::periodicFastCallback() { #if EFI_ENGINE_CONTROL void EngineState::updateTChargeK(int rpm, float tps) { float newTCharge = engine->fuelComputer.getTCharge(rpm, tps); - // convert to microsecs and then to seconds - efitick_t curTime = getTimeNowNt(); - float secsPassed = (float)NT2US(curTime - timeSinceLastTChargeK) / US_PER_SECOND_F; if (!cisnan(newTCharge)) { // control the rate of change or just fill with the initial value + efitick_t nowNt = getTimeNowNt(); + float secsPassed = timeSinceLastTChargeK.getElapsedSeconds(nowNt); sd.tCharge = (sd.tChargeK == 0) ? newTCharge : limitRateOfChange(newTCharge, sd.tCharge, engineConfiguration->tChargeAirIncrLimit, engineConfiguration->tChargeAirDecrLimit, secsPassed); sd.tChargeK = convertCelsiusToKelvin(sd.tCharge); - timeSinceLastTChargeK = curTime; + timeSinceLastTChargeK.reset(nowNt); } } #endif diff --git a/firmware/controllers/algo/engine_state.h b/firmware/controllers/algo/engine_state.h index f708e51371..2cfaeac5e0 100644 --- a/firmware/controllers/algo/engine_state.h +++ b/firmware/controllers/algo/engine_state.h @@ -60,7 +60,7 @@ public: // Angle between firing the main (primary) spark and the secondary (trailing) spark angle_t trailingSparkAngle = 0; - efitick_t timeSinceLastTChargeK; + Timer timeSinceLastTChargeK; float currentVe = 0;