Temp: have residency updates on 1s clock.

Temperature residency time / temperature achieved check is in
the order of seconds, while updates for residency time were being
called every 10ms - unnecessarily often.
This commit is contained in:
Robert Konklewski 2016-04-18 13:18:05 +02:00 committed by Markus Hitter
parent 8e977d50ce
commit 03c8d71a56
3 changed files with 35 additions and 21 deletions

View File

@ -91,6 +91,8 @@ static void clock_250ms(void) {
display_clock(); display_clock();
#endif #endif
temp_residency_tick();
if (DEBUG_POSITION && (debug_flags & DEBUG_POSITION)) { if (DEBUG_POSITION && (debug_flags & DEBUG_POSITION)) {
// current position // current position
update_current_position(); update_current_position();

52
temp.c
View File

@ -380,27 +380,7 @@ void temp_sensor_tick() {
(EWMA_SCALE-EWMA_ALPHA) * temp_sensors_runtime[i].last_read_temp (EWMA_SCALE-EWMA_ALPHA) * temp_sensors_runtime[i].last_read_temp
) / EWMA_SCALE); ) / EWMA_SCALE);
} }
if (labs((int16_t)(temp_sensors_runtime[i].last_read_temp - temp_sensors_runtime[i].target_temp)) < (TEMP_HYSTERESIS*4)) { }
if (temp_sensors_runtime[i].temp_residency < (TEMP_RESIDENCY_TIME*120))
temp_sensors_runtime[i].temp_residency++;
}
else {
// Deal with flakey sensors which occasionally report a wrong value
// by setting residency back, but not entirely to zero.
if (temp_sensors_runtime[i].temp_residency > 10)
temp_sensors_runtime[i].temp_residency -= 10;
else
temp_sensors_runtime[i].temp_residency = 0;
}
if (DEBUG_PID && (debug_flags & DEBUG_PID))
sersendf_P(PSTR("DU temp: {%d %d %d.%d}"), i,
temp_sensors_runtime[i].last_read_temp,
temp_sensors_runtime[i].last_read_temp / 4,
(temp_sensors_runtime[i].last_read_temp & 0x03) * 25);
}
if (DEBUG_PID && (debug_flags & DEBUG_PID))
sersendf_P(PSTR("\n"));
} }
/** /**
@ -418,6 +398,36 @@ void temp_heater_tick() {
} }
} }
/**
Called every 1s from clock.c. Update temperature residency info.
*/
void temp_residency_tick() {
temp_sensor_t i;
for (i = 0; i < NUM_TEMP_SENSORS; i++) {
if (labs((int16_t)(temp_sensors_runtime[i].last_read_temp - temp_sensors_runtime[i].target_temp)) < (TEMP_HYSTERESIS*4)) {
if (temp_sensors_runtime[i].temp_residency < (TEMP_RESIDENCY_TIME*120))
temp_sensors_runtime[i].temp_residency += 100;
}
else {
// Deal with flakey sensors which occasionally report a wrong value
// by setting residency back, but not entirely to zero.
if (temp_sensors_runtime[i].temp_residency > 100)
temp_sensors_runtime[i].temp_residency -= 100;
else
temp_sensors_runtime[i].temp_residency = 0;
}
if (DEBUG_PID && (debug_flags & DEBUG_PID))
sersendf_P(PSTR("DU temp: {%d %d %d.%d}"), i,
temp_sensors_runtime[i].last_read_temp,
temp_sensors_runtime[i].last_read_temp / 4,
(temp_sensors_runtime[i].last_read_temp & 0x03) * 25);
}
if (DEBUG_PID && (debug_flags & DEBUG_PID))
sersendf_P(PSTR("\n"));
}
/** /**
* Report whether all temp sensors in use are reading their target * Report whether all temp sensors in use are reading their target
* temperatures. Used for M116 and friends. * temperatures. Used for M116 and friends.

2
temp.h
View File

@ -38,6 +38,8 @@ void temp_sensor_tick(void);
void temp_heater_tick(void); void temp_heater_tick(void);
void temp_residency_tick(void);
uint8_t temp_achieved(void); uint8_t temp_achieved(void);
void temp_set(temp_sensor_t index, uint16_t temperature); void temp_set(temp_sensor_t index, uint16_t temperature);