R60 A Home Heating & Lighting Controller A Personal Embedded Controller Although most TCJ readers are familiar with my regular¨ column on Z-System software, I actually got my start in¨ microcomputing with controllers. Ever since editor/publisher¨ emeritus Art Carlson began asking for articles on embedded¨ controllers, I have thought about describing my very first¨ computer project, an Intel 8085-based controller that has¨ been operating the heating and lighting systems in my house¨ for the past decade. Background In the late 1970s I was working in Raytheon Company's¨ Research Division developing charge-coupled devices (CCDs)¨ for analog signal processing. To facilitate the measurement¨ of field-effect semiconductor devices, I designed a number¨ of test boards that used analog integrated circuits¨ (especially operational amplifiers) and small- and medium-¨ scale digital logic circuits. At the time, Raytheon sponsored some Summer short courses¨ at Cornell in various electrical engineering subjects. One¨ of them was an introduction to the then new microprocessor¨ chips. In return for its support, Raytheon was allowed to¨ send one employee to attend the course. I was offered the¨ opportunity; it sounded like fun; so I accepted. I enjoyed¨ that course so much that on my return I started immediately¨ on the design of a microprocessor-based system that would¨ operate the electrical circuits in our house. Why did I choose that application? A couple of years¨ earlier, our house had been broken into, and to discourage¨ burglars from a repeat performance, we put clock timers on¨ half a dozen of our lamps. It was quite a nuisance, however,¨ when a timer would turn off the only light in the room and¨ we would have to crawl around on the floor in the dark¨ trying to find the timer. The computer controller would make¨ life easier by working in parallel with the regular light¨ switches. In addition, we were still in the aftermath of the 1973¨ oil crisis, and I thought we could greatly reduce our oil¨ consumption by having the computer controller operate the¨ electrical circuits in the heating system. Ultimately, this¨ is where the system has really been productive. It is going to take a couple of columns (at least) to¨ describe this whole project. This time I am just going to¨ lay the groundwork; next time I will get into the details of¨ the computer circuit. Although the circuit was designed and¨ built more than ten years ago, and I would do a number of¨ things differently today, the basic concepts are, I think,¨ still sound and instructive. The Basic Functions The functionality of the controller that is visible to¨ the user is basically a flexible scheduler. It stores the¨ day and time when actions are to take place. It also knows¨ about various conditions, such as whether we are at home or¨ away and whether it is an ordinary day or a vacation period.¨ Scheduled events can depend on combinations of those¨ conditions. Two kinds of actions are supported: (1) turning¨ electrical circuits on or off and (2) setting the thermostat¨ for the heating system. Electrical circuit switching is¨ actually controlled in two ways. The obvious way involves¨ turning circuits on and off at specific wall-clock times. A¨ second stored schedule turns circuits on and off at times¨ relative to the onset of darkness outside, as determined by¨ monitoring a photocell. I generally turn lights on based on¨ outside brightness and turn them off based on wall-clock¨ time. In this way, the schedule does not have to be revised¨ with the change of seasons. Also, lights will turn on¨ automatically during dark rainstorms (and off again when the¨ storm clears). We will share more specifics about the operation of the¨ controller next time. For now we will continue with a¨ discussion of the internal control strategy used to operate¨ the heating plant. Heating Control Concept Our house, like many in New England, uses an oil-fired¨ boiler to heat water that is circulated by a pump through¨ radiators (cast iron in our case). A thermostat senses the¨ air temperature and turns on the circulator when the room¨ air drops below the set temperature. The temperature of the water in the boiler is similarly¨ regulated by what is called an aquastat. While the¨ thermostat could be set back at night, either manually or¨ automatically, the aquastat always has a fixed setting. In¨ order to ensure adequate heat on the coldest day possible,¨ the water temperature is generally kept at a very high¨ setting, perhaps 180 degrees Fahrenheit (80 Celsius). Day¨ and night. Warm weather and cold. And what does all the hot water in the boiler do while it¨ is sitting around waiting to be circulated to the radiators?¨ Well, for one thing, it leaks its heat into the basement.¨ Our basement being unfinished, this is nearly a complete¨ waste. Second, it sets up a nice convection up the chimney.¨ This literally sucks heat up the chimney, cooling off the¨ water in the boiler and drawing fresh cold air into the¨ house. More waste! Besides being inefficient, this control strategy also¨ provides less comfort. After the air in the house cools, the¨ circulator comes on, bringing very hot water into the¨ radiators, which then transfer their heat into the air. Soon¨ the room has warmed up and the circulators shut off. But,¨ the radiators are still nice and hot, and they keep pouring¨ heat into the room. The room gets much hotter than the¨ thermostat setting, and during the long cooling down time¨ with no heat, the rooms tend to have cold drafts. Not very¨ nice! The best thing to do, I thought as a physicist, was to¨ control the water temperature so that the radiators were at¨ just the right temperature to transfer heat into the air at¨ the exact rate heat was leaking out of the house. The¨ circulators could run continuously. On warmer days and at¨ night, when the thermostat setting was low, the boiler water¨ would be quite cool, and the losses, both into the basement¨ and up the chimney would be much less. Also, there would be¨ almost no swings in air temperature, and the steady low­ level heat from the radiators would inhibit drafts. Simple, linear heat conduction theory implies that the¨ boiler temperature would have to exceed the desired (and¨ actual) air temperature by some factor times the amount that¨ the air temperature inside is to exceed the air temperature¨ outside, that is ( Tb - Ti ) = K * ( Ti - To ) or Tb = ( K + 1 ) * Ti - ( K * To ) where Tb is the boiler temperature, Ti the inside air¨ temperature, and To the outside air temperature. The factor¨ K depends on the amount of insulation in the house and the¨ effectiveness of the radiators (big cast iron radiators are¨ great; baseboard units are pretty poor). More Sophistication Once one has a microprocessor running things, one might¨ as well really put its processing power to work. I,¨ therefore, applied some more sophisticated control¨ strategies on top of the basic one described above. If the aquastat is set exactly at the temperature¨ required to maintain the steady-state air temperature¨ desired, then there will be no excess capacity to allow the¨ house to warm up when the thermostat setting is increased.¨ Therefore, an additional correction is included in the¨ aquastat setting in proportion to the difference between the¨ desired air temperature and the actual current air¨ temperature. The equation thus becomes Tb = (K1 + 1)*Ti - (K1 * To) + K2*(Ts - Ti) where Ts is the thermostat setting. Adding this term has several benefits. It allows the¨ house to warm up during programmed increases in temperature¨ (Ts-Ti > 0), as we just said. It also allows the boiler to¨ remain extra cool during programmed decreases in thermostat¨ setting (Ts-Ti < 0). Finally, it enhances the stability of¨ the system against errors in the control parameters. Cycling an oil burner on and off is not good for¨ efficiency. During the first several minutes of a burn,¨ while the combustion chamber (fire box) is still cold, the¨ oil does not vaporize well and, therefore, does not burn as¨ well. There is less heat and more soot, which builds up on¨ the heat exchanger and impedes heat transfer into the water. The best thing would be to have a variable-firing-rate¨ nozzle. Then one could keep the flame on continuously and¨ regulate its heat production to match exactly the leakage¨ rate from the house. Today there are gas-fired boilers that¨ work somewhat this way. As far as I know, this has never¨ been done with oil. I suspect that burning oil is a tricky¨ process and that nozzles are carefully optimized for a¨ particular flow rate. Building an efficient variable-flow­ rate nozzle may not be feasible. My compromise was to use a nozzle that provided just a¨ little more heat than would be needed on the coldest¨ possible day. Experiments showed that I could change to a¨ nozzle with only half the flow rate of the one that had been¨ in the boiler! With a small nozzle, firing times are longer,¨ and the inefficient burn time is a smaller fraction of the¨ total burn time. Naturally, we want the house to be quite cool at night,¨ and there is no sense keeping the boiler warm during that¨ time. Therefore, the controller is programmed so that when¨ it sees a decrease coming in the desired air temperature, it¨ automatically decreases the aquastat setting and allows the¨ radiators to extract as much heat as possible. Typically, by¨ the time we go to bed at night, the boiler is down to only¨ about 25 degrees C, barely above room temperature. This in turn introduces a new problem. With the boiler so¨ cold overnight and such a low firing rate, if the system¨ waited until the thermostat setting came back up to turn on¨ the boiler, it might be many hours before the house would¨ catch up. The controller is, therefore, made to look ahead¨ and to compute the time to begin firing so that the house¨ temperature reaches a future programmed temperature at¨ exactly the time it is programmed for. On a really cold day,¨ the boiler begins firing three or four hours ahead! Normally the boiler is cycled on and off in response to¨ the computed aquastat setting. If one used a single¨ temperature set point, of course, the oil burner would turn¨ on and off frequently, so, as with standard mechanical¨ thermostats and aquastats, some hysteresis is included to¨ stabilize this. In other words, the turn-off setting is¨ slightly higher than the turn-on setting. In addition, since the early firing of the burner is less¨ efficient, the controller is programmed to give a minimum¨ burn time, once firing has started, independent of aquastat¨ setting. I figured that it was better to have the water¨ slightly hotter than necessary sometimes rather than have¨ short burn times. Water condensation in the cool chimney and¨ boiler parts could lead to corrosion. The minimum burn time¨ was chosen to ensure that the boiler flue temperature would¨ reach at least 100 C. There is a worry one always has with a circulating water¨ heating system -- freezing. If there is a pipe near an¨ outside wall, and if the circulator is off for a long period¨ of time, and if the weather is very cold, a section of the¨ pipe may freeze and possibly burst. This makes for quite a¨ mess (especially if you haven't disabled the automatic water¨ filling system, as I have). To prevent freezing, the¨ software turns on the circulator for a short period of time¨ after a maximum off interval even if no heat is needed. As I mentioned earlier, with the control strategy¨ implemented here, the circulator can run nearly¨ continuously. In fact, that is exactly what happened with an¨ early version of the software, and we noticed a substantial¨ jump in our electric bill because of the energy consumed by¨ the motor. I then reasoned that it should be adequate to turn on the¨ circulator only long enough to exchange the slug of water in¨ the radiator for a new, warm slug of water. So long as the¨ room temperature is within some hysteresis band of the¨ desired temperature, the circulator is cycled on for only¨ one minute out of ten. Should the room temperature fall¨ below the bottom limit point, then the circulator runs¨ continuously. This approach has been very effective. Design Goals The above description should give you a pretty clear¨ picture of the kind of sophisticated control that a¨ microprocessor based system can provide. I would like to¨ close this installment by saying a few things about some¨ important design constraints I imposed. I required that the system operate for an extended period¨ of time without AC power. One would not want a power glitch¨ to erase the programmed schedule and leave the electrical¨ circuits and heating system uncontrolled thereafter. We¨ might, after all, be away on vacation. A sealed lead-acid¨ battery, constantly charged from the AC, can operate the¨ complete system for at least 10 hours. During the time that the power is off, some control¨ operations cannot be performed because there is no¨ electrical power to the circuits being controlled. The¨ system is smart enough to know that AC power has failed, to¨ keep track of any state changes that should have been¨ carried out, and to carry them out as soon as power is¨ restored. A second requirement was that the system be highly fail­ safe. A complete failure of the computer must still result¨ in a house whose temperature will stay within reasonable¨ bounds. Failure of the controller with the boiler turned on¨ must not lead to overheating and possible explosion of the¨ boiler. Failure of the controller at a time when the boiler¨ is turned off must not allow the house temperature to drop¨ to the point where water pipes might freeze. We will leave¨ the description of how this is done for next time. Finally, there must be full manual backup control.¨ Electrical circuits must be switchable as usual with the¨ computer controller turned off or completely removed. Under¨ the same circumstances, the heating system must fall back to¨ normal manual control. This, too, will be described next¨ time.