Hi Guys, I am trying to build a PID controller that will run an element connected to an SSR. I used the PID Adaptive Tuning Example as a start point however what I am having issues with is overshoot.
The element is a 200W ceramic element connected to machine aluminium slug. there is enough material there to be able retain heat for a fair amount of time but what I am getting is a huge amount of overshoot.
For instance if i turn the 10K pot up and adjust the set temperature to 119 degrees (or there about) i get an overshoot of 10 or so degrees.
Below is the log of what I am getting as the temperature climbs but i am not sure what I should be adjusting to reduce the overshoot as the temperature climbs.
Any suggestions as to what to tweak would be greatly appreciated as I think i have lost a few more hairs from trying to work this out. The good news however is that once the peak is reached the unit cools back down and sits at the set temperature quit well however I would rather not exceed the set temperature on its way up for this project.
Set Point: 119.36 Thermistor: 116.46 Output :103.56
Set Point: 119.36 Thermistor: 116.46 Output :91.59
Set Point: 119.36 Thermistor: 118.33 Output :92.60
Set Point: 119.36 Thermistor: 118.33 Output :85.61
Set Point: 119.36 Thermistor: 120.33 Output :73.61
Set Point: 119.36 Thermistor: 120.33 Output :59.60
Set Point: 119.36 Thermistor: 121.42 Output :81.59
Set Point: 119.36 Thermistor: 122.45 Output :61.57
Set Point: 119.36 Thermistor: 123.62 Output :55.55
Set Point: 120.33 Thermistor: 124.73 Output :49.52
Set Point: 119.36 Thermistor: 125.98 Output :49.48
Set Point: 119.36 Thermistor: 124.73 Output :37.44
Set Point: 119.36 Thermistor: 127.17 Output :43.39
Set Point: 120.33 Thermistor: 128.40 Output :43.33
Set Point: 119.36 Thermistor: 129.81 Output :32.28
Set Point: 119.36 Thermistor: 129.81 Output :24.22
Set Point: 119.36 Thermistor: 131.15 Output :19.15
Set Point: 119.36 Thermistor: 131.15 Output :26.08
Set Point: 119.36 Thermistor: 132.54 Output :0.00
Set Point: 119.36 Thermistor: 132.54 Output :13.77
Set Point: 120.33 Thermistor: 132.54 Output :0.00
Set Point: 119.36 Thermistor: 134.14 Output :0.00
Set Point: 120.33 Thermistor: 134.14 Output :0.00
Set Point: 120.33 Thermistor: 134.14 Output :0.00
Set Point: 118.33 Thermistor: 134.14 Output :0.00
Set Point: 119.36 Thermistor: 137.25 Output :0.00
#include <PID_v1.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,16,2); // set the LCD address for a 16x2 line display
#define PIN_INPUT A0
#define PIN_OUTPUT 3
#define ThresholdPin 1 //Analog pin temp pot connected
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Define the aggressive and conservative Tuning Parameters
//double aggKp=60, aggKi=0.2, aggKd=2;
//double consKp=1, consKi=0.005, consKd=0.25;
double aggKp=16, aggKi=0.2, aggKd=2;
double consKp=6, consKi=0.005, consKd=0.1;
unsigned long modelTime, serialTime;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);
double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
//Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
return Temp;
}
void setup()
{
pinMode(PIN_INPUT, INPUT);
pinMode(PIN_OUTPUT, OUTPUT);
Serial.begin(57600);
//initialize the variables we're linked to
Input = analogRead(PIN_INPUT);
Setpoint = 900;
//turn the PID on
myPID.SetMode(AUTOMATIC);
serialTime = 0;
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0); //Start at character 0 on line 0
lcd.print(" SET TEMP OUT");
}
void loop()
{
Input = analogRead(PIN_INPUT);
Setpoint = map(analogRead(ThresholdPin),0,1023,0,1023);
double gap = abs(Setpoint-Input); //distance away from setpoint
if (gap <= 10)
{ //we're close to setpoint, use conservative tuning parameters
myPID.SetTunings(consKp, consKi, consKd);
}
else
{
//we're far from setpoint, use aggressive tuning parameters
myPID.SetTunings(aggKp, aggKi, aggKd);
}
myPID.Compute();
analogWrite(PIN_OUTPUT, Output);
if(millis()>serialTime)
{
//lcd.print("SET TEMP OUT")
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(Thermister(Setpoint), 1);
lcd.setCursor(6,1);
lcd.print(Thermister(Input), 1);
// lcd.setCursor(0,1);
lcd.setCursor(13,1);
lcd.print(Output, 1);
Serial.print("Set Point: ");Serial.print(Thermister(Setpoint), 2); Serial.print(" Thermistor: ");Serial.print(Thermister(Input), 2); Serial.print(" Output :");Serial.println(Output, 2);
serialTime+=1500;
}
}