PID help tuning and approach
grasshopper
Posts: 438
My problem is that I can not tune the PID to run correctly. Do I need to read the temperature less or more? Do I need to provide a cushion for example if the temp is 20.03 +/- .02 so that the temp would range from 20.05 to 20.01
Suggestions please
My Code so far
Some plots of the runs at various P.I.D. constants will come soon
Suggestions please
My Code so far
pid.init(5.0, 1.0, 5.10,TargetT, 30, 10.0, -10.0) Stash := A2D.GetTemp(1) 'Gets temp Drive := pid.calculate(Stash) ' Calculates PID output IF (Drive > 1) ' Drive temp up Heat outa[noparse][[/noparse]INNA]~~ outa[noparse][[/noparse]INNB]~ MOS.SetDuty(Drive) IF (Drive < 0) ' Drive temp down cool drive := (drive * -1) ' make the neg number positive to pwm outa[noparse][[/noparse]INNA]~ outa[noparse][[/noparse]INNB]~~ MOS.SetDuty(Drive)
Some plots of the runs at various P.I.D. constants will come soon
Comments
It runs but not good enough for my needs. I just think that i need pointers on tuning the thing. If I use just the proportional i get great oscillation for example. If i use to much derivative i get weird spikes and so on.
For now any ideas how i can begin to tune this correctly where do i start?
I doubt very much you need any D at all because generally things take time to heat so there is unlikely to be any rapid changes that need to be fought.
I would start with P and try reducing the gain to make it less sensitive.
Graham
The time constant of your process is one of the
biggest variables in the equation. I would suspect
that it takes a long time for a step input to cause
a full swing in temperature change. If your loop
is being run too fast, relitave to this time constant,
you will have all kinds of issues with oscillations.
Start with I and D set to zero. Increase P until
you see oscillations in the output, then back P
down. After that you can do the same to I.
Remember that I is best for removing persistent
errors that P will not correct. Too much I will
cause oscillations too.
You will probably not need D. Its the least understood
off the three. D is very dependent on your process,
and will cause noise on the output if your loop is running
too fast.
Lastly, you might need to filter the input signal. A noisy
input will cause noise on the output. Especially when
using D.
Check my last post to this forum, there was a sample
first order IIR filter written in Spin. Its smooth like
butter.
Scott
The P term = Gain * Error·is clearly·independent of update rate.
The I term takes into account the time between updates·and is therfore also independent of the update period#
Similarly for the D term.
We seem to agree on how to tune the loop.
The D term is well understood; it is just diffucult to apply in the real world due to noise. Fortunately, many systems can operate without D.
As Graham said, if the process·has a long time constant, the output will change slowly, the D term will be small, and hence probably not needed.··
- "Graham" - To clear this up a bit I am controlling temperature inside a small box that uses a heating / cooling element. I am reading the temperature in the order of +/- .02°c that ranges from -50°c to 150°c. The device is required to maintain a precision of the +/- .02 once the temperature is reached in other word "stay stable +/- .02". Some of you mentioned the notion to toss out the Derivate. I argue this and I could be very wrong, but what if the door to the small box is opened for a few moments. I want the device to react quickly. As far a noise I have not seen any. The oscillations are derived from my over control and programming woes.
- "Scotta" I noticed the problem you mentioned and have since corrected the loop by making it a little bit slower.
- "Paul M" I did noted your point as well. It sounds funny, but I solved this by reading more decimal places ( i.e. started out at 2 now I read 6 )
As far as tuning the whole thing I will do as you all suggest and begin with the P-Gain and so on.
I will keep you all posted. i have great plots that i need to post here and more questions i am sure.
Is that what you are using to get temperature feedback?
What temperature sensor are you using that is accurate·to 0.02 deg C?
Accuracy is a metricing term, it defines the sensor's ability to follow the ideal line. Accuracy does not say how precise the sensor is. For a lot of applications, repeatably precise is more than enough. The process parameters can be fiddled to produce the desired outcome.
Evan
I find it hard to believe that a device that has such a wide temperature range requires such precision, but only Grasshopper can enlighten us on this.
I've coded the source in spin - not much to it really.
There is also a minor bug in your code:
·Evanh·- how did you get to requiring a resolution of 1ppm? 1ppm in -50 to 150 is 0.0002
Thanks for catching the bug!
I was experimenting with a sensor that could tell me rate, and so I was not calculating the derivative in the routine. I've attached a version with the traditional derivative calculations.
-David
Evan
The sensor itself is not accurate to +/-.02 per say, but I have a reference thermometer that is. Thus allowing me to calibrate my device towards the reference thermometer. Also I do not use the LM135AH as the data sheet suggest I am using it as a 2 pin configuration. As a side note * I am trying to replace the lm135 with a RTD sensor, but company politics and pride have insisted that I use the LM135.
Please comment more on the subject. Be aware I still very new to electronics design and have only been working as such for 4 years. I have learned that I make good mistakes and often. [noparse]:)[/noparse]
Sorry for the delay in posting the data plots but I am at home and wont return to work until Monday where I can finish tunning the PID. The good news is that i can read the temperature up to 4 decimal places and Its repeatable. The PID is working great it just needs to work better than great.
Post Edited (grasshopper) : 7/5/2008 4:41:39 PM GMT
I recommend adding a 16 or 32 word averaging (FIR) filter. This reduces the response time but hopefully you can increase the sampling rate to compensate.
This will increase your effective resolution. You should notice an immediate improvement of control.
yea the plots below show what happens if you take no averages also i used no D or I
As i promised below is the charts that show the use of a derivative and no derivative. Perhaps as some of you mentioned i may not need to use the derivative
I must try to remove the over shooting when driving to the desired temperature. Perhaps too much integral.
Graham
Hum now things are getting more and more complex.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Shawn Lowe
When all else fails.....procrastinate!
It is hard to know what to suggest without an idea of what you are trying to achieve, why and how it is implemented. What I would say is that if you have a volume to which is attached a heater/cooler it is not possible to make the whole volume the same temperature, at least it will be difficult, it needs to be very well insulated at least. There is bound to be a temperature gradient otherwise. I suspect however that there are ways of designing things to minimize these effects but I have no experience with this.
You might try mounting your thermocouple directly to the heater to begin with, get that sorted and move on to the more demanding full application.
Oh and there must be stuff about this in the library, at least a university one.
Graham
Is the later part of the final graph smooth enough? It's a bit hard to tell just looking at it here.
What happens without any Integral gain? Does the overshoot go away? If so then yes you have too strong a gain or it's being accumulated too early. Managing wind-up on step changes can be a pain.
I'm late for work ...
Integral gain helps as I expected tremendously. I noticed that some people zero out the integral, but adding the right upper and lower limit seems to be working great as of now. Without this upper and lower limit the temperature will definitely overshoot and with to little upper and lower limit it will never reach the temp. So all in all it is working pretty good, the later part of the graph is almost good enough. As far as taking the lid off I will have to get back to you on that.
Great comments Ill post more plots as soon as I can
Sorry Graham that I can not go into specific details about the unit itself. I am bound to a contract on this particular project.
What are these upper and lower limits you mention?
Graham
I hope it helps.
The upper and lower limits that I mentioned are part of the PID object that I am using.
It clamps the total gain of the integral as far as I can tell. It seemed through my experiments that if the integral gets to large during the rise in temperature from a long span (i.e. rising from 0C - 50C) it would over heat. This is logical because the integral continues to grow until the desired temperature is reached and if not dealt with (zero it out when approaching the desired temperature, or put upper and lower limits as I am doing) the integral will be such a large number that it the "drive" will overshoot the desired temperature.
This is probably not typical and is a desired effect in most P.I.D applications, but in mine i don't want to overshoot the temperature by much.
By adding limits I think you are creating a different kind of controller.
Is the PID object from the object exchange?
Graham