Refrigerator control

Hi gyus, I have an old little heater powered refridgerator whose thermostat burnt out. I couldn't find a replacement, so I figured I'd put together
a microcontroller, a temp sensor and one relay instead.
I decided to just copy the thermostat hysteresis way of controlling things, so let's say I want to keep 4 degrees celsius inside, I turn the heater on when it's 5 degrees, and off when it's 3.
All looked so simple :). But in practice when I installed the new electronic controller it turned out the system has huge lag/inertia. For example if it's 5 degrees and I start the heater the temp inside will rise up to 6-7 before it starts to fall down, obviously the heater needs time to warm up. And when I turn it off at 3 degrees the hater compartment is so hot, that after the heater is off it continues to cool down to 0 degrees celsius inside (my youghurt freezes).
I have searched around and the obvious solution for such problems is PID regulation. The problem is I don't want to make a complicated circuit for variable control of the heater.
Can you suggest an algorithm to compensate for the lag/intertia but still keep my simple on/off control of the heater?
I have plenty of power to do calculations, 1024 bytes of RAM and 15kb FLASH on the MCU, I know it's an overkill for this task but that's what I had lieing around. Let's hope with your help I will put this power to some useful task :).
Regards, Rado
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
snipped-for-privacy@gmail.com wrote:

Congratulations on the success you've had so far; it isn't trivial. The problem you found is addressed in on-off feedback with an "anticipator". For a house heater, that is simple a bit of resistance wire that the thermostat current runs through, so located that it warms the sensor above ambient. that "fools" the sensor, causing it to shut down the heater before the room temperature is high enough. With the resistance set right, the temperature coasts up to the set value with the heat already stored in the system,
It's not so simple for a refrigerator, but you might try ramping the setpoint down as a function of time while the heater is on. Less hysteresis probably wouldn't hurt.
A good model of the cooling process will provide even better anticipation; call it prediction. You can probably model the accumulated heat with single time constants and a linear ramp for warm-up and an exponential decay for cool-down. As a first approximation, the bubble-pump is either on or off, so speed of heat removal from the box can be modeled as a constant while the ammonia-water mix is circulating. The overall effect after circulation stops is probably negligible.
Let me know how you make out. The thermostat in my camper's fridge seems to be flaky. and I might follow your lead. :-)
Jerry
--
Engineering is the art of making what you want from things you can get.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Hi, Jerry and Tim!
Thanks for the answers and the interesting discussion. I wasn't aware of the existense of so called 'anticipator' before :).
I will definitely try lowering the hysteresis to 1 or 0.5 degrees.
Here's what I think to try as a first attempt at solving this. Measure the time form the moment the heater is turned on to the moment the temperature inside the fridge starts to fall. Also measure for how long the temperature continues to fall, after the heater is off. To show an example, lets say it takes 10 min for the heater to warm up and the temp inside to start to fall. Calculate the rate at which the temperature is rising while the heater is off. If it is 3 degrees now and it's going up with 0.1 deg/minute turn the heater on 10 min before the desired max temp will be reached. Do the same while the heater is on, and turn it off earlier based on the rate at which temp is falling and the time inertia is running. I'll assume the current rate of rise/fall is linear to simplify and see how this works out.
But before doing this I will make an RS232 connection from the controller and hook it up to the PC to collect the time/temp data. I got bored sitting in front of the refrigerator watching the current temp (I already have an LCD displaying the temperature inside) and timing how long it takes to warm up/cool down.
All code/hardware I make will be available for everyone to use, I'll publish it when it's working in an acceptable way :).
Regards, RAdo
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
snipped-for-privacy@gmail.com wrote:

A program in the thermostat that collects data and adjusts the times automatically would be better than collecting the data and determining times open loop. It would track changes that arise from variations in temperature outside the box and from the load inside it.
Jerry
--
Engineering is the art of making what you want from things you can get.

  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Jerry Avins wrote:

Yes it would. I would start by collecting data in the PC, though, so I could get a good feel for how things worked.
--

Tim Wescott
Wescott Design Services
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
snipped-for-privacy@gmail.com wrote:

The one big temperature controller that I've had experience with linearized its output by switching on and off with a varying duty cycle that was well within the thermal time constant of the chamber who's temperature it was controlling. It was still slow enough (around a 1 minute period IIRC) so you didn't have to worry too much about wearing out the solenoid. This slow on/off cycle was controlled by a PID; the behavior of the system was more or less classic.
For a refrigerator, though, attempting to use PID control with anything like a proportional output will net you a bunch of stability problems that probably aren't worth the pain for just cooling your yogurt. Not only would you have to tune the system in the first place, but the lag in the thing would vary between an April morning when all you have in their is your yogurt vs. the day after Thanksgiving when it's stuffed to the gills with all those leftovers. For all this pain you'd be able to hold the system to exactly 4 degrees instead of a range of 3-5 (or 2-6).
So I think you want something simpler.
Electromechanical thermostats do not just have a thermal switch with hysteresis: they also have a little heater coil called a "predictor" that slowly warms up the thermal switch when the heat is on (or the cold off, in your case). This predictor helps the thermostat anticipate the action of the cooler that it's controlling. With this predictor your system dynamics will be quite different than without.
Judging from the amount of temperature swing in your fridge when you use hysteresis I suspect that it must have had a thermostat who's action amounted to a pure relay with time delay. So you could either implement your switch-with-hysteresis plus a predictor, or you could just implement a stubborn switch that refuses to change state for 30 seconds or a minute after it changes, then does whatever the outside temperature is telling it to do.
--

Tim Wescott
Wescott Design Services
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Tim Wescott wrote:
...

Tim,
What you call a predictor, Minneapolis-Honeywell calls an anticipator. It's an easy thing to for for a heater. Would you use a Peltier junction for a cooler? Is there another direct way? I suggested ramping the setpoint up instead.
My house thermostat doesn't have an anticipator. Instead, it has a model based on past and present measurement. If there's overshoot, it cuts the furnace off earlier next time. If the rate of rise is low, it knows that it's cold outside and allows for less coasting from the heat in the firebox and the air in the ducts. (An open window has the same effect.) It doesn't know the actual outside temperature, but it doesn't need to. It measures the combined effects of outside temperature, insulation effectiveness, and furnace capacity and does the right thing. It runs off energy it stores in a rechargeable battery when the "contact" is open, and it behaves just as intelligently when controlling the air conditioning. $35 + tax. Made in China or Singapore; I forget which.
Jerry
--
Engineering is the art of making what you want from things you can get.

  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Jerry Avins wrote:

"Anticipator" is probably more correct*. I don't know what real refrigerators use (it'd be good to know) but I suspect they just anticipate ambient heating with a heater coil, because that's what's easy to make.

But how much work did it take to get the engineering right? An underlying point here is that what works right in an electromechanical setting (an anticipator) where mechanisms are hard to implement may not be the best thing in a microprocessor-powered environment where extremely complex control rules will not tax the system resources, but will take engineering time to implement. OTOH, an anticipator is known to work. Sometimes when you optimize your code you need to optimize it for engineering time, just making it good enough and stopping rather than chasing some "best functionality" rainbow.
* In its observational linguist form: "what everyone says".
--

Tim Wescott
Wescott Design Services
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Tim Wescott wrote:

...

For a heater, an anticipator needs a small external source of heat. That's easy to do. For a cooler, it needs a small external source of coolth.* That's not so easy. What do you suggest?
...
Jerry _________________________________________ * I like that word, even if it's not a real one.
--
Engineering is the art of making what you want from things you can get.

  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Jerry Avins wrote:

Just what I said: when you turn the refrigeration _off_, turn a little heater _on_. You're still successfully anticipating the fact that the heat will rise, you're just doing it in the reverse sense from if you're controlling a heater. All in all it'll probably heat the inside of the 'fridge less than a Peltier cooler would, and it'll be much less expensive.
--

Tim Wescott
Wescott Design Services
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Tim Wescott wrote:

I'm afraid you don't get it. The thermostat shuts the heat (electric, gas, whatever) OFF when the temperature at the sensor DROPS. Increasing the sensor temperature will keep the heat on forever. This is an absorption refrigerator. It contains ammonia dissolved in water, and hydrogen under pressure so that although the partial pressure of ammonia is different in evaporator and condenser, the total pressure difference is small. Because there is no significant pressure head, a bubble pump (like the stem of a percolator coffee maker) suffices to circulate the refrigerant. Ammonia dissolving in water releases heat. It comes out of solution in the evaporator, absorbing heat. External heat operates the bubble pump. When the heater is on, the machine is cooling, and it is cooling that needs to be anticipated. You can't do that with a heater.
Maybe http://www.rvmobile.com/Tech/Trouble/2801Sys.htm will be useful.
Jerry
--
Engineering is the art of making what you want from things you can get.

  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Jerry Avins wrote:

I'll grant that _one_ of is is having a _really bad day_, but that's as far as I'll go.

Right. The thermostat turns the refrigeration _off_ when the temperature _drops_, which causes the refrigerator contents to heat, with considerable lag. This is akin to a heater, except that in a heater the thermostat turns the heat _on_ when the temperature drops, which causes the temperature to rise, again with considerable lag.
In either case if you wait until the temperature rises to the setpoint before turning the refrigeration back on (or the heat back off) then the temperature will severely overshoot. To fix this you fire up the anticipator whenever you expect the temperature to be increasing.

Um, sorry. It is, overall, a negative feedback system. Increasing the thermostat temperature will tend make do what it can to _decrease_ the temperature. In the case of the refrigerator this means turning the refrigeration on; in the case of a heater it means turning the heat off. In either case, turning the anticipator's heater on when the system temperature is commanded to rise, and off when the system temperature is commanded to fall, will compensate somewhat for the long thermal lag in whatever it is that you're trying to cool or heat.
The anticipator, however, _is_ positive feedback, so it has to be pretty wimpy -- you don't want the thermostat to be enjoying the balmy breezes from the anticipator while the contents of your refrigerator (or house) freeze solid.

Wow. I always wondered how they did that -- now I know. I assume the process is quite inefficient, but less so than a propane-powered generator and a motor.

When the machine is heating or cooling the trend needs to be anticipated. This can be done by applying and then removing a heat source, or by removing and then applying a heat sink. In either case you need to slowly drop the thermometer's temperature when things are cooling and slowly increase it when things are heating. Whether you do this with an electric coil, a Peltier cooler, or a shivering mouse is immaterial.
--

Tim Wescott
Wescott Design Services
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Tim Wescott wrote:
...

I missed the import of that. When everything works normally and the door stays closed, the cycle will be a sawtooth, with a fast drop and a slow rise. The heater is an integrator. Since it would be on most of the time, it would effectively change the setpoint without doing much to minimize overshoot. An anticipator should operate on the steep slope.

See above.

Not necessary. With a processor, model the heat buildup in the bubble-pump branch and compute the predicted temperature if the heat were to shut off now. Shut it when predicted equals desired. Keep measuring. If the calculation is wrong, tune the predictor. Just like my house thermostat.

The temperature isn't commanded to rise in a fridge. That makes all the difference.

Turning the heat -- that is, refrigeration -- on early won't keep the yogurt from freezing. Turning it *off* early is needed. There's no way a heater will do that.

A Peltier junction and a shivering mouse may be equivalent, but heat won't work.
Jerry
--
Engineering is the art of making what you want from things you can get.

  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Jerry Avins wrote:

Exactly. You have a processor. You don't need an external setpoint modifier, whatever you want to call it.
There are a number of ways to crack this nut:
Modelling, as suggested above by Jerry can be a fairly simple 1st order predicted = temperature now + measured overshoot, or as complicated as the processor resources allow. However, the simple case takes no account of things that have been mentioned before like external temperature, amount of food in the fridge, etc. The complex model would need either to know these things (an external temperature sensor is easy enough, but amount of food sensor?), or keep track of time constants for heating cooling, lag, etc and adapt itself.
So, why not implement a PID solution? Actually, I doubt there's a need for the I term, but clearly a D term is required. This would react to the rate of change of temperature, switching the heat on or off early to prevent excessive overshoot. At the moment you have a pure P with way too much gain. You could start by using PWM to reduce that. You won't need much resolution; 0 to 100% in 16 steps would probably be enough.
Oh BTW, given the inherent integrating effect of the system, I don't believe that you need hysteresis, certainly not 2 degrees C.
--
Andy


Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Hi, Andy!
It seems we have typed our messages at the same time. Please see my reply to Jerry above. I think what I described is close to what you call a 'D term'.
I don't know much about control theory, I've downloaded some books I could find online and will try to educate myself a bit.
I use a mechanical relay to switch the heater on/off so I try to keep the number of switches low. That's why I think a PWM solution is not appropriate, I think solid state switchin is required for PWM to work reliably, but designing the circuitry for solid state switching is beyond my skills.
How can I control it without hysteresis? Won't this cause rapid on/off switching? I thought at least some hysteresis is needed (though I agree my first 2 degree C quess is too much) if not for something else my temp sensor LM335 has at best +-1 deg accuracy, and the 10 bit ADC is +-1LSB accurate. I see the measured temp fluctuate within some limit, which is surely because of errors, real temp can't change that fast - i measure it 2 times per second to display it on the LCD. I'll try putting the MCU in some ADC sleep mode it supports and see if this will improve measurement accuracy, at list according to the datasheet it will eliminate internal noise.
Regards, Rado
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
snipped-for-privacy@gmail.com wrote:

You can but solid-state relays, but that's not the point. An absorption refrigerator is an on-off device. If there's enough heat to make bubbles in the riser pipe, it cools. If the heat falls below a threshold, it stops. The rate of cooling varied from full to zilch over a very narrow range of boiler temperature. You can exercise linear control over the heater, but not over the whole refrigerator.

About hysteresis, you're right on. The accuracy of the LM335 isn't really important, but the repeatability is. At worst, you can calibrate it against a good thermometer. In use, you will likely use a thermometer in the refrigerator. Most refrigerator thermostats have numbers unrelated to temperature anyway.
How many of the ADC's bits are actually used? if only 5 or 6, you might consider an amplifier.
Jerry
--
Engineering is the art of making what you want from things you can get.

  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Rado,
There is a conceptual difference between what you describe and the D (differential or rate controlling) term.
In your scheme, you are modelling, as suggested by Jerry, and using this to modify the set point (i.e. telling the heater that the temperature is already at the set point in the cooling case, or that it is about to exceed the set point in the warming up case). If you base the delays and rates of cooling & warming-up on current observations, then you are being adaptive.
The traditional P, I & D terms are directly in the feedback loop, modifying the demand to meet the set point. This is a reactive system.
Because your time constants are long, you don't need rapid switching. I expect that a minimum on or off time of 1 minute would be OK. A heater load is a pretty benign load, compared to a motor, so you relay life should be fine.
Re the hysteresis: you won't get rapid on/off given the time constants of your system, and if you are using some kind of proportional control, it will simply make the control worse.
Andy
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
snipped-for-privacy@gmail.com wrote:

See http://www.wescottdesign.com/articles/pidwophd.html and other articles on, or linked from, my website. Sometime this spring my book, http://www.elsevier.com/wps/find/bookdescription.cws_home/707797/description#description , should be coming out. I hope it will be helpful (it does go into the math, but I tried to make it as painless as possible).

There's PWM and there's PWM. To effectively PWM a driver you need to switch it slower than the time constant of your plant. In this case your plant's time constant is measured in minutes, if not 10's of minutes, so having a PWM period of a minute (or two, or five) is no problem at all. The two biggest concerns that you should have if you choose to PWM are wear on the relay (which you could fix with a solid state relay) and any efficiency lost in the cooling process when the heater is heating up but not yet making the cooler percolate.

If you use my suggestion of switch then wait a while you will be guaranteed switching times that are no shorter than the wait, and will probably be longer because the temperature will change.

1LSB accurate or repeatable?

You may get better resolution (_not_ accuracy) by measuring significantly faster and averaging. Averaging over a power of two interval is easy, because you just add up the readings and right shift the result. If the last ADC bit is really random you'll pick up quite a bit of resolution this way.
I'd suggest 32 times a second -- take 16 samples, add them up. Don't shift them down for internal use -- use the extra 4 bits of noisy data for the resolution they'll give you. Do shift them down for temperature display, however.

--

Tim Wescott
Wescott Design Services
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Tim Wescott wrote:
...\

My experience with an absorption refrigerator rated 90 to 135 volts was that cooling capacity maxed out at 120-125 volts and dropped a bit at 135. (Too much froth, not enough liquid?) 90 volts cooled at about the same rate as 135, and it didn't cool at all at 85 volts. What kind of PWM can be done with that? Just think of the thermostat as a long-period pulse-width modulator if that scratches your itch. :-)

A sticky switch is hysteresis of a sort.

We're on the same track here.
...
Jerry
--
Engineering is the art of making what you want from things you can get.

  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Jerry Avins wrote:

Find out how long it needs to be on to be efficient and make sure you keep it on that long.
Yes, the thermostat acts as a long-period pulse-width modulator, but the period is long enough that the plant temperature discernibly changes. The one and only one PWM'd thermal control system that I am familiar with had a period of about 10 seconds. It was well within the time constant of the 600 cu-ft thermal chamber that it controlled, but outside of the time constant of the LN2 valve (at least once the gaseous N2 was purged and the liquid actually made it to the chamber).
Keeping in mind that I don't think a PID controller with a PWM'd actuator is necessary, I doubt that a 10 second period would be right in this case: I think the percolator would be wasting a lot of energy on thermal cycling for not much cooling. If you _were_ going to use PWM you'd have to figure out how long the percolator needs to warm up (and hence how much energy you waste), decide how much energy you wanted to waste doing that vs. actual cooling, then set your minimum PWM interval accordingly.
From my perspective this is mostly moot: I would just use the thermostat, and let the fridge temperature vary a bit.
--

Tim Wescott
Wescott Design Services
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.