From 7fc3efe6066f82d9da055fbd3091756eb9cd06be Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Mon, 16 Sep 2024 19:59:07 +0200 Subject: [PATCH] Add hysteresys to max water temp handling --- v10/main.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/v10/main.c b/v10/main.c index 6f60cbb..8d5e66f 100644 --- a/v10/main.c +++ b/v10/main.c @@ -69,14 +69,16 @@ volatile char mode = mode_heat; volatile char old_mode = mode_heat; /* Water temperature */ -int water_centi_degrees = 0; +volatile int water_centi_degrees = 0; +#define T_HYST 200 /* 2°C */ +#define T_HYST_DELAY 1800 /* 1800 * DEC_PERIOD : 180 seconds : 3 minutes */ +volatile int temp_OK_hysteresys = 0; + /* Internal temperatures */ int deci_degrees_power = 0; /* Power board sensor */ int deci_degrees_disp = 0; /* Display board sensor */ -/* Set to ABSOLUTE_MAX_WATER_TEMP - 1.5°C when enabling max temp hysteresis */ -int max_temp_hysteresys = 0; /* Value in mA computed upon startup from config ext_source_power_limit */ int32_t max_intensity = 0; @@ -111,6 +113,12 @@ void handle_dec_request(uint32_t curent_tick) overvoltage--; } } + /* Decrease temp hysteresys only when getting bellow max configuration temperature by T_HYST */ + if (temp_OK_hysteresys > 0) { + if (water_centi_degrees < (sc_conf.conf_max_temp - T_HYST)) { + temp_OK_hysteresys--; + } + } } @@ -231,6 +239,10 @@ void handle_cmd_update(uint32_t curent_tick) force_fan = 1; } break; + case mode_water_critical: + /* Water over-temperature limit reached */ + cmd = 0; + break; case mode_manual: case mode_forced: /* Forced heating mode */ @@ -394,14 +406,30 @@ void mode_update(void) } /* Mosfet temperature limit reached or internal temperature above max internal temp */ if ((mosfet_temp_shutdown != 0) || (internal_temp_error_shutdown < 0)) { - old_mode = mode; - mode = mode_overtemp; + if (mode != mode_overtemp) { + old_mode = mode; + mode = mode_overtemp; + } + return; + } + /* Water temperature above absolute maximum limit ? */ + if (water_centi_degrees >= ABSOLUTE_MAX_WATER_TEMP) { + if (mode != mode_water_critical) { + old_mode = mode; + mode = mode_water_critical; + } return; } /* Water temperature reached config limit ? */ if (water_centi_degrees >= sc_conf.conf_max_temp) { mode = mode_temp_OK; /* Max temperature reached */ + temp_OK_hysteresys = T_HYST_DELAY; + return; + } + if (temp_OK_hysteresys > 0) { + mode = mode_temp_OK; /* Max temperature reached */ + /* Do not decrease temp hysteresys here to get more precise duration */ return; } -- 2.43.0