www.wholelattelove.com: our caffeinated commitment to you

PID - back to basics

Postby mini on Wed Aug 11, 2010 8:37 pm

First off: my post pertains to espresso machine PIDs, but it is primarily full of math questions. If it needs to be moved to a different forum, please do so. If it is so off topic that it needs to be taken down, then please let me know - I won't be offended. I was hoping to call upon the expertise of those who commented on other PID postings.

In the interest of general tinkering, engineering fun, and micro-controller experience, I've been thinking a lot about espresso machine PIDs. I read through everything I could find on PIDs, but I still have some questions.

To me, the general concept is really pretty simple, and I've got a fun new Arduino micro-controller, an attractive LCD screen, and some temperature sensors. I thought I could probably write my own PID code and mod my Le'Lit. The goal is not necessarily to make the most effective, useful, or cheap PID - I just want to have fun and learn something.

Astute readers will realize that two PID codes for the Arduino already exist. I can follow some of the code pretty well, and there is even a built-in Auto Tuning function that is nice, but I want the satisfaction of writing the code completely myself (I'm willing to sacrifice end user ease of control and even performance).

My goal is to build the simplest PID controller possible, both mathematically and in terms of components.

I want to use my Arduino, my screen, a SSR, and a sensor. I will tune the the set point and gain parameters "by hand" - that is, I will just go back and change the values by rewriting the code. Tedious, but super simple.

I'd really appreciate some suggestions from those of you with control theory / PID / thermal experience to get started. I guess understanding the mathematics and performing the calculations are different things. Here's the basic outline (right?):
    1. take temperature measurements
    2. calculate the proportional, integral, and differential components with measurements (and gains)
    3. translate that into heating element on and off

What I'm lacking is all the practical know-how. Here are my current questions:
    1. How fast is it advisable to switch a heating element on and off?
    2. Disregarding some PWM technique or power changing device, one must define a small temperature range around the set point within which the temperature oscillates, correct?
    3. Are temperature measurements of the external boiler better than internal measurements, or are they just easier?

And my big question is about temperature sampling and sampling frequency. I can't find any informations about PIDs on this basic level. I think I should take a sliding window of temperature measurements for the calculations. For example, take 10 measurements with 1 measurement every half second replacing the first. I would think this would help with some of the noise in the system, and keep start-up integral errors from overwhelming the function. Is this an effective way? What would be a good sampling time? A good window size? Help? :D

Thank you very much.
matt
mini
 
Posts: 228
Joined: Jul 18, 2009
Location: Atlanta, GA

Postby randytsuch on Thu Aug 12, 2010 1:09 am

There is a group at homeroasters that I am participating in, using an Arduino as the basis for a 4 channel temp meter.

I am working on write an Arduino PID program for roasting, you can read a little about it starting here
http://homeroasters.org/php/forum/viewthread.php?thread_id=1774&rowstart=300#post_22140

With the way we are doing things, it appears that once a second is as fast as I can sample, and do all of the PID calculations.

My output is one of the PWM pins, running at 4 hz. I have not tried faster, but I don't really think you can run a SSR faster then that and get reasonable results. For a espresso machine, a 2 hz output might be fine. I have a Fuji PID on my machine, and it does fine with a 1 hz output.

At some point, I plan to convert my espresso machine to a Arduino PID too. I would not worry about the D term, it is basically to dampen things out, to help stop over/undershoot. Since a espresso machine normally is set to one temp, I don't think D needs to come into play.

You really might be able to do it with just the P term. The problem you may have is that with just using P, you may find the temp is always off by some number. You can "cheat", and just offset you target temp to account for this.

Randy
randytsuch
 
Posts: 255
Joined: Aug 11, 2009
Location: Los Angeles

Postby JimG on Thu Aug 12, 2010 9:25 am

I've recently completed a mission nearly identical to Matt's. Here are a few things I can pass along that might make Matt's project go smoother:

  • This (from Atmel) is a pretty good high level, general reference to get you started.
  • I favor defining the tuning parameters in terms of proportional band (Pb), resets (rE), and rate/derivative (rA or D).
  • Pb has units of degrees; rE has units of 1/time; and rA has units of time.
  • I suggest you build yourself a software tool that will display a realtime trace of the PV (i.e. boiler temperature). The Processing language works fairly well for this in an Arduino application.
  • I also suggest that you give yourself a means of monitoring the individual P, I, and D output components in realtime. This will help you with tuning, as well as help with understanding how the algorithm works.
  • It is also cool to be able to observe that eventually, when the system is running along at a steady temperature (PV = SV), the integral term shows you precisely the duty cycle required to maintain the machine at idle. From this, you should be able to get a reasonably accurate estimate of the average power consumption of your heater.
  • Depending on how you accomplish the ADC for your temperature sensor, you will probably need to digitally filter this signal. If you filter it too much, then you'll introduce a response lag that can make control difficult. Hunt around on the internet for first order low pass digital filters.
  • Plan on incorporating a means of defeating "windup" in the integral/reset output component. There are several ways to do this described in various online references.
  • I find it helpful to incorporate derivative action for good control of a brew boiler. Without it, overshoot and undershoot are major problems when recovering from the disturbance caused by pulling a shot.
  • Like Randy suggested, you may be able to control a steam boiler using PI control; or P-only with a manual reset correction.
  • A cycle time of 1 second is fast enough to control an espresso machine boiler. Your PWM frequency should be slow enough to span several AC line voltage cycles to maintain some resolution on output levels.

Have fun!

Jim
JimG
 
Posts: 544
Joined: Jun 11, 2006
Location: Lexington, KY

Postby mitch236 on Thu Aug 12, 2010 8:58 pm

I have a Fuji PID and would love to set it up to allow me to have the SV take the unit to that value (SV offset maybe?). Then I would also love it if the PV would display the value measured at the grouphead (PV offset maybe?).

Here's my observation. When I set the SV to 200f, the grouphead measures 196f. I figured out the SV offset to get the grouphead measurement to match the SV by setting the SV offset but I can't seem to get the PID to display the measured temp to be offset to estimate the temp at the grouphead. In other words, now that I have the SV offset properly set, the measured temps display about 204f. I would rather it display 200f. Is that possible?
User avatar
mitch236
 
Posts: 627
Joined: Jul 21, 2010
Location: Florida

Postby durwiler on Fri Aug 13, 2010 3:52 pm

On the Fuji, turn your set value offset back to 0 and adjust your process offset (POUF) by-4 degrees and it should be what you see (and set) is what you get.



Dan
durwiler
 
Posts: 8
Joined: Feb 10, 2009
Location: Seattle Washington

Postby mitch236 on Sat Aug 14, 2010 9:27 am

durwiler wrote:On the Fuji, turn your set value offset back to 0 and adjust your process offset (POUF) by-4 degrees and it should be what you see (and set) is what you get.



Dan


Thanks. That gets me close but here's the problem. I calibrated my machine for 200f and by setting the PVOF I was able to nail 200f on the set value and measured temp. Perfect. But when I went for 210f (to check if the PID stayed accurate) the measured temp was low by about 4f. Are there parameters to play with to try to get the PID completely dialed in?
User avatar
mitch236
 
Posts: 627
Joined: Jul 21, 2010
Location: Florida

Postby cafeIKE on Sun Aug 15, 2010 2:21 pm

Not sure if this helps, but with e61 DB & HX PID, it's not a 1:1 change between boiler and brew temp.
User avatar
cafeIKE
 
Posts: 2905
Joined: Jun 27, 2006
Location: Woodland Hills, CA

Postby mitch236 on Sun Aug 15, 2010 10:05 pm

cafeIKE wrote:Not sure if this helps, but with e61 DB & HX PID, it's not a 1:1 change between boiler and brew temp.


Not only that, but I decided to change blends and needed to lower the temp from 200 to 198 and I had to tune the PVOF by -0.3. I wish there were a way to set the PID to have accurate set values from say 196-205. I would be very happy with that. For now, every change requires the Scace and Fluke to come out and about 30 mins of trial and error until I get it all dialed in. The good thing is once its dialed in, its consistent, which is of utmost importance to me.
User avatar
mitch236
 
Posts: 627
Joined: Jul 21, 2010
Location: Florida

Postby cafeIKE on Mon Aug 16, 2010 12:42 pm

After a while, Up and Down will suffice. You'll have built a mental database of what tastes good where. :wink:
User avatar
cafeIKE
 
Posts: 2905
Joined: Jun 27, 2006
Location: Woodland Hills, CA


Return to Espresso Machines