hello,
i am using a PLC to control an immersion heater and am having issues with the PID control. it works well until it reaches the temperature setpoint, then it will output zero and the heater stays on. the code I am using is just copied from the example on github. below is relevant code. any suggestions would be appreciated
cheers
#include <P1AM.h>
#include <PID_v1.h>
double hot_temp = 200; //target hot temp
double hot_max = 250; //hot tank max temp
double hot_tank_temp; //hot tank temp. slot 4 channel 2
bool heater; //contactor to control heater. slot 3 channel 7
double Setpoint, Input, Output;
double Ki=1, Kp=0, Kd=0;
PID PID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
unsigned long pid_time;
int pid_delay = 15000; //pid loop time delay, ms
void setup() {
pid_time = millis(); //pid start time
setpoint = hot_temp; //hot pid setpoint
PID.SetOutputLimits(0, pid_delay);
PID.SetMode(AUTOMATIC);
}
void loop() {
pid_control();
}
void pid_control() {
input = hot_tank_temp;
setpoint = hot_temp;
PID.Compute();
if (millis() - pid_time > pid_delay) {
pid_time += pid_delay;
}
if (hot_tank_temp < (0.85 * hot_temp)) { //ramp up to heat tank on start
heater = true;
} else {
if (output < (millis() - pid_time)) { //only turn heater on if there is no estop active
heater = true;
} else {
heater = false;
}
}
}