View previous topic :: View next topic |
Author |
Message |
cmengnr
Joined: 28 Dec 2012 Posts: 12
|
Autotuning of PID Algo in 8 bit Microcontroller |
Posted: Fri Dec 28, 2012 11:44 pm |
|
|
Hello
I want to implement Autotuning of PID Algo in PIC16 Microcontroller to control temperature.
Most commonly used Ziegler method is clear to me with Ultimate Gain and Period Oscillations.
But I want to know how to implement these graphs in C code. I found somewhere that autotuning function cannot be implemented in 8 bit micros.
Please suggest if whether 8 bit micro is able to do these mathematical calculations or not. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19519
|
|
Posted: Sat Dec 29, 2012 2:38 am |
|
|
No simple answer.
Depends on an enormous number of variables in your system. You could be implementing a large slow turning system, with the PID algorithm updating only a few hundred times a second, in which case there are plenty of resources for a simplified ZN tuning. On faster systems, you also can save a lot of chip maths, by very careful scaling of the numbers, and choice of the arithmetic used (look at some of the Microchip examples on PID, with basic controllers, where things like 24bit scaled integers are used). Remember you can pre-calculate the core parameters used by the tuning algorithm.
It is certainly possible to implement ZN tuning on a PIC18. I did it about five years ago, at quite reasonable speeds and responses. However it is very much easier to implement without so much thought in the code, on something like a DSPIC, which will be able to perform the arithmetic using the standard libraries, much faster. Chip costs are not that different, while development costs will be a lot less.
Best Wishes |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Sat Dec 29, 2012 6:24 am |
|
|
comment
Anyone saying 'no' probably says bumblebees can't fly either!
Yes, an 8 bit PIC will do PID to control temperature. BTDT, about 10-12 years ago with a 16F877 ('the' PIC of choice back then..). I've done remote energy control systems since '84 and was R&Ding some upgrades.
As Ttelmah points out, there are several points for considerations but I know it is 'do-able'. Usually 'Temperature control' is a 'slow' process, a lot of time between turning on the plant and then waiting for the temperature to rise(or fall), allowing millions of usecs for calculations.
What's the scope of the project? Controlling a small test chamber or whole room? A block of steel or a styrofoam cooler?
As for the 'math', if you have access to Matlab (or equal), you can 'reverse engineer' the graphs into equations, then reduce them to integer formula, vastly speeding up the calculations.
hth
jay |
|
|
cmengnr
Joined: 28 Dec 2012 Posts: 12
|
|
Posted: Sat Dec 29, 2012 7:16 am |
|
|
Thanks for your reply.
I want to control temp of oven in which sometimes i wants to control in slow manner like with Proportional band from 25 degree and sometimes i want controlling of PID starts from about 90 % of temperature.
Max Temp range is about 850 degree
Manual tuning by hit and trial is fine but i wants to implement autotuning function in it.
I have not used MATLAB earlier for any project. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Sat Dec 29, 2012 7:42 am |
|
|
As long as you are taking 100 reading/second or slower you should have no problem implementing PID on an 8 bit PIC. Autotuning just takes a little more ROM space, not much more PIC computing power.
You should do all the math with scaled integers. Use 8, 16, or 32 bit integers as required. For simplicity you might represent temperature in integer deci-degrees or milli-degrees. 850 degrees = 8500 deci-degrees which fits nicely in a 16 bit signed variable. On a PIC floats should never be used for anything fast or precise. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
cmengnr
Joined: 28 Dec 2012 Posts: 12
|
|
Posted: Sat Dec 29, 2012 8:19 am |
|
|
Thanks SherpaDoug for your reply.
Mathematical calculations with scaled integer is fine for me, but i want to know how to find out ultimate gain and period using Ziegler Method during undershoot and overshoot using C Code in PIC so that the system automatically sets its P, I and D values for a process. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sat Dec 29, 2012 9:11 am |
|
|
i very recently have been working on a microscope stage incubator heating system, where the mass/bulk of the unit is a fairly large aluminum block.
the controller has a NO programmed "I" component as the
the thermal soak was so slow - that 1 update reading per second and a VERY large D component were required to get 37 deg C +/- .1 deg stability.
there are often significant physical parameters that translate into either the I or D component of a project, and I have found that only careful experiment shows the way to an ultimate design.
If there is a cookbook for such things, i have never found it
|
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Sat Dec 29, 2012 12:03 pm |
|
|
Hi,
It's totally doable. I did a PID controller for a thermal test chamber (slow process response) that came out so well, that I adapted the hardware, and reused the basic design for an air velocity controller (fast process response). I also added auto tune functionality, and it worked very well.
Do a search for 'osPIS' (open source PID) to get some good tutorials, and design ideas. It's an Arduino based system, but it's not hard to adapt to CCS 'C'! There is also a Google group devoted to PID controllers using small micros.
John |
|
|
cmengnr
Joined: 28 Dec 2012 Posts: 12
|
|
Posted: Sat Dec 29, 2012 9:34 pm |
|
|
Could anyone please give some links, tutorials etc as I searched a lot but feeling not comfortable with all stuff.
Everywhere for autotuning zieglers method is mentioned.
But how to implement this method in Microcontroller. After reaching set point, how does the controller manage its o/p to find ultimate gain and period during overshoot and undershoot ?
How many hit and trials from controller side is applied to value of kp, so that overshoot and undershoot becomes stable to 5% of set point ? That value of Kp become ultimate gain. Now using the period of oscillations and ultimate gain, values of P, I and D can easily found.
Give me some hits regarding coding, tutorials etc. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Dec 30, 2012 3:17 am |
|
|
I'm not aware of commercial PID controllers using gain margin and oscillation period according to Ziegler-Nichols method for autotuning. Most are identfying control system parameters from a single or multiple step response. Tuning rules based on measured dead and transition time can be found in text books. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19519
|
|
Posted: Sun Dec 30, 2012 4:50 am |
|
|
For anything as slow as temperature control, PID, is rarely used. You'll find a lot of people using 'subsets' of PID (particularly PI), and relatively simple tuning rules. Unless your sample time is very slow, and your heater very powerful, you are unlikely to get much overshoot, so the 'D' term does little. As such, simply tune the P term, using a couple of fairly basic rules, so that if overshoot occurs, you reduce the P term, while if correction takes longer than a defined limit, you increase it. A slow tweak can then be applied to the I term, depending on any long term offsets. Maths involved is then minor.
Get a copy of the paper published by Schei in 1994, and the later work on this by Astrom in 1998. The latter in particular gives simple formulae for tuning the behaviour of a PI controller.
Best Wishes |
|
|
cmengnr
Joined: 28 Dec 2012 Posts: 12
|
|
Posted: Sun Dec 30, 2012 7:53 am |
|
|
Actually my requirement is to design a Autotune PID based Temperature controller up to 850 degrees. In some cases i want max temp of 200 degree with different wattage of heater and sometimes i want temp of 400 degrees with different heaters and with different aluminum case.
As PID values calculated for a particular process cannot be applied to another process.
Also all customers want controlling with PID not with single PI.
That is why I want to add autotune function in it so that user can easily upgrade PID values as per their product mechanical specifications using Autotune Function in it. |
|
|
cmengnr
Joined: 28 Dec 2012 Posts: 12
|
|
Posted: Tue Jan 01, 2013 12:21 am |
|
|
I have read somewhere that for Autotuning ZN method is not best. They said go for Discrete Autotuning Methods.
Could anyone please help me to move one step ahead toward autotuning. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19519
|
|
Posted: Tue Jan 01, 2013 4:05 am |
|
|
The big question is how the tuning is to me handled.
The easiest way by far, will be to have a 'setup' jumper on the board, which you make. Then the controller goes into setup mode. It is then told to make a temperature change, and operates as a pure P controller. Start with Kp=1. It then looks at the response peak, and following trough, and increases or decreases Kp, till this is a determined percentage of the specified change (perhaps less than 10%, but greater than zero). This gives Kp. The setup then measures the time at the response 'peak' and at the next trough, to give the overshoot time and sets the integral time to be 1.5* this, at the same time reducing Kp by perhaps 0.8*. Then introduce the D term as typically Ti/4 to Ti/5.
ZN, is not particularly good or bad. It depends on what you want from the actual loop when running. The 80%, and 25% figures above, are based on the ZN model.
You then can 'move on' from this. The first thing is that the basic initial tuning, _must_ be done in the system configuration that gives the fastest responses for the particular hardware (so with minimum fluid present say). Otherwise the tuning will give instability if the response speed increases. Once you have the initial tuning done, what you can then do, is to have a set of discrete 'gain' values, with this initial set as the limit one, and the others giving higher Kp values, and lower Ti/Td values. Perhaps 3 or four sets. If the system has a direct method of measuring 'leve' or 'flow', you can use this as an input to the controller to switch between the sets. Thiss is a very common approach. Alternatively, during normal operation, you time the interval from step response to reaching the output level, and the overshoot. If the overshoot is greater than a set level, you select the next lower response set, while if the step interval is higher than a set time, you select the next higher set. Ideally you can actually measure these configuration sets, perhaps with the fluid at half, and full levels, otherwise you have to extrapolate them.
Best Wishes |
|
|
cmengnr
Joined: 28 Dec 2012 Posts: 12
|
|
Posted: Tue Jan 01, 2013 4:36 am |
|
|
Thanks Ttelmah for your explanation.
Could you please explain it in terms of voltage applied to heater and change in temperature. And when temp reaches set point, what the code will do to compute values of all parameters.
A simple code in c which explaining the autotuning functions will helps. |
|
|
|