diff --git a/Core/Src/Gui/screen_calibration.c b/Core/Src/Gui/screen_calibration.c index a17a17c..3cb45e3 100644 --- a/Core/Src/Gui/screen_calibration.c +++ b/Core/Src/Gui/screen_calibration.c @@ -81,6 +81,7 @@ static void sample1_menu_cb(int opt) { // Continue next_phase(); request_paint(); + s_calib.temp1 = 100; s_calib.sample1 = app_temp_read_oven_raw(); app_heater_enable(false); break; @@ -104,6 +105,7 @@ static void sample2_menu_cb(int opt) { // Continue next_phase(); request_paint(); + s_calib.temp2 = 200; s_calib.sample2 = app_temp_read_oven_raw(); app_heater_enable(false); break; @@ -197,6 +199,8 @@ void screen_calibration(GuiEvent event) next_phase(); request_paint(); + PRINTF("KNOB_REL PH %d\r\n", s_calib.phase); + if (s_calib.phase == PH_DONE) { app_heater_set_target(0); app_heater_enable(false); diff --git a/Core/Src/app_heater.c b/Core/Src/app_heater.c index a490343..03e0616 100644 --- a/Core/Src/app_heater.c +++ b/Core/Src/app_heater.c @@ -188,6 +188,8 @@ void app_task_heater(void *argument) heaterEnterCritical(); // TODO load from flash PID_SetTunings(&state.pid, state.tuning_p, state.tuning_i, state.tuning_d); + PID_SetOutputLimits(&state.pid, 0, 100); + PID_SetITermLimits(&state.pid, 0, 100); PID_Initialize(&state.pid); heaterExitCritical(); diff --git a/Core/Src/app_knob.c b/Core/Src/app_knob.c index ff4bb2c..23a8bf8 100644 --- a/Core/Src/app_knob.c +++ b/Core/Src/app_knob.c @@ -71,7 +71,7 @@ bool app_knob_pushed() { void app_knob_push_isr(bool push) { - PUTCHAR(push ? '#' : '.'); + //PUTCHAR(push ? '#' : '.'); BaseType_t yield = pdFALSE; if (push) { diff --git a/Core/Src/app_pid.c b/Core/Src/app_pid.c index 6d1af5e..0187dff 100644 --- a/Core/Src/app_pid.c +++ b/Core/Src/app_pid.c @@ -13,8 +13,8 @@ static void clampOutput(struct PID *self) static void clampIterm(struct PID *self) { - if (self->ITerm > self->outMax) { self->ITerm = self->outMax; } - else if (self->ITerm < self->outMin) { self->ITerm = self->outMin; } + if (self->ITerm > self->iTermMax) { self->ITerm = self->iTermMax; } + else if (self->ITerm < self->iTermMin) { self->ITerm = self->iTermMin; } } void PID_Compute(struct PID *self, float input) @@ -32,6 +32,11 @@ void PID_Compute(struct PID *self, float input) clampIterm(self); + // Shortcut to reduce overshoot + if (error < 0 && self->ITerm > 0) { + self->ITerm = 0; + } + float dInput = (input - self->lastInput); @@ -91,6 +96,14 @@ void PID_SetOutputLimits(struct PID *self, float min, float max) self->outMax = max; clampOutput(self); +} + +void PID_SetITermLimits(struct PID *self, float min, float max) +{ + if (min > max) { return; } + self->iTermMin = min; + self->iTermMax = max; + clampIterm(self); } diff --git a/Core/Src/app_pid.h b/Core/Src/app_pid.h index a84bfb6..71c1566 100644 --- a/Core/Src/app_pid.h +++ b/Core/Src/app_pid.h @@ -27,6 +27,7 @@ struct PID { float kp, ki, kd; uint32_t SampleTimeTicks; float outMin, outMax; + float iTermMin, iTermMax; enum PIDCtlMode ctlMode; // false enum PIDDirection controllerDirection; }; @@ -41,6 +42,8 @@ void PID_SetSampleTime(struct PID *self, uint32_t new_sample_time); void PID_SetOutputLimits(struct PID *self, float min, float max); +void PID_SetITermLimits(struct PID *self, float min, float max); + void PID_SetCtlMode(struct PID *self, enum PIDCtlMode mode); void PID_Initialize(struct PID *self);