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

Reply to
radolin
Loading thread data ...

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

Reply to
Jerry Avins

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.

Reply to
Tim Wescott

...

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

Reply to
Jerry Avins

"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".
Reply to
Tim Wescott

...

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.
Reply to
Jerry Avins

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.

Reply to
Tim Wescott

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

formatting link
will be useful.

Jerry

Reply to
Jerry Avins

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.

Reply to
Tim Wescott

...

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

Reply to
Jerry Avins

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.

Reply to
Andy McC

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

Reply to
radolin

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

Reply to
radolin

You'd need to be careful applying any sort of duty cycle control with this system in that the cooling effect is likely to be pretty nonlinear. Applying partial heat is likely to result in minimal cooling below a certain threshhold.

Reply to
bruce varley

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

Reply to
Jerry Avins

The actual behavior of the box is the result of the combined effects you list. Since the behavior, not its causes, needs to be controlled, separating the effects isn't necessary. At it's simplest, measure the under/overshoot and adjust the next cycle to correct it. Sophisticated analysis can shorten the convergence time, but that may not be needed.

An anticipator behaves like a D term.

Oh BTW, given the inherent integrating effect of the system, I don't

You do need hysteresis, but not likely that much. In practice if not on paper, every switch needs to be debounced. Hysteresis does that.

Jerry

Reply to
Jerry Avins

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

Reply to
Jerry Avins

I have my AREF for the ADC at 5.0V and the sensor outputs 10mv/degree kelvin, so at the temperatures I measure is around 2.8V. ADC resulution in this case is 5mv, so I have 0.5 degree K resolution and around 1 degree accuracy (from the ADC), but the sensor itself is rated +-1 degree. I don't need more for the current project I think.

I thought of measuring the lag once and hardcoding it, but your idea to make dynamic adjustments makes the project more interesting. I'll try to do it. This I suppose will give better results when external temperature and refridgerator contents vary.

If I can keep the temperature inside in a 2 degree C band for periods when the door is not opened I'll be more than happy.

When the door is opened for longer than a couple of second the temperature rises and it needs some time to compensate. With such low powered unit I think this is unavoidable (the heater is less than

100W), I'll just have to make up my mind before opening the door ;).

Regards, Rado

Reply to
radolin

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

Reply to
Andy McC

Air temperature rises quickly when the door is opened, but the food, because of its high water content, doesn't. The food and other parts of the box will begin to cool the air significantly as soon as the door is closed, even without the refrigerator turning on.

Jerry

Reply to
Jerry Avins

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.