From 929843e295dccc89b7640d181b8d1e71d2355c10 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Thu, 26 May 2022 20:02:41 +0200 Subject: [PATCH] Switch two divisions to faster multiplications --- Firmware/temperature.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 70dac692e..43bcf9c0d 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -2327,9 +2327,12 @@ static uint8_t TM_dT_smp = MAX(TM_dTs, MAX(3/TM_fS, 3/TM_fE)); static void check_temp_model() { + const float soft_pwm_inv = 1. / ((1 << 7) - 1); + const float soft_pwm_fan_inv = 1. / ((1 << FAN_SOFT_PWM_BITS) - 1); + // input values - float heater_scale = (float)soft_pwm[0] / ((1 << 7) - 1); - float fan_scale = (float)soft_pwm_fan / ((1 << FAN_SOFT_PWM_BITS) - 1); + float heater_scale = soft_pwm_inv * soft_pwm[0]; + float fan_scale = soft_pwm_fan_inv * soft_pwm_fan; float cur_temp_heater = current_temperature_isr[0]; float cur_temp_ambient = current_temperature_ambient_isr + TM_aC;