Author Topic: Modeling an Oven with matlab and finding the PID numbers automaticaly  (Read 7253 times)

0 Members and 1 Guest are viewing this topic.

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
Hi
I 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.


ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline mjkuwp

  • Supporter
  • ****
  • Posts: 259
  • Country: us
  • mechanical engineering defector
    • The Mz Lab
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #1 on: February 14, 2017, 11:30:52 am »
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?
 

Offline ondreji

  • Contributor
  • Posts: 43
  • Country: au
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #2 on: February 14, 2017, 12:21:36 pm »
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 / L
PI: P = 0.9L / T, I = .27 T / L / L
PID: 1.2T / L, I = .6 T / L / L, D = .6T

Then experiment with:
P - to change rise time
D - reduce overshoot and settling time
I - tweak steady-state error

At 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


 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #3 on: February 14, 2017, 12:48:36 pm »
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
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline MagicSmoker

  • Super Contributor
  • ***
  • Posts: 1408
  • Country: us
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #4 on: February 14, 2017, 12:58:30 pm »
There is a page on Mathworks site concerning this: https://www.mathworks.com/discovery/pid-control.html


 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #5 on: February 14, 2017, 02:31:46 pm »
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 :)
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline MagicSmoker

  • Super Contributor
  • ***
  • Posts: 1408
  • Country: us
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #6 on: February 14, 2017, 03:28:57 pm »
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.


 

Offline mark03

  • Frequent Contributor
  • **
  • Posts: 711
  • Country: us
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #7 on: February 14, 2017, 05:03:52 pm »
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.pdf

I 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.

 

Offline Vtile

  • Super Contributor
  • ***
  • Posts: 1144
  • Country: fi
  • Ingineer
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #8 on: February 14, 2017, 06:08:04 pm »
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.  :D

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..  :-//
« Last Edit: February 14, 2017, 06:20:48 pm by Vtile »
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14195
  • Country: de
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #9 on: February 14, 2017, 08:05:43 pm »
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.
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #10 on: February 15, 2017, 07:08:49 am »
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 it ;)

The cool front panel
https://ibb.co/fEE7tv

Almost 4Kw of heater elements
https://ibb.co/cWafDv

Meet the micro toaster Rev 1.0 Designed by ASiDesigner
https://ibb.co/cvEJ0a

The side view
https://ibb.co/cxYBLa

Didn't I told you it has lot's of connectivity  ;) ;)
https://ibb.co/hkaQfa
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline mark03

  • Frequent Contributor
  • **
  • Posts: 711
  • Country: us
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #11 on: February 15, 2017, 06:17:11 pm »
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?
 

Offline MagicSmoker

  • Super Contributor
  • ***
  • Posts: 1408
  • Country: us
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #12 on: February 15, 2017, 06:45:56 pm »
...
How do you hold the thermocouple in contact with the PCB being reflowed?  I am still searching for a good way.
...

Drill 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.
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #13 on: February 17, 2017, 12:12:29 pm »
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
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #14 on: February 17, 2017, 02:01:08 pm »
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.

 

Offline mjkuwp

  • Supporter
  • ****
  • Posts: 259
  • Country: us
  • mechanical engineering defector
    • The Mz Lab
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #15 on: February 17, 2017, 06:13:47 pm »
.....

How do you hold the thermocouple in contact with the PCB being reflowed?  I am still searching for a good way.

.....

I'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
 

Offline mjkuwp

  • Supporter
  • ****
  • Posts: 259
  • Country: us
  • mechanical engineering defector
    • The Mz Lab
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #16 on: February 17, 2017, 06:33:54 pm »
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.
.....
Regards

I 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/PIDTemp

I use this for reflow - controlling the slope of temperature, not value of it.
http://mjkuwp94.tumblr.com/PIDSlope

I also found that I got good control of reflow by using PID to control the slope of temperature instead of the value of temperature.  I have a state machine that controls the reflow process and adjusts the desired slope of 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.
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #17 on: February 18, 2017, 08:24:35 am »
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."?
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline mjkuwp

  • Supporter
  • ****
  • Posts: 259
  • Country: us
  • mechanical engineering defector
    • The Mz Lab
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #18 on: February 18, 2017, 12:38:08 pm »
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."?

I 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.
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #19 on: February 18, 2017, 03:15:29 pm »
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.
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Elf

  • Guest
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #20 on: February 18, 2017, 07:03:33 pm »
[...] 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. [...]
310C 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.
 

Offline mjkuwp

  • Supporter
  • ****
  • Posts: 259
  • Country: us
  • mechanical engineering defector
    • The Mz Lab
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #21 on: February 18, 2017, 08:52:14 pm »
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.

 

Offline Vtile

  • Super Contributor
  • ***
  • Posts: 1144
  • Country: fi
  • Ingineer
Re: Modeling an Oven with matlab and finding the PID numbers automaticaly
« Reply #22 on: February 18, 2017, 09:01:19 pm »
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..  :-BROKE

You have created a toaster!   

PS. Analog world is funny isn't it  :) That 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...
« Last Edit: February 18, 2017, 10:24:34 pm by Vtile »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf