How to implement PID to control Temperature

Hi.

I want to control temperature of a pot with peltier cells, so, i am now with some simple control, basically:

if (actualTemperature < wishedTemperature)
 ... activate relay pin to rise temperature

...
if(actualTemperature > wishedTemperature)
 ... activate relay pin to lower temperature

...

Si, i need to control that temperature with PID, i really have no clear how to implement that?

I see the PID library but i cannot understand the examples in the way i cannot see where i place the temperature read in the functions and when to activate the pins of the relays, i really had read tutorials and try to implement code but i really don't understand.

Thanks.

First, get temperature control working using your simple (non-PID) approach. You may find that to be satisfactory.

If your setup works, but not satisfactorily, come back to the forum, post a complete description of your setup (with details of the heater, heater driver, heater power supply and temperature sensor) and the code.

Then you will be prepared to ask specific questions that forum members can answer.

For me PID control is quite interesting and have heard many times. But the technique is too complicated, so I'm not able to learn and apply for even in a simple app.

Can anyone describe a short overview of PID control? Does the technique really use in many fields?

A couple of links you might find helpful in your quest:
http://www.csimn.com/CSI_pages/PIDforDummies.html
http://ee.sharif.edu/~industrialcontrol/Introduction_to_PID_Control.pdf

I can't find the one I liked, however, there was an article in Circuit Cellar some time ago on using a PID controller for the home brewer. It was called "Home-brewed HERMS" and I believe it was in issue 191 - he was using PID for his mash.

In an ideal world PID output should be an 'analogue' rather than a simple binary condition. Because the controller does not output analogue you can use PWM as a pseudo-analogue. However PWM cannot be effectively implemented using a simple driver relay since the relay would be chattering constantly. You can however use an SSR which will quite happily operate with PWM. Alternatively, rather than 'normal' PWM you could use "burst mode" on the output which is effectively a very low frequency form of PWM. In this case ON for so many seconds, then OFF for so many seconds, depending on heat demand. This method is frequently used in mains type heating systems.

Note also that PID control requires an analogue input sensor, rather than a simple digital switched input since you need to sense both the value of offset and rate of change of offset

I have a PID program running on a PIC processor currently (new version is ESP8266) that runs PWM with a 2.5 second cycle time to control the temperature of an aluminum plate under my hummingbird feeder to keep it from freezing. I use two temperature sensors (old version is analog - new version will be 18b20 sensors) - one for ambient air temperature and one for the heat plate temperature. The 2.5 second cycle time seems to work quite well since the time constant for the heat plate is fairly long (it takes a minute or two at 100% power to bring the plate up to temperature (about 70F)). I also have 3 green LED's around the edge to show when the power is on to the heater so I can see the duty cycle that way - given the circular shape of the feeder with the blinking green lights around it, people commented on the little flying saucer in my back yard :slight_smile:

heartbismane:
For me PID control is quite interesting and have heard many times. But the technique is too complicated, so I'm not able to learn and apply for even in a simple app.

Can anyone describe a short overview of PID control? Does the technique really use in many fields?

PID is easy to understand. The hard part is tuning the constants.

jackrae:
In an ideal world PID output should be an 'analogue' rather than a simple binary condition. Because the controller does not output analogue you can use PWM as a pseudo-analogue. However PWM cannot be effectively implemented using a simple driver relay since the relay would be chattering constantly. You can however use an SSR which will quite happily operate with PWM. Alternatively, rather than 'normal' PWM you could use "burst mode" on the output which is effectively a very low frequency form of PWM. In this case ON for so many seconds, then OFF for so many seconds, depending on heat demand. This method is frequently used in mains type heating systems.

Note also that PID control requires an analogue input sensor, rather than a simple digital switched input since you need to sense both the value of offset and rate of change of offset

Your "burst mode" is not a low-frequency form of PWM, it is PWM. There is literally no theoretical difference at all whether the frequency is 50 kHz or 50 mHz.

My previous job had big thermal chambers that used PID controllers to modulate the temperature inside them according to a specific thermal profile, example:

  1. ramp to 85C in 10 minutes
  2. Hold for 1 hour
  3. Ramp to -40C in 30 minutes
  4. hold for 1 hour
  5. Ramp to 25C in 20 minutes
    Repeat 100 times

The multi-kilowatt heaters and cooling compressors were controlled by relays with a PWM period of about 10 or 15 seconds. The time constant for most things in Newton's Law of Cooling is YUUUGE!!, probably many many minutes long for a good pot of water. A PWM cycle lasting several seconds should be more than good enough for controlling temperature on most things with a large thermal mass.

Jiggy-Ninja:
PID is easy to understand. The hard part is tuning the constants.Your "burst mode" is not a low-frequency form of PWM, it is PWM. There is literally no theoretical difference at all whether the frequency is 50 kHz or 50 mHz.

My previous job had big thermal chambers that used PID controllers to modulate the temperature inside them according to a specific thermal profile, example:

  1. ramp to 85C in 10 minutes
  2. Hold for 1 hour
  3. Ramp to -40C in 30 minutes
  4. hold for 1 hour
  5. Ramp to 25C in 20 minutes
    Repeat 100 times

The multi-kilowatt heaters and cooling compressors were controlled by relays with a PWM period of about 10 or 15 seconds. The time constant for most things in Newton's Law of Cooling is YUUUGE!!, probably many many minutes long for a good pot of water. A PWM cycle lasting several seconds should be more than good enough for controlling temperature on most things with a large thermal mass.

Sorry to disappoint, but burst mode definitely isn't PWM. You are not Modulating the Width of a Pulse, you are controlling On and Off times of a power feed. In PWM you generally have a fixed frequency drive and you then control the On period within each and every cycle, whilst in burst mode you switch On for several (or many) cycles and then switch Off for several (or many) cycles - quite different from PWM. That's why I described it as a "form" of PWM, I was using a metaphor to explain the difference to someone who is learning about temperature control via PID.

jackrae:
Sorry to disappoint, but burst mode definitely isn't PWM. You are not Modulating the Width of a Pulse, you are controlling On and Off times of a power feed. In PWM you generally have a fixed frequency drive and you then control the On period within each and every cycle, whilst in burst mode you switch On for several (or many) cycles and then switch Off for several (or many) cycles - quite different from PWM. That's why I described it as a "form" of PWM, I was using a metaphor to explain the difference to someone who is learning about temperature control via PID.

Except there isn't a difference. You don't need a metaphor to compare them because they're exactly the same thing.

You say with burst mode it's on/off for "several cycles" each. What cycle time you are using? The system designer has total freedom to decide how long or short the PWM period is. My previous job was validating electric power steering modules for a Tier 1 supplier. The thermal chambers we used had a PWM period of 10 s for the temperature and humidity controls, and the motors in the steering modules themselves used a 40 us period (25 kHz) into the motor's H-bridges. Even with a 250,000 fold difference in frequency, one is not any more or less PWM then the other.

The EPS motor needed very snappy responses, so it required a fast PWM frequency. Thermal systems are much much slower, so they can get away with much slower PWM frequencies as well.

PWM doesn't stop being PWM just because the frequency goes below some arbitrary value. I need to bring this out for emphasis:

you are controlling On and Off times of a power feed

That is what PWM is.

Hi.

I appreciate all the coments about this topic; the theory shows PID a few hard to implements, but in real life with PID library is not that hard, the thing is how to obtain the constants (kp, ki, kd), to this i will check with many values.

In my case the SetPoint (temperature) comes from user, so is always different, is this an inconvenient or what changes in PID implementation.

Also input is a sensor value.
PID myPID(&input, &output, &temperature, kp, ki, kd, DIRECT);

Thanks.

If you're keen it's time you learnt some control theory....

Try wikipedia for a start...

regards

Allan

the thing is how to obtain the constants (kp, ki, kd),

Google "pid tuning" for standard approaches and tutorials.