From 64326d0dea5e285f4cd27238e4c9b4a951b6411a Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Sun, 10 May 2026 11:07:21 +0200 Subject: [PATCH] fix delta calc to signed --- fw/main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fw/main.c b/fw/main.c index 2653cf3..5fa990f 100644 --- a/fw/main.c +++ b/fw/main.c @@ -496,6 +496,7 @@ __attribute__((noreturn)) int main(void) u32 tip_mv = ((u32)injection_results[0]*VCC_MV)/4096; tip_temp_c = I16_FP_EMA_K2(tip_temp_c, (tip_mv*TC_CONV_NOM)/TC_CONV_DEN) + temp_c; } + int16_t delta = (int16_t)pd_profile.set_temp - tip_temp_c; switch (state) { case STATE_MENU: @@ -526,7 +527,7 @@ __attribute__((noreturn)) int main(void) // Display power //u8g2_DrawStr(u8g2, x_off+0, y_off+15, "W:"); //u8g2_DrawStr(u8g2, x_off+10, y_off+15, u8g2_u16toa(power, 3)); - u8g2_DrawStr(u8g2, x_off+0, y_off+15, i16toa(pd_profile.set_temp - tip_temp_c)); + u8g2_DrawStr(u8g2, x_off+0, y_off+15, i16toa(delta)); // Display current u8g2_DrawStr(u8g2, x_off+45, y_off+15, "A:"); u8g2_DrawStr(u8g2, x_off+55, y_off+15, u16toa(current_ma)); @@ -560,10 +561,8 @@ __attribute__((noreturn)) int main(void) const uint16_t tim_max = FUNCONF_SYSTEM_CORE_CLOCK / PWM_FREQ_HZ - 1; static int16_t err_p, err_i, err_d, prev_delta; - int16_t delta = pd_profile.set_temp - tip_temp_c; err_p = delta; - err_i += delta; - err_i = MAX(-1000, MIN(1000, err_i)); + err_i = MAX(-1000, MIN(1000, err_i+delta)); err_d = delta - prev_delta; prev_delta = delta;