PID controller for slow heater - Page 1
Forum section: electronics / beginners

author: Brathahn
author_rank: Contributor
timestamp: March 12, 2022, 02:43:27 pm
content: Hello everyone,i want to design a whirlpool heater with a PID controller.Yes, PID controllers are a well covered topic but all i have found so far, only covers fast changing control loops.Since its a lot of water to heat up, it takes around 1 minute for a change in temperature.i made a graph of the actual response when the heater is turned on manually:My questions/ideas:-I dont need the D-term (PI-controller) as there are no fast changes anyway.-What sampletime would a system like this need? Since its very slow i think around 1-5 seconds would be fine? My thinking behind this is: if i sample too often, the I-term will wind up and the controller will oscillate.-As PID controllers calculate an error, how do you convert an error in temperature (°C) to 0-100% for the heater?-Is it a good idea to switch between crontrol modes depending on temperature? PID when within 5°C of setpoint, otherwise simple ON/OFF.-Where should i place the temperature sensor? at the moment its before the heater: (can be changed)Thanks for your ideas!

author: Kleinstein
author_rank: Super Contributor
timestamp: March 12, 2022, 05:22:13 pm
content: If one needs the D term depends on the speed one is aiming for. With the D term the regulation can be faster, but the setting of the parameters gets more critical and difficult.If there is no D term, the sampling time for the termometer does not really matter and it can be fast with no problem. The sampling time can become important if a D term is included, as in the simple form the sampling time also sets the interval over which the derivative is calculated. So the Sampling time takes over the funktion of the 4 th parameter to set the final high frequency limit. For some reason this parameter is usually ignored in the usual theory - though it has to be there in a real regulator, as there is not true D element (can't to differentiation all the way to day-lighte an beyound).The sampling time is included in the factor to set the effect of the integral part. So with faster sampling the numbers add up faster, but the factor to multiply with gets smaller to compensate.For the position of the sensor it depends. The sensor before the pump is relatively far away from the heater, and this the relatively large delay. One kind of needs this position to get a reasonable accurate values, though for the regulaton speed it is not ideal.There is no real need to use seprate control mechanisms for the close by and far off range. PI(D) with anti wind-up has no problem coming out of the full on phase with much delay. With a fixed system and little external disturbance, 2 separate regions may get a slightly faster settling with a well trimmed parameter of the switch over conditions or starting conditions. However a full PID regulator would likely be even faster.The measured step response curve can be used to calculate the suitable PI (D) parameters from one of the usual design / adjustment rules (e.g. Nichols Ziegler). There is a clear delay and slope and chances are the system is reasonable well behaved.

author: Siwastaja
author_rank: Super Contributor
timestamp: March 12, 2022, 05:53:42 pm
content: Don't overcomplicate it.On/off hysteretic (classical thermostat) might be good enough. If not, P likely is, if the heater power is not excessively high; P controllers are widely used in HVAC etc.I term can be of course added to remove the tiny constant error that results from the P controller - or, just finetune the setpoint accordingly and live with P.Example of what P controller is:Gain = 50% per degC:Setpoint = 50 degC, measured = 49.0 degC, output power = 100%Setpoint = 50 degC, measured = 49.5 degC, output power = 75%Setpoint = 50 degC, measured = 50 degC, output power = 50%Setpoint = 50 degC, measured = 50.5 degC, output power = 25%Setpoint = 50 degC, measured = 51.0 degC, output power = 0%I have controlled a chemical process within 0.1degC or so with a simple P controller. The trick was just agitated (stirred) tank, which responds well without overshoot, and a constant setpoint (that required by the chemical process; it doesn't change) and fairly consistent ambient temperature. In such conditions, all you need is to determine the power setting needed to maintain the desired temperature, and then add a steep P term around that. Deviations from the assumptions (i.e., changing ambient, changing setpoint) then cause a small offset error. Which can be corrected by manually adjusting the setpoint, or adding an I term with small gain.

author: Etesla
author_rank: Regular Contributor
timestamp: March 12, 2022, 10:42:40 pm
content: Siwastaja is probably right. Keep it simple until you can prove that simple isn't good enough.However, if you want to try to use a custom PID controller you'll learn a lot doing it and I'm all for it. The key here is simulation because the system is so slow. It's just not worth it to try to tune the parameters in real time like it is with a faster system. You spend too much time waiting on results. Simulating what's going on in a simple way is not very difficult, here's the process.The steps to model and simulate your system are as follows:1.) Decide on a sampling time in seconds (Ts) that you will use for the rest of this process. For this slow of a system, probably a Ts of about 60 seconds will work OK. You can experiment with this number to see what works best in the future. Leave it configurable.2.) Gain control of the heating element using a microcontroller. Probably you'll control the thing with a 'duty cycle' which means you'll turn the heating element for X% of the time out of Ts where X is 0-1003.) Feed the whirlpool thing a stepped set of inputs (like 0.1 for 45 minutes, then 0.5 for 45 minutes, then 0.3 for 45 minutes, then 1.0 for 45 minutes, then 0.8 for 45 minutes then 0.0 for 120 minutes would probably be a good first attempt). Record the PWM% 'input' and the temperature 'output' once every Ts seconds into a .csv file or something. This is example data that will help you characterize the whirlpool system in the next step.4.) Set up a for loop in some programming language you're familiar with (python, matlab, something like that). You'll be doing a lot of plotting. The first step is to model the whirlpool system itself as something that takes an input (duty cycle out of 1) and has an output (temperature)The pseudo code for what you're going to put together is this:// initialize stuffreal output = output temperatures measured in step 3 as an arrayreal input = input duty cycles measured in step 3 as an arraysimulatedOutput = emptyArray(length(dataFromStep3))initialTemperature = real output(0)A = .1B = 0.9i = 0 // just a counter// run a 'simulation'for(every (real input, real output) point you measured in step 3) {simulatedOutput(i) = simulatedOutput(i-1)*B + real input(i)*A}simulatedOutput = simulatedOutput + initialTemperature // add the initial temperature offsetplot({real input, real output}, {real input, simulatedOutput}) // your goal is to adjust A and B so that the 'simulatedOutput' plot overlaps as best as you can get it with the 'real output' plot.There is a 'discrete time z domain 1st order' transfer function that you altering by adjusting A and B that is being used to model the whirlpool thing which is usually referred to as the 'plant' in the control system. You don't have to get it perfect, just try to get it close. If you're curious that transfer function is:A Output(z)-------- = --------------1 - B*z^(-1) Input(z)You can do a lot of learning / reading about this discrete time transfer function stuff, but just remember that all one of these is saying is that the current output depends on some factors*previous outputs and some other factors*previous and current inputs. Simple as that, just like you see in the pseudocode.5.) Now that you have A and B guesstimated, you can use that to simulate how the system will react to your PID tuning. This is the simulation part.Put together another for loop like this:// setupsetpointInDegreesC = 70 // the target temperature you'll aim forinitialTemperatureInDegreesC = 30currentTemperatureDegreesC = initialTemepratureInDegreesCpreviousError = 0;Dterm = 0; // totally arbitrary first guessesIterm = .001;Pterm = 2;Imax = 100000; // anti windupImin = -100000;Isum = 0;simulationTimeSeconds = 0->1200 // pretty arbitraryfor(all the time in simulationTimeSeconds once every Ts seconds) { // run the simulation// code the MCU would actually be running in real time once every Ts seconds. This IS a standard PID controller. It's really very simple.previousError = errorerror = setpointInDegreesC - currentTemperatureDegreesCIsum += Errorif(Isum > Imax) {Isum = Imax}if(Isum < Imin) {Isum = Imin}dutyCycleApplied = error*Pterm + (error - previousError)*Dterm + Isum*Iterm // this is the line where the error is turned into a PWM% out of 1, which is usually referred to as the 'control effort'if(dutyCycleApplied > 1) { // doesn't make sense to have a duty cycle > 1 or < 0, so clip that numberdutyCycleApplied = 1}if(dutyCycleApplied < 0) {dutyCycleApplied = 0}// simulated output so that you don't have to wait and see how the thing actually performs in real life. The real MCU code in the real application doesn't have a reason to include the code from this point down.currentTemperatureDegreesC = currentTemperatureDegreesC*B + dutyCycleApplied*A}plot({simulatedTimeSeconds, currentTemperatureDegreesC}, {simulatedTimeSeconds, setpointInDegreesC})6.) now you just adjust your P I and D values until the output simulated temperature goes to the setpointInDegreesC temperature in a reasonable amount of time without too much overshoot. Then you can carry those values over to your microcontroller and try it for real. Basically you're just checking that your PID values don't cause the output temperature to get out of control or oscillate or land too far off of the target temperature. Definitely recommend also plotting dutyCycleApplied and maybe Isum as well for further understanding and troubleshooting purposes.That's all there is too it for a first attempt. Hopefully your question of how to convert error to a PWM% is answered by the above pseudocode.You can easily experiment with your other ideas once you have this simulation set up.There's a bunch of stuff that you could have done to make this process more accurate and stuff. For example, you could use matlab and something like the system identification toolbox to really nail down a good model for your plant. You could use Matlab and the PID tuner to find a robust set of PID parameters that works well for your system. You could analyze the system for it's sensitivity to different parameters and adjust things to make it more robust. You could include a delay in the model of the plant and use a higher sampling rate. But the above procedure is pretty easy to follow with any tools that you have available to you and you don't need a lot of background information so maybe try that first and then complicate it as needed... Always a fan of getting something simple going and then learning from there as you encounter issues.

author: Kleinstein
author_rank: Super Contributor
timestamp: March 13, 2022, 09:10:51 am
content: A high power heater may not allow a simple linear control. There are limits on how much power can be used with SCR phase angle switching. So one may have to use some on/off control or PWM (using full cycles with zero voltage switching) with a realatively large cycle time. To be kind to the grid, 2 seprate regulator settings may for this reason makes sense.A simulation is indeed a good idea an it is not that difficult. I did that onc, based on the pulse response and than just simple step wise adding to pulse responses from the past time steps. The model does not even have to be that accurate. It is mainly about the initial part of the response with the higher frequencies. Errors in the part with a long delay usually don't effect the stability and the regulators are usually working well in this region.With a modern computer even a not so effective simulation can be way faster than the real thing.

author: Siwastaja
author_rank: Super Contributor
timestamp: March 13, 2022, 12:42:38 pm
content: Obviously no phase dimming. Switch full semicycles. For this, a pre-engineered optoisolated SSR is the right tool. Make sure it's not "random" switching type. PWM control can then be at frequency around 1Hz or even lower.

author: Brathahn
author_rank: Contributor
timestamp: March 16, 2022, 03:35:17 pm
content: Thanks everyone for the elaborate answers! Sorry for the late reply.@EteslaThe simulation of the process seems a bit complicated but i will give it a try.And i will place the sensor behind the heater to reduce the delay as much as possible. actually i just add another temp sensor, and use that one. maybe together with the first one, i can calculate the delta-t of the heater. i dont know if thats any help to the regulator itself.@Siwastajai already have a big 3-phase ssr that is driven by a slow pwm. no dimming needed.