Manually tuning PID

Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum

Help Support Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

MalFet

/bɪər nɜrd/
HBT Supporter
Joined
May 31, 2010
Messages
8,627
Reaction score
1,478
Location
NYC / Kathmandu
Hello,

I've been gradually automating my fermentation chamber, particularly the mechanisms I use for pressurized fermentation. I use a mass flow controller to gently bleed pressure off of my fermentor in response to measurements from an in-line transducer. I use the PID library on an Arduino to keep my setpoint, and so far it has been working very well.

After a fair bit of trial and error, I've found PID coefficients that seem to keep me steady (Kp = 200, Ki = 1, Kd = 5). These keep me reasonably tight on my setpoint, and even during the height of fermentation I rarely drift more than a tenth of a PSI away.

But, in the course of keeping things steady, my control output (valve position) races around like a jackrabbit. At peak fermentation, I'll see something like 300 SCCM average, but at any given moment it will be anywhere from 200-400. I stay very close to my target pressure, but the flow rate oscillates on about a 90 second period.

Any suggestions for convincing my output to settle down? My instinct is that I should lower my Kp and increase my Ki, but I wasn't able to make this work immediately. Before futzing with it more extensively, I thought I'd put the question to the many here who understand this stuff far better than I ever will.

Thanks!
 
Have you tried playing around with the PID update rate. I believe that the default for the arduino PID library is rather fast and if your oscillations are at a 90 second period then the integral may be winding up too much before the system responds to the change in output. You may actually want to decrease the integral because it may cause the output to change too much before the system can respond. Once the system does start to move towards the set point then it takes too long for the integral to unwind which causes it to swing past the set point in the other direction.

So I would try decreasing the integral gain and/or slowing down the update rate, but I may be completely wrong as its been about 4 years since I took feedback control theory in college.
 
Have you tried playing around with the PID update rate. I believe that the default for the arduino PID library is rather fast and if your oscillations are at a 90 second period then the integral may be winding up too much before the system responds to the change in output. You may actually want to decrease the integral because it may cause the output to change too much before the system can respond. Once the system does start to move towards the set point then it takes too long for the integral to unwind which causes it to swing past the set point in the other direction.

So I would try decreasing the integral gain and/or slowing down the update rate, but I may be completely wrong as its been about 4 years since I took feedback control theory in college.

Thanks for your suggestion. Unfortunately, it doesn't seem to be working. The slower sampling rate actually amplifies the swing on my control parameter, which is unfortunate because I was optimistic about your idea.

From what I understand about the algorithm, I feel like I should need to drop my Kp and raise my Ki, but as soon as I do that I start seeing my pressure swing.

Hmm...this is very perplexing.
 
Have you tried playing around with the PID update rate. I believe that the default for the arduino PID library is rather fast and if your oscillations are at a 90 second period then the integral may be winding up too much before the system responds to the change in output. You may actually want to decrease the integral because it may cause the output to change too much before the system can respond. Once the system does start to move towards the set point then it takes too long for the integral to unwind which causes it to swing past the set point in the other direction.

So I would try decreasing the integral gain and/or slowing down the update rate, but I may be completely wrong as its been about 4 years since I took feedback control theory in college.

Slowing the update rate of the Arduino PID algorithm will adversely affect the integral term. The less often you update the integral accumulation the less accurate it will be. The sample time is taken into account in the integral calculation (as well as the derivative calculation). The only time you would need to increase the sample time would be due to the controllers inability to actually scan the code that quickly. So I would not recommend increasing the sample time.

kp=200 does seem quite high. High proportional gain can definitely cause oscillation.

Like you said backing off the kp will help. But without seeing a trend, it's hard to say which direction the ki needs to go.

You could back off your kp a lot, and let the integral do most of the work. The response will probably be slower but you will have less movement of your output.
 
Slowing the update rate of the Arduino PID algorithm will adversely affect the integral term. The less often you update the integral accumulation the less accurate it will be. The sample time is taken into account in the integral calculation (as well as the derivative calculation). The only time you would need to increase the sample time would be due to the controllers inability to actually scan the code that quickly. So I would not recommend increasing the sample time.

kp=200 does seem quite high. High proportional gain can definitely cause oscillation.

Like you said backing off the kp will help. But without seeing a trend, it's hard to say which direction the ki needs to go.

You could back off your kp a lot, and let the integral do most of the work. The response will probably be slower but you will have less movement of your output.

Thanks for the analysis. This seems to have helped, though the fermentation ran out of steam before I could test it properly. I'm hoping these new settings will work well for my next batch, and I'll post more info then. :mug:
 
I haven't used this controller, but in general in control some aspects that might be used, especially if there is say a pressure range that is acceptable to maintain rather than an exact specific pressure, is to incorporate a deadband. That is extremely common in industrial control where you don't want your modulating valve making tons of tiny little movements all the time causing excessive wear and tear. Having the derivative gain set too high usually makes the system quite twitchy, the proportional can do that as well.
 
I haven't used this controller, but in general in control some aspects that might be used, especially if there is say a pressure range that is acceptable to maintain rather than an exact specific pressure, is to incorporate a deadband. That is extremely common in industrial control where you don't want your modulating valve making tons of tiny little movements all the time causing excessive wear and tear.
...

Good point. However, the Arduino library doesn't include deadband functionality. That wouldn't be too difficult to add to the the PID library Compute() function if needed. Only update the output if the absolute value of the error is greater than your deadband value.
 
For starters, get rid of the derivative. It's not needed for slow changing process variables. P & I control is more than enough for your application. Might start to settle things out.
 
Shifting the bulk of my coefficient magnification to the integral component seems to have done the trick. I still need to keep P relatively high, somewhere near 80 or so, to get the thing to settle in the first place. Thanks for all the help!


For starters, get rid of the derivative. It's not needed for slow changing process variables. P & I control is more than enough for your application. Might start to settle things out.


Well, what do you guys mean by "slow changing"? I gain or lose 5 psi in less than 15 seconds.
 
Shifting the bulk of my coefficient magnification to the integral component seems to have done the trick. I still need to keep P relatively high, somewhere near 80 or so, to get the thing to settle in the first place. Thanks for all the help!

...

Well, what do you guys mean by "slow changing"? I gain or lose 5 psi in less than 15 seconds.

Glad to hear you were able to make improvements to your control.

However, I don't really agree with Poobah58's statement regarding slow changing process variables. Typically, derivative gain is useful in a process that has a lot of dead time. Dead time is the length of time is takes to see ANY response in the process due to a change in your control output. All that being said, it sounds like you probably don't have a lot (if any) dead time in your system.
 
Glad to hear you were able to make improvements to your control.

However, I don't really agree with Poobah58's statement regarding slow changing process variables. Typically, derivative gain is useful in a process that has a lot of dead time. Dead time is the length of time is takes to see ANY response in the process due to a change in your control output. All that being said, it sounds like you probably don't have a lot (if any) dead time in your system.

This is probably not the time to debate this but you are wrong. Dead time is the amount of time it takes for a process to start changing after a disturbance in the system. If there is dead time your gain is probably too low. By definition with derivative action the controller output is proportional to the rate of change of the process variable or error. Thus, if it's a slow moving process, derivative won't give you much of a control action. Slow moving PV's are helped more by the integral control action. With integral action the controller output is proportional to the amount and duration of the error signal. I've been tuning PID control loops in boiler room enviroments for 25+ years and have used derivative on 1 job and it was due to incorrect scaling of a transmitter. I apologize to the OP for the rant. :D
 
I can't really evaluate the theory on this stuff, but I will say that in playing around with my variables I was never able to get the system to hold steady without a significant derivative component.

Thanks for the help everyone!
 
This is probably not the time to debate this but you are wrong.
Yet, you debate it anyway. So bold. :rolleyes:

Dead time is the amount of time it takes for a process to start changing after a disturbance in the system. If there is dead time your gain is probably too low.
I disagree with your definition of deadtime. Deadtime is the amount of time that it takes to see a change in the process variable after making a change in your control variable. You cannot reduce deadtime of a system simply by changing gains. Deadtime is an inherent property of the system. A common cause of deadtime is transmission delay.

This guy has a good explanation of deadtime.
http://www.controlguru.com/wp/p51.html

By definition with derivative action the controller output is proportional to the rate of change of the process variable or error. Thus, if it's a slow moving process, derivative won't give you much of a control action.
The amount of derivative control action is dependent on the derivative gain. A small rate of change can still make a significant impact on the controller output. I've tuned loops with derivative gains in the 1000's.

Slow moving PV's are helped more by the integral control action. With integral action the controller output is proportional to the amount and duration of the error signal.
A slow moving PV can cause a lot of integral wind-up.

I've been tuning PID control loops in boiler room enviroments for 25+ years and have used derivative on 1 job and it was due to incorrect scaling of a transmitter. I apologize to the OP for the rant. :D
I haven't been tuning loops for 25 years, but I've tuned a wide varity of loops. Flow control, level control, pressure control, density control, cascaded loops, etc. I agree that derivative isn't necessary in all applications, but the majority of times that I have used it involve integrating heating applications, like steam super-heaters that have a lot of thermal mass.
 
Hm I attended a seminar on PID tuning recently, and the presenter mentioned something I don't remember hearing before. First that temperature control is usually not linear; i.e. if you double the power from 10 watts to 20 watts the steady state temperature reached (proportionately) is usually not the same as when you then double from 20 watts to 40 watts.

The other was whether the system is self regulating. He indicated that whether a change in CV would result in a leveling out of the PV. So for a level control usually that does not occur, like opening a tank drain 10% does not normally result in a steady state of tank level if that were your
 
Back
Top