PID for temperature controlhttps://www.microchip.com/forums/(c) Microchip30Re: PID for temperature control (NKurzman)For Classic PID your Out put is 0 to 100%<br/>Rather than try to force the PID math to match your control signal, you should have a separate function to do the translation .<br/>That said this application does not really call for a PID loop. logic to limit the current if the Temp is too high would probably work just as well, and not require tuning.<br/> <br/>" I am worried about integral part. It will keep increasing when the temperature is less than 95"<br/>This is called "integral wind up" you can google to find one of the many solutions for it.<br/>https://www.microchip.com/forums/FindPost/1119795Fri, 22 Nov 2019 09:25:54 GMTRe: PID for temperature control (Mysil)No,<br/>Scaling PID input, and scaling PID output will have different effects.<br/>Scaling PID input will be done in units and measurement range of your sensors,<br/>scaling PID output will work in the units and range of your PWM Input.<br/>Anyway, the PID regulation loop will try to make the error signal value smaller,<br/>regardless of any input or output scaling you make.<br/>That is unless there is a mistake in a sign somewhere, then it surely will run away.<br/> <br/>There are different scaling effects in work already,<br/>both on PID input caused by the properties of the temperature sensor,<br/>and on PID output, caused by properties of the PWM code.<br/> <br/>I suspect that you may have some difficulty to get PID output to be 4500 at 95 Celsius,<br/>by manipulating Kp, Ki and Kd only.<br/>I think you may make a translation of PID output like this, <br/>either: PWM input = PID output + 4500;<br/>or maybe: PWM input = 4500 - PID output;<br/>beware, changing the sign here will have an effect on the sign of input scaling required.<br/> <br/> Mysil<br/>https://www.microchip.com/forums/FindPost/1119600Thu, 21 Nov 2019 07:14:32 GMTRe: PID for temperature control (GunkutA)Thank you Mysil, that suggestions will help me a lot. Especially dynamic setpoint suggestion. Is it same to make scaling in PID input or PID output? I was thinking of making the scaling at the output. Something like this: <br/> <br/>PID output = (error * Kp + integral * Ki*dt+ derivative * Kd /dt)<br/> <br/>And setting up the Kp, Kd and Ki so that at 95 Celsius PID output will be 4500, and as it increases PID output will be decreasing. But that seems like a wrong way actually.<br/>https://www.microchip.com/forums/FindPost/1119460Wed, 20 Nov 2019 05:22:36 GMTRe: PID for temperature control (Mysil)Hi,<br/>In this case, you have a regulation goal that is not linear.<br/>You may try to change the PID regulator setpoint value for temperature, to be the same as the actual temperature measured, as long as the temperature is below the maximum (95 degree C).<br/> <br/>But I think there are 2 regulation loops here, one is for the temperature,<br/>the other is for current 2 Ampere or PWM duty cycle 4500, <br/>in order for the PID regulator algorithm to give any output at all.<br/> <br/>You might try to make a scaled combination of temperature and current for PID input and setpoint,<br/>something like<br/>PID Input = Temperature * ScaleT - Current * ScaleC;<br/>PID Setpoint = minimum(Temperature, 95degreeC) * ScaleT - 2Ampere * ScaleC;<br/> <br/>I did put in a minus sign in the scaling expression for the current,<br/>because of the inverted behaviour of your PWM code, higher PWM input giving less current.<br/>A negative scaling factor would have the same effect.<br/> <br/>For testing regulation settings, you might try to run with a lower temperature limit,<br/>maybe 35 degree C, temporarily to study how the regulation works.<br/>And maybe put in some independent safety code,<br/>to shut down completely in case the measured temperature exceed setpoint temperature + 10 degreeC.<br/> <br/>Maybe using PWM regulation in this application might be overkill,<br/>you might get by with something like:<br/><pre class="prettyprint"> if (temperature < 90)<br /> PWM = 4500;<br /> else if (temperature < 91)<br /> PWM = 5500;<br /> else if (temperature < 92)<br /> PWM = 6500;<br /> else if (temperature < 93)<br /> PWM = 7500;<br /> else if (temperature < 94)<br /> PWM = 8500;<br /> else if (temperature < 95)<br /> PWM = 9500;<br /> else<br /> PWM = 9999; </pre><br>But integrating and testing PID regulation code in your program, will be a more useful learning experience. <br/> <br/>Regards,<br/> Mysil<br/>https://www.microchip.com/forums/FindPost/1119454Wed, 20 Nov 2019 04:20:39 GMTPID for temperature control (GunkutA)Hello, I am creating a Li-ion battery discharger. Only thing left is temperature control loop right now and I want to use PID for that purpose. I want to keep the temperature inside the device at max 95 Celsius. I am using PWM to set the discharging current. Which is 4500 for 2 Ampere ( maximum rate) and 9999 is the minimum discharging rate which is 0 ampere. So I will be discharging the battery at 2 ampere till temperature ( if it will ) reaches the 95 Celsius then I want to increase PWM values according to PID which will decrease the discharging current. However I cannot figure out how PID will be used for this purpose. I though following a way like this :<br/>if(temperature<90){}<br/>else{<br/>PID Loop<br/>.<br/>.<br/>.}<br/>Will this approach break the PID loop? If yes then what kind of path I should follow. I am worried about integral part. It will keep increasing when the temperature is less than 95. But since the discharge current is constant 2 amp for this case, temperature will not rise and integral part will be increasing and increasing. And in case of any heat rise, piled up integration will break up the PID term in this case. I am looking forward for all the suggestions. Thanks beforehand.<br/>https://www.microchip.com/forums/FindPost/1119438Wed, 20 Nov 2019 01:24:47 GMT