matho
Active Member
Hey fastTalker,
I never said that PID control isn't suited for heating water, I said I don't think the arduino PID library is very well suited for heating water.
here are my thoughts on the library, I could be wrong.
With the default sample time set to
that would mean using a DS18B20 with a 12 bit resolution the conversion time is about 750mS the Iterm would have 7 increases before D could even get calculated, it gets worse when you put in the time it takes to ramp the temperature of the water. If the rate of rise is 2 deg c / min then that equates to 0.033 deg c / second, the finest resolution for a DS18B20 is 0.0625 degc so that means a measured temperature change every 2 seconds which would allow Iterm to increase 20 times before D would have a value
If I term is there to remove a constant error that persists with a P drive only, which it is, why is it allowed to ramp to 100% of the output? If you had a constant error that required 100% output then your drive system is too small. I believe that for D to really be effective it should be subtracted from I term like this
that would allow D to stop Iterm from winding up if the rate of change is large enough.
The last thing is if you increase the sample time the D gain is reduced and the I gain is increased.
I believe that the PID library would be well suited for fast responding symmetrical drive systems like motors but for heating water it isn't quite right but can be worked around.
Again, these are just my thoughts and I could be wrong as I'm not an expert on PID systems
cheers steve
I never said that PID control isn't suited for heating water, I said I don't think the arduino PID library is very well suited for heating water.
here are my thoughts on the library, I could be wrong.
With the default sample time set to
Code:
SampleTime = 100;
that would mean using a DS18B20 with a 12 bit resolution the conversion time is about 750mS the Iterm would have 7 increases before D could even get calculated, it gets worse when you put in the time it takes to ramp the temperature of the water. If the rate of rise is 2 deg c / min then that equates to 0.033 deg c / second, the finest resolution for a DS18B20 is 0.0625 degc so that means a measured temperature change every 2 seconds which would allow Iterm to increase 20 times before D would have a value
Code:
void PID::Compute()
{
if(!inAuto) return;
unsigned long now = millis();
unsigned long timeChange = (now - lastTime);
if(timeChange>=SampleTime)
{
/*Compute all the working error variables*/
double input = *myInput;
double error = *mySetpoint - input;
ITerm+= (ki * error);
if(ITerm > outMax) ITerm= outMax;
else if(ITerm < outMin) ITerm= outMin;
double dInput = (input - lastInput);
/*Compute PID Output*/
double output = kp * error + ITerm- kd * dInput;
if(output > outMax) output = outMax;
else if(output < outMin) output = outMin;
*myOutput = output;
/*Remember some variables for next time*/
lastInput = input;
lastTime = now;
}
}
If I term is there to remove a constant error that persists with a P drive only, which it is, why is it allowed to ramp to 100% of the output? If you had a constant error that required 100% output then your drive system is too small. I believe that for D to really be effective it should be subtracted from I term like this
Code:
ITerm-=(Kd*dInput);
double output = kp * error + ITerm;
that would allow D to stop Iterm from winding up if the rate of change is large enough.
Code:
void PID::SetTunings(double Kp, double Ki, double Kd)
{
if (Kp<0 || Ki<0 || Kd<0) return;
dispKp = Kp; dispKi = Ki; dispKd = Kd;
double SampleTimeInSec = ((double)SampleTime)/1000;
kp = Kp;
ki = Ki * SampleTimeInSec;
kd = Kd / SampleTimeInSec;
if(controllerDirection ==REVERSE)
{
kp = (0 - kp);
ki = (0 - ki);
kd = (0 - kd);
}
}
The last thing is if you increase the sample time the D gain is reduced and the I gain is increased.
I believe that the PID library would be well suited for fast responding symmetrical drive systems like motors but for heating water it isn't quite right but can be worked around.
Again, these are just my thoughts and I could be wrong as I'm not an expert on PID systems
cheers steve