From f454d1ecf22ba1c282f2b7911e0089ad079ce465 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Thu, 7 Jul 2022 00:46:52 +0200 Subject: [PATCH] TM autotune: fix off-by-one in fan power levels --- Firmware/temperature.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 6a8b0798e..042d3d30a 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -2784,8 +2784,8 @@ bool autotune(int16_t cal_temp) fanSpeedSoftPwm = 255; wait(30000); - for(int8_t i = TEMP_MODEL_R_SIZE; i > 0; i -= TEMP_MODEL_CAL_R_STEP) { - fanSpeedSoftPwm = 256 / TEMP_MODEL_R_SIZE * i - 1; + for(int8_t i = TEMP_MODEL_R_SIZE - 1; i > 0; i -= TEMP_MODEL_CAL_R_STEP) { + fanSpeedSoftPwm = 256 / TEMP_MODEL_R_SIZE * (i + 1) - 1; wait(10000); printf_P(PSTR("TM: R[%u] estimation\n"), (unsigned)i); @@ -2803,6 +2803,7 @@ bool autotune(int16_t cal_temp) } // interpolate remaining steps to speed-up calibration + // TODO: verify that the sampled values are monotically increasing? int8_t next = TEMP_MODEL_R_SIZE - 1; for(uint8_t i = TEMP_MODEL_R_SIZE - 2; i != 0; --i) { if(!((TEMP_MODEL_R_SIZE - i - 1) % TEMP_MODEL_CAL_R_STEP)) {