heater.c: Limit PID I term with conditional integration.

This commit is contained in:
David Forrest 2014-03-16 09:22:54 -04:00 committed by Markus Hitter
parent 4ccca52367
commit 707c4f35de
1 changed files with 11 additions and 5 deletions

View File

@ -328,11 +328,17 @@ void heater_tick(heater_t h, temp_type_t type, uint16_t current_temp, uint16_t t
) / PID_SCALE
);
// rebase and limit factors
if (pid_output_intermed > 255)
pid_output = 255;
else if (pid_output_intermed < 0)
pid_output = 0;
// rebase and limit factors
if (pid_output_intermed > 255) {
if (t_error > 0)
heaters_runtime[h].heater_i -= t_error; // un-integrate
pid_output = 255;
}
else if (pid_output_intermed < 0) {
if (t_error < 0)
heaters_runtime[h].heater_i -= t_error; // un-integrate
pid_output = 0;
}
else
pid_output = pid_output_intermed & 0xFF;