Correction overflow protection

This commit is contained in:
Javier Arigita 2020-04-26 08:48:03 +02:00
parent c577a955b0
commit 83cdd2f26f
1 changed files with 4 additions and 4 deletions

View File

@ -402,10 +402,10 @@ void ThermostatCalculatePI(void)
aux_time_error = (int32_t)(Thermostat.temp_target_level_ctr - Thermostat.temp_measured) * 10; aux_time_error = (int32_t)(Thermostat.temp_target_level_ctr - Thermostat.temp_measured) * 10;
// Protect overflow // Protect overflow
if (aux_time_error >= (int32_t)(INT16_MIN)) { if (aux_time_error <= (int32_t)(INT16_MIN)) {
Thermostat.temp_pi_error = (int16_t)(INT16_MIN); Thermostat.temp_pi_error = (int16_t)(INT16_MIN);
} }
else if (aux_time_error <= (int32_t)INT16_MAX) { else if (aux_time_error >= (int32_t)INT16_MAX) {
Thermostat.temp_pi_error = (int16_t)INT16_MAX; Thermostat.temp_pi_error = (int16_t)INT16_MAX;
} }
else { else {
@ -459,10 +459,10 @@ void ThermostatCalculatePI(void)
aux_time_error = (int32_t)Thermostat.temp_pi_accum_error + (int32_t)Thermostat.temp_pi_error; aux_time_error = (int32_t)Thermostat.temp_pi_accum_error + (int32_t)Thermostat.temp_pi_error;
// Protect overflow // Protect overflow
if (aux_time_error >= (int32_t)INT16_MIN) { if (aux_time_error <= (int32_t)INT16_MIN) {
Thermostat.temp_pi_accum_error = INT16_MIN; Thermostat.temp_pi_accum_error = INT16_MIN;
} }
else if (aux_time_error <= (int32_t)INT16_MAX) { else if (aux_time_error >= (int32_t)INT16_MAX) {
Thermostat.temp_pi_accum_error = INT16_MAX; Thermostat.temp_pi_accum_error = INT16_MAX;
} }
else { else {