From 707c4f35de584f9cae95213b721f4405ec8d59d5 Mon Sep 17 00:00:00 2001 From: David Forrest Date: Sun, 16 Mar 2014 09:22:54 -0400 Subject: [PATCH] heater.c: Limit PID I term with conditional integration. --- heater.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/heater.c b/heater.c index dfb2c51..9fe1cc1 100644 --- a/heater.c +++ b/heater.c @@ -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;