heater: fix residency compare.

labs requires a signed int.
This commit is contained in:
Markus Amsler 2011-03-25 19:31:53 +01:00 committed by Michael Moon
parent 9860d2850f
commit 093d20481e
4 changed files with 4 additions and 4 deletions

View File

@ -269,7 +269,7 @@ void heater_tick(heater_t h, temp_sensor_t t, uint16_t current_temp, uint16_t ta
}
// compare where we're at to where we should be
if (labs(current_temp - heaters_runtime[h].sane_temperature) > TEMP_HYSTERESIS) {
if (labs((int16_t)(current_temp - heaters_runtime[h].sane_temperature)) > TEMP_HYSTERESIS) {
// no change, or change in wrong direction for a long time- heater is broken!
pid_output = 0;
sersendf_P(PSTR("!! heater %d or temp sensor %d broken- temp is %d.%dC, target is %d.%dC, didn't reach %d.%dC in %d0 milliseconds\n"), h, t, current_temp >> 2, (current_temp & 3) * 25, target_temp >> 2, (target_temp & 3) * 25, heaters_runtime[h].sane_temperature >> 2, (heaters_runtime[h].sane_temperature & 3) * 25, heaters_runtime[h].sanity_counter);

View File

@ -269,7 +269,7 @@ void temp_sensor_tick() {
}
temp_sensors_runtime[i].last_read_temp = temp;
if (labs(temp - temp_sensors_runtime[i].target_temp) < TEMP_HYSTERESIS) {
if (labs((int16_t)(temp - temp_sensors_runtime[i].target_temp)) < TEMP_HYSTERESIS) {
if (temp_sensors_runtime[i].temp_residency < TEMP_RESIDENCY_TIME)
temp_sensors_runtime[i].temp_residency++;
}

View File

@ -269,7 +269,7 @@ void heater_tick(heater_t h, temp_sensor_t t, uint16_t current_temp, uint16_t ta
}
// compare where we're at to where we should be
if (labs(current_temp - heaters_runtime[h].sane_temperature) > TEMP_HYSTERESIS) {
if (labs((int16_t)(current_temp - heaters_runtime[h].sane_temperature)) > TEMP_HYSTERESIS) {
// no change, or change in wrong direction for a long time- heater is broken!
pid_output = 0;
sersendf_P(PSTR("!! heater %d or temp sensor %d broken- temp is %d.%dC, target is %d.%dC, didn't reach %d.%dC in %d0 milliseconds\n"), h, t, current_temp >> 2, (current_temp & 3) * 25, target_temp >> 2, (target_temp & 3) * 25, heaters_runtime[h].sane_temperature >> 2, (heaters_runtime[h].sane_temperature & 3) * 25, heaters_runtime[h].sanity_counter);

2
temp.c
View File

@ -269,7 +269,7 @@ void temp_sensor_tick() {
}
temp_sensors_runtime[i].last_read_temp = temp;
if (labs(temp - temp_sensors_runtime[i].target_temp) < TEMP_HYSTERESIS) {
if (labs((int16_t)(temp - temp_sensors_runtime[i].target_temp)) < TEMP_HYSTERESIS) {
if (temp_sensors_runtime[i].temp_residency < TEMP_RESIDENCY_TIME)
temp_sensors_runtime[i].temp_residency++;
}