Modeling an Oven with matlab and finding the PID numbers automaticaly - Page 1
Forum section: electronics / projects

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: February 14, 2017, 11:09:42 am
content: HiI have built an oven for my projects, I need to tune the oven temperature to a certain temperature, I have decided to use PID as my controller,Here I have tested the system with my Power elements to it's full power (PWM was set to 1000), yes I can PWM my elements from 0 to 1000. And have read the thermocouple temperature with 500ms sample rate.I'm new to matlab, I wanted to model my oven with the sample data and find the best KI,KP,KD parameters for fine tuning my PID controller.I have attached the Oven data, please guide me to do it, I know it's must be so damn simple.

author: mjkuwp
author_rank: Unknown
timestamp: February 14, 2017, 11:30:52 am
content: What is the power level of the heating elements and the volume (inside dimensions) of the oven? Where do you have your feedback sensor? is it placed in the air in the middle of the oven or somewhere else?

author: ondreji
author_rank: Contributor
timestamp: February 14, 2017, 12:21:36 pm
content: Your data looks like a step response. Find delay time L and time constant T. For Ziegler-Nichols method (response with an overshoot about 25% and good settling time and there are more robust methods):P only: P = T / LPI: P = 0.9L / T, I = .27 T / L / LPID: 1.2T / L, I = .6 T / L / L, D = .6TThen experiment with:P - to change rise timeD - reduce overshoot and settling timeI - tweak steady-state errorAt this point you have PID regulator (analog) and it should be converted to PSD (digital, dt is your temperature measurement sampling time):https://en.wikipedia.org/wiki/PID_controller#Discrete_implementation

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: February 14, 2017, 12:48:36 pm
content: mjkuwp I have about 3KW of elements inside my oven, I'm not sure about my oven dimensions right now, but It's bigger ones in the market. and my sensor is some where in the middle of the right wall hanging from the wall in the Air.ondreji Thanks for your help. I think I wanted to get the Step response of the oven.how did you find the numbers? are they a rough estimate or suggestions. where is matlab instructions to do it with matlab.Regards

author: MagicSmoker
author_rank: Super Contributor
timestamp: February 14, 2017, 12:58:30 pm
content: There is a page on Mathworks site concerning this:https://www.mathworks.com/discovery/pid-control.html

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: February 14, 2017, 02:31:46 pm
content: Thanks MagicSmoker,It's huge, Did you done it before? Do we have a simpler way? or do you have the required matlab commands? remember I'm newbie in matlab and dealing with huge documentation would ruin my dream

author: MagicSmoker
author_rank: Super Contributor
timestamp: February 14, 2017, 03:28:57 pm
content: I don't use Matlab. Feedback loop compensator design is a bit tough, yes. The Ziegler-Nichols method is pretty good at coming up with workable - if not strictly optimal - PID parameters for unknown plants.

author: mark03
author_rank: Frequent Contributor
timestamp: February 14, 2017, 05:03:52 pm
content: When designing my reflow oven (http://www.hau.nz/posts/reflow_oven.html) I found this oven model helpful:http://newton.ex.ac.uk/teaching/CDHW/Feedback/PHY3128-CW070901-1.pdfI calibrated the model by looking at the temperature rise in my oven under full power, then tuned my PID coefs in a MATLAB simulation (the script is linked from my project page); however, these coefs turned out not to be stable in the real system. The problem was that the simulation had perfect (noiseless) temperature measurement, whereas in the real oven, thermocouple data are noisy. You can filter the thermocouple data, but this leads to additional phase lag and oscillation. Thus, the simulation wants a lot more derivative feedback than you can actually get away with in practice. It was a useful learning exercise, though.Note that, depending on the oven, PID control is really overkill. That is certainly true for any off-the-shelf toaster oven.

author: Vtile
author_rank: Super Contributor
timestamp: February 14, 2017, 06:08:04 pm
content: Analog PID is notoriously pita to tune up properly. There is thousands of books written on the subject and hundrets after hundrets of scientific studies.Step response test and Ziegler–Nichols method gives good starting values. I wonder if you are willing to make an analog autotuner, would be great (IDK if anyone were cuckoo enough to build a such back in the days).Go digital discrete PID, you might have better changes to get it right in first place, than trying to build a robust enough analog implementation and only notice after that it didn't work in real life as you expected.Edit. I don't know where I did get the idea that you are doing analog controller..

author: Kleinstein
author_rank: Super Contributor
timestamp: February 14, 2017, 08:05:43 pm
content: Especially with such a large and thus relatively slow oven a digital (software based) control is preferred. I don't think the TO ever planed analog control.There are quite a few rather similar methods to tune an PID from the step response. The Ziegler-Nichols values are one possibility. However the Ziegler-Nichols PID is restricted to a certain ratio (you only use 2 characteristic points of the response curve to fix 3 PID parameters. Still it is a good start.Depending on the furnace details, the response might be different at higher temperature. This could happen if radiative heat transfer gets important and could speed up the response. Still the usually slower response measured at low temperature should give a stable regulation, though not the best possible.A simulation of the response is possible, though this is a little easier if based on the pulse response instead of the step response.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: February 15, 2017, 07:08:49 am
content: Guys thanks, Nobody these days use Analog PID, I'm using a digital PID.Actually I have converted the Arduino PID library to ARM and using it. And my Thermocouple readings are pretty good and I do not see noisy data. I will share some pictures of my oven so if you are curious.I hope together we could make this oven great, because it's fucking great to do itThe cool front panelhttps://ibb.co/fEE7tvAlmost 4Kw of heater elementshttps://ibb.co/cWafDvMeet the micro toaster Rev 1.0 Designed by ASiDesignerhttps://ibb.co/cvEJ0aThe side viewhttps://ibb.co/cxYBLaDidn't I told you it has lot's of connectivityhttps://ibb.co/hkaQfa

author: mark03
author_rank: Frequent Contributor
timestamp: February 15, 2017, 06:17:11 pm
content: That's a nice looking project.How do you hold the thermocouple in contact with the PCB being reflowed? I am still searching for a good way.Are your heater elements shielded from the PCB? I guess the PCB goes above that metal plate, with the heating elements below it? Is there any airflow inside the oven, to get a more uniform temperature across the board?

author: MagicSmoker
author_rank: Super Contributor
timestamp: February 15, 2017, 06:45:56 pm
content: Quote from: mark03 on February 15, 2017, 06:17:11 pmDrill a hole in the top of the oven - between elements, of course - and run a Type J or K thermocouple bead through it. The glass-wool insulation typically used on thermocouples is tough stuff.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: February 17, 2017, 12:12:29 pm
content: I have 3 thermocouples in the oven, And I have hanged my DMM thermocouple around another one to hang in the free air. Also the PCB goes on top of the aluminum plate and all the elements are insulated from the oven. I do not have any fan in the oven. Already I have tried some values for the KP=5.2 KI=0.01 and KD=0 these combination is giving me about 20% overshoot on the set temperature, Please help me find the best values for the PID constants, 20% overshoot in 200 degree means it will go up about 240 dgree which would kill my sensitive parts on the PCB

author: retrolefty
author_rank: Super Contributor
timestamp: February 17, 2017, 02:01:08 pm
content: PID temperature control can be among the more difficult to tune due to often slow laggy process response. I think your KD=0 is a mistake as some derivative control is desirable for this application to combat overshoot. Many small standalone PID temperature controllers (digital) offer a usually proprietary 'auto tune' function that can be a real time saver in tuning temperature PID control parameters.

author: mjkuwp
author_rank: Unknown
timestamp: February 17, 2017, 06:13:47 pm
content: Quote from: mark03 on February 15, 2017, 06:17:11 pmI've had really good success taping the thermocouple to the bottom of a copper plate in the oven.PCB sits on top of the copper plate (which has been blackened to help it absorb energy).Thermocouple is directly under the center of the PCB. The copper plate sits on the wire rack.This is very easy and I just have to account for a small offset between the copper plate and the pcb (typically 5 to 10C). I am watching the oven so I can see the difference when the solder melts. however, since I use lead solder my tolerance is really wide so even worrying about this offset change is probably overkill.with this setup I can simply shuffle boards in and out and not mess with the thermocouple.mark

author: mjkuwp
author_rank: Unknown
timestamp: February 17, 2017, 06:33:54 pm
content: Quote from: ali_asadzadeh on February 14, 2017, 12:48:36 pmI asked because the oven seems to have moved 1C/second at maximum power. I am not certain but this may be too low of power for the load (mass, volume, losses). I am not a soldering expert but I've seen references that heating rates are supposed to be 1.5C/s or 2.0C/s in some stages.I think it is helpful to discuss the constants in terms of real physical units and that is how I documented mine. I didn't parameterize the oven volume but I would say mine is "medium American sized".Constants for setting a temperature (I only use this for preheating boards for rework)http://themzlab.tumblr.com/PIDTempI use this for reflow - controlling theslopeof temperature, not value of it.http://mjkuwp94.tumblr.com/PIDSlopeI also found that I got good control of reflow by using PID to control theslopeof temperature instead of the value of temperature. I have a state machine that controls the reflow process and adjusts the desiredslopeof temperature based on the state. For example during the soak period I adjust the slope of temperature so that I hit 150C after 100 seconds. This state is triggered when C crosses above 100C.I tuned mine by running it over and over and over again and observing the contributions of the P and I and D in excel. so... I guess I did it by human intuition. This is not a challenging PID loop and the main issue is the lag (delay in response) caused by the elements.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: February 18, 2017, 08:24:35 am
content: Thanks for sharing this info, then I want to ask you this question how did you calculate for example that The proportional constant is 32.0 W / deg C , how did you find "meaning a 1 C error will add 32Watts of power to the elements."?

author: mjkuwp
author_rank: Unknown
timestamp: February 18, 2017, 12:38:08 pm
content: Quote from: ali_asadzadeh on February 18, 2017, 08:24:35 amI did not calculate that value. I performed experiments (several years ago) in which I tried different values for P I and D, then ran the oven and observed the response on a temperature and power versus time plot. What is meant is that for each 1C error my PWM command will increase by a value sufficient to get 32W additional power (assuming normal supply voltage of 120V).I'm suppose there is a math model that could be created to calculate these constants and predict the response but I took a more practical approach or perhaps a 'good enough' one. Ovens are pretty simple and stable with the main characteristic being that they have a lag.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: February 18, 2017, 03:15:29 pm
content: Thanks, sharing how you did the practical calculations is worth a lot, because I like the practical things better than pure math. Here I have done a step response of my oven with a PCB inside to model the thing better,I just turned all the heaters on and sample the thermocouple every second. But unfortunately my PCB burnt and generate lot's of toxic smoke!!! all the magic smoke started @ 310C readings from my thermocouple. So I was scared and turned it off, I think the entire process took about 450S to reach 310C. Should we get these results with the PCB at these temperatures!!!? I think I have done several SMD parts removal with my soldering station and the air temperature was 400C and sometimes it took about 3-4 minutes to remove a 240 pin TQFP.

author: Unknown
author_rank: Unknown
timestamp: February 18, 2017, 07:03:33 pm
content: Quote from: ali_asadzadeh on February 18, 2017, 03:15:29 pm310C is a bit high, as you can see. A temperature of 400C at the nozzle of the hot air wand is a lot higher than the temperature of the board itself, even, I'd guess, after a few minutes of that.I am no expert in any of this -- I am just looking into a similar project for myself -- but I haven't seen reflow profiles with temperatures much higher than 250C at peak.

author: mjkuwp
author_rank: Unknown
timestamp: February 18, 2017, 08:52:14 pm
content: I turn off the elements when the thermocouple on my copper sheet (under the circuit board) is about 215C or at the highest 220C. Considering the difference between the two I think that my pcb never exceeds 230C. After this peak, I blow a fan into the oven with the door open to get the temperature below liquid and then pull out the pcb with a pliers or tweezers.

author: Vtile
author_rank: Super Contributor
timestamp: February 18, 2017, 09:01:19 pm
content: Well if you have small oven like one could assume from the use, have 3kW worth of heating elements and you turn them fully on and the thermal insulation and thermal mass of the PCB is something..You have created a toaster!PS. Analog world is funny isn't itThat said I think biggest problem at your current setupis the temperature sensing. 2nd hurdle after you get that sorted out is that you notice your board is in wrong place in the oven and after that tweak you can resetup your temperature sensing. Then you might rething the shielding of the heaters, maybe add some airflow a better temperature sensor, maybe revisit the contoller input dynamics and and and...