R60 A Home Heating & Lighting Controller, Part 2 The Electrical Interface In the introductory column last time on the embedded¨ controller that runs the electrical and heating systems in¨ my house, I described the history behind its development and¨ the control strategy it applies to managing the heating¨ system. This time I am going to talk about the electrical¨ interface, that is, how the computer, which runs on low­ voltage DC, is able to operate the high-voltage AC¨ electrical circuits in the house. The GE Low-Voltage Wiring System The basis of the interface is the General Electric low­ voltage wiring system. It was designed primarily for¨ industrial installations, but somehow my group leader at¨ Raytheon had found out about it and used it when he built¨ his own house. Since then I have seen it several other¨ times. In fact, the lighting system in the main auditorium¨ at Lincoln Laboratory uses it. The basic idea is as follows. Each circuit, no matter¨ from how many places it is to be controlled, has a single,¨ latching relay installed to switch the AC current. These¨ relays have two windings that operate at 24 volts, AC or DC. ¨ When one of the windings is energized, a shorting bar is¨ pulled back from a pair of electrical contacts, opening the¨ 110-volt circuit; when the other winding is activated, the¨ shorting bar is pushed into the contacts, closing the¨ circuit. These relays are designed to mount through the cutout in¨ a standard electrical wiring box. The 110-volt AC¨ connections are made inside the box, while the low-voltage¨ connections are made outside. This maintains isolation¨ between the two systems and keeps the low-voltage system¨ safe against shock hazard. The single-pole single-throw toggle switches normally¨ used in the wall boxes to control the AC are replaced by¨ small, momentary-contact, single-pole double-throw (SPDT),¨ center-off low-voltage switches. The basic circuit is shown¨ in Fig. 1. For reasons that will become clear later, we¨ operate the switches from a DC source. At rest, the switches are in a neutral, center position¨ with the pole connected to neither side. To turn the AC¨ circuit on, one presses the top of the switch. This¨ completes the circuit to the ON winding of the relay. The¨ switch need be closed for only a small fraction of a second,¨ after which the relay is latched into the ON state. To turn¨ the circuit off, one taps the bottom of the switch,¨ completing the circuit to the OFF winding of the relay and¨ opening the circuit. The simplest, least expensive low­ voltage switches are so small that three of them can fit in¨ the standard electrical box used for one AC switch. Advantages of the GE Low-Voltage System The GE low-voltage wiring system has many advantages. ¨ For example, there are very strict codes that apply to the¨ treatment of 110-volt AC wiring. For obvious reasons, the¨ wiring has to be carefully protected -- mechanically,¨ electrically, and thermally. All connections must be made¨ inside boxes that meet the standards of the electrical code,¨ and wire runs have to be enclosed, either inside walls or¨ inside conduits, or both. Because of the high electrical¨ energy available in 110-volt circuits, overload breakers are¨ required to interrupt the current flow if it reaches a level¨ that could cause the wires to reach an unsafe temperature¨ and ignite a fire. In many, if not all, jurisdictions,¨ 110-volt wiring must be installed by a licensed electrician;¨ at the least, a permit is required, and the work must be¨ inspected. After all, if it is done improperly, it can pose¨ the dual threats of electrocution or fire. The low-voltage wiring is intrinsically safe. The¨ voltage is too low to cause electrocution, and the¨ transformer that provides the power has a high enough¨ internal impedance that even if the wiring is shorted it¨ cannot generate enough heat to pose a fire hazard. ¨ Consequently, there are, as far as I know, few or no code¨ requirements on how this wiring is installed. It's¨ basically like wiring up a doorbell. In principle, the wiring materials are also cheaper. For¨ 20-ampere service, the AC lines must use 12-gauge wires --¨ including a ground as well as a neutral lead -- with heavy¨ insulation. The low-voltage wiring needs only 16- or¨ 18-gauge wire and lighter insulation. No grounding is¨ necessary. The switches are also intrinsically much cheaper, since¨ they switch relatively low currents at low voltages. In¨ practice, however, I have found that most of this advantage¨ is hard to realize. Standard AC wiring components, because¨ of the extremely high production volume and competition¨ among suppliers, are available at very low prices. For¨ large-scale industrial installations, there probably is a¨ cost saving, both in material costs and in labor for¨ installation. For home installations, this is not a¨ significant factor. One of the most important advantages of the GE system to¨ me was the ease with which it allows multiple controls in a¨ circuit. Consider the problem of wiring a circuit so that¨ it can be switched from two or three different places. Fig.¨ 2 shows the required switches and wiring for one-, two-, and¨ three-switch circuits. You can see how rapidly they grow in¨ complexity. With only one switch, a single-pole single-throw (SPST)¨ switch suffices, along with a normal three-wire cable (hot,¨ neutral return, and ground). The two-way circuit requires¨ single-pole double-throw (SPDT) switches, and the cable¨ between the two switches has to have and extra conductor. ¨ By the time we get to the three-way circuit, we have DOUBLE­ pole double-throw switches (DPDT) and up to FOUR extra wires¨ in the cable. The same circuit using the GE wiring is illustrated in¨ Fig. 3. Note the extreme simplicity. Although I have shown¨ only three switches, in fact there can be ANY NUMBER OF¨ SWITCHES. The circuit does not increase in complexity no¨ matter how many switches are used. This is a bus¨ architecture -- if you want another switch, you just hang it¨ off the bus! And this just begins to show the flexibility of the GE¨ system. Look at Fig. 4! There we show two AC circuits. ¨ Switch A controls the circuit on the left; switch C controls¨ the circuit on the right. What about switch B? It controls¨ BOTH circuits. The diodes are needed to isolate the two¨ relay control circuits (and that's why we use a DC low­ voltage source). If you study the circuit, you will see¨ that when switch A is closed, it cannot draw current from a¨ winding of the right-hand relay because there will be a¨ reversed diode in the path. With conventional AC switches,¨ this functionality can be achieved only by ganging up¨ electrically independent switches, a bulky and expensive¨ proposition. With the GE system, the only extra components¨ are a few tiny, dirt cheap switching diodes. The concept can be extended to a complete diode crossbar¨ connecting a group of switches 1...M to a group of relay¨ windings 1...N, as shown in Fig. 5. By inserting diodes¨ into the crossbar, any switch can be made to control any¨ combination of relay windings, completely independently of¨ the function of any other switch. When a given switch¨ grounds one of its leads, all relay windings connected to¨ that lead by a diode will be pulled to ground, energizing¨ the associated relay. The directionality of the diodes¨ prevents one pulled-down relay winding from pulling down¨ another switch wire and thence other relay windings. Note that the ON and the OFF functions of a single switch¨ may be programmed independently! For example, one of the¨ switches in our bedroom is set up to turn off all three¨ lights in the living room. This is handy when we go to bed. ¨ The ON position of the same switch, however, turns on only¨ one light. Separate switches in or near the living room¨ control the individual lamps. In fact, there is nothing to¨ say that an OFF position on a switch has to turn a circuit¨ off; it can just as well turn it on. One might have a¨ switch whose ON position turns one light on and another one¨ off. The OFF position, meanwhile, might turn the second¨ light on and the first one off. Basically, you can do¨ absolutely whatever you want. Interfacing to the Computer The next important thing to realize is that switches are¨ not the only things that can activate the relay windings. ¨ All the switches are doing is pulling a circuit down to¨ ground, and that is something that a TRANSISTOR can do just¨ as well. It would be very hard to use a transistor to control AC¨ circuits directly. First of all, transistors cannot easily¨ control such high voltages and currents. Secondly,¨ transistors are intrinsically unipolar; they like to have¨ current flowing in only one direction. For example, with an¨ NPN transistor, current injected into the base controls a¨ current flowing into the collector toward the emitter. The¨ magnitude of the current can be controlled but not its¨ direction. Although the relays latch at modest currents (fractions¨ of an ampere), the normal parallel-port drivers on a¨ computer are not, by themselves, powerful enough to operate¨ the relays. However, there are very nice, inexpensive,¨ compact integrated circuits that provide the buffering¨ between the milliampere drive capability of parallel-port¨ chips and ampere-range currents of peripheral circuits. I used ULN-2814 ICs made by the Sprague Electric Company. ¨ These are 18-pin DIPs with eight individually controlled¨ circuits, each capable of sinking 600 ma of current and¨ sustaining up to 50 volts in the OFF state. I can't find¨ the data sheet for this specific part, but similar parts for¨ which I do have data sheets require input currents of less¨ than 1 ma. More Details on the Interface I would now like to cover some details of the interface¨ circuit, which is actually a little more complicated than¨ what I suggested above. I designed the controller to handle 16 circuits, which¨ means 32 relay windings. This would take four 8-bit¨ parallel ports to handle all at once, but I decided that the¨ controller would pulse no more than one relay at a time. ¨ This simplified the control software, since circuits can¨ then be treated sequentially, one at a time. In addition,¨ it completely eliminates the possibility of exceeding the¨ power dissipation limits of the driver ICs, since only one¨ of the eight drivers could be dissipating power at any one¨ time. If only one driver is to be active at one time, I can get¨ by with an addressing circuit. Five bits are enough to¨ select one driver out of 32. Since most of the time no¨ circuits are activated, we need one more line to serve as an¨ 'enable' control. That makes six lines in all; one parallel¨ port from the microcomputer can handle it. It seemed a bit risky to me to have the relay windings¨ connected directly to the computer. For one thing,¨ inductive circuits, such as relay coils, tend to produce¨ nasty transients. Although I included in the circuit some¨ protective diodes to clip any voltages that tried to get¨ outside the range from ground to 24 volts, I felt that the¨ computer was too expensive to take any chances with. The¨ low-voltage wiring involved hundreds or even thousands of¨ feet of wire, and there was always a chance for an error¨ that might put a very high voltage on that wiring. The answer was to optically isolate the computer from the¨ relay-driver circuitry. For those of you who are not¨ familiar with these components, they have a photoemitter¨ (light-emitting diode or LED) controlled by the input side¨ of the IC and a photodiode or phototransistor detector on¨ the output side of the IC. The two parts are separated by a¨ high-dielectric strength insulator that is optically¨ transparent. I chose the 5082-4351 optically coupled isolators from¨ Hewlett Packard. Each eight-pin mini-DIP houses one¨ coupler. The input leads are on one side of the chip (pins¨ 1 to 4), while the outputs are on the other side (pins 5 to¨ 8). The chip can operate with a potential difference of up¨ to 2500 volts between the two sides! There are six of these¨ chips on the board, one for each control line. The Sprague 2814 interface chips get their inputs from¨ four CD4051 3-to-8 decoder chips. Address lines A0, A1, and¨ A2 will select one of the eight output lines. The CD4051¨ also has an inhibit input. Only if the inhibit is released¨ will any output from that chip become active. A fifth CD4051 is used to select which one, if any, of¨ the four main decoders will be enabled. Address line A3¨ goes to the low order input of this fifth decoder and¨ selects between circuits 0..7 and 8..15. The fifth address¨ line, which I call the ON/OFF line, selects between the¨ drivers that connect to ON relay windings and those that¨ connect to OFF windings. Finally, the inhibit input is¨ controlled by the sixth addressing line. The microcomputer¨ puts a 0.1 second pulse on this line after the correct¨ driver has been selected by the other address lines. Interfacing to the Heating System The interface to the heating system controls is also made¨ using GE low-voltage relays. In this case, however, the¨ relays are being used as general computer-controlled¨ switches and not for the direct control of 110 volt AC. I will start with a description of the control of the¨ thermostat setting. One's first thought would be to have a¨ GE relay directly turn the circulator pumps on and off. But¨ what would happen, then, if the computer failed and the¨ circulators did not go off or on? The house could easily¨ overheat or freeze. And what would I do if the computer had¨ to be shut down for repair? For safety and reliability reasons, I decided to take an¨ indirect approach. I installed a second standard¨ thermostat. The original thermostat was left exactly as it¨ was, but it was set to the lowest temperature to which we¨ would ever want the house to go (about 50 degrees¨ Fahrenheit). If the air temperature drops below that¨ setting, the circulator pump will come on quite¨ independently of the computer, and if the computer ever has¨ to be shut down, all I have to do is go back to using this¨ thermostat in the usual way. The second thermostat is installed in parallel with the¨ original one, except that a GE relay is installed in series¨ with its wires. This thermostat is set to the highest¨ temperature we would ever want the house to reach (about 73¨ degrees). Now consider a normal situation where we are¨ trying to control the temperature at, say, 68. In this¨ case, the first thermostat's circuit will be open (since the¨ air temperature is above its setting), but the second¨ thermostat's circuit will be closed (since the temperature¨ is below its setting). Now, if the computer closes the GE¨ relay, the circulator will run, and, if it opens the relay,¨ the circulator will stop. Thus the computer can control the¨ circulator, but the range of control is bounded by the¨ settings on the two thermostats. If we set both thermostats¨ to the same temperature, then we are back to normal control¨ of the circulator. Now let's look at how I control the temperature of the¨ water in the boiler. I explained last time that the system¨ has what is called an aquastat. Just as a thermostat senses¨ the air temperature and opens or closes a contact, the¨ aquastat senses the water temperature and opens or closes a¨ contact. I could have let the computer control the oil burner¨ directly by installing a GE relay in place of the aquastat,¨ but this would be risky. What if the computer made a¨ mistake and failed to turn off the boiler? We could end up¨ with an explosion. There is a second, safety aquastat that¨ is supposed to protect against this, but I really did not¨ want to rely on it. Instead of removing the aquastat, I just installed the GE¨ relay in series with it. In this way, the computer could¨ turn off the oil burner, but it could not force the burner¨ to remain on after the water temperature reached the¨ aquastat setting. We set the aquastat to the highest¨ temperature that would be needed on the coldest expected¨ day. Now what happens if the computer fails to turn on the¨ boiler on a very cold day? Our fail-safe thermostat¨ arrangement will start the circulator pump, but this will¨ not help if the boiler is off. To protect against this¨ possibility, I installed another thermostat in the basement¨ and wired its contacts in parallel with the GE relay. I had¨ observed that enough heat leaked into the basement from the¨ boiler that the temperature there never dropped below about¨ 50 degrees, so I set this thermostat to just under that. ¨ Now if the computer should fail to turn on the boiler, this¨ thermostat would short out the GE relay and again allow the¨ regular aquastat to regulate the boiler. If the computer¨ has to be removed for repair, all I have to do is raise the¨ setting on that thermostat to, say, 80. Then the relay will¨ always be bypassed, and the normal controls will operate. The Sensors As I discussed last time, the controller requires various¨ environmental sensors. Management of the heating system¨ requires knowing three temperatures: the temperature of the¨ air in the house, the temperature of the air outside, and¨ the temperature of the water in the boiler. I chose to use¨ precision linear thermistors manufactured by YSI, the Yellow¨ Spring Instruments Company. These are tiny modules, perhaps¨ a millimeter across, that look like little capacitors. ¨ Inside there are two thermistors. When wired up with a pair¨ of precision resistors, the circuit can produce either a¨ resistance or a voltage that is a very highly linear¨ function of temperature. Of course, the computer could have¨ converted the signals from single, nonlinear thermistors to¨ accurate temperature values, but it seemed much easier¨ simply to buy the better components. The thermistors come in various types for different¨ temperature ranges. For example, the one for sensing inside¨ air temperature is designed for temperatures from 30 to 100¨ degrees Fahrenheit. It has an absolute accuracy of plus or¨ minus 0.3 degrees. I wired the thermistors for voltage¨ outputs and then fed the signals to CMOS operational¨ amplifiers. The gains of the amplifiers were set to provide¨ a convenient mapping of temperature onto a one-byte binary¨ scale in the output from the analog-to-digital (A/D)¨ converter. For example, the inside air temperature uses 255¨ units of 0.1 degree Celsius to read from 0 to 25.5 (78 F). ¨ The boiler temperature, which spans the greatest range, uses¨ 255 units of 0.5 degree to cover temperatures from 0 to¨ 127.5. [By the way, with this project I made the conscious¨ decision to go metric. All temperature displays and¨ settings are in Celsius.] The one other environmental sensor is a photocell to¨ measure outdoor light level. I just grabbed some old¨ photocells from a junk barrel and tested them until I found¨ one with a logarithmic voltage response. This signal, too,¨ goes to a CMOS op amp, whose gain is set to give a nearly¨ full-scale input to the A/D converter on a clear, sunny day. Closing Comments Some of you may wonder how I managed to retrofit the GE¨ low-voltage wiring in my house. Given my interests in¨ electrical experiments, I am lucky to live in a house with¨ an unfinished basement. The electrical wiring (and the¨ plumbing) are conveniently exposed in the ceiling. All the¨ wall outlets were fed from the basement, and it was easy to¨ install GE relays to control those outlets I wished to switch. At the time, our house also had an only partially¨ finished second floor. The few circuits (overhead lights)¨ that I could not tap into from the basement I could get to¨ from the attic. Shortly after I built the home controller, I renovated¨ the second floor. Actually, I gutted it and rebuilt it from¨ scratch, a project that took a whole year of full-time¨ evening and weekend work. It cured me of any desire ever to¨ do that again, but it did give me a golden opportunity to¨ wire things the way I wanted to. I installed numerous¨ switch boxes and ran large bundles of wires from each one¨ back to central control panels. There, as I described¨ earlier, I can easily rewire any of the switches to perform¨ any functions I want. I also fed a huge bundle of low-voltage cables down into the basement. Some go to the¨ computer and some to switches on the first floor. Some are¨ spares for future use. That completes the material I wanted to cover for this¨ issue. I'm not sure right now what part of the project I¨ will treat next time, but I think it will probably include¨ some of the software. You may have noticed that I have not included detailed¨ schematics of the circuits I have described. There are two¨ reasons for this. First, I do not have the tools to produce¨ publication-quality circuit diagrams with a reasonable¨ effort. Second, these designs are quite old at this point,¨ and, if I were starting on this project today, in most cases¨ I would not use the exact same circuits. Therefore, I am¨ more interested in presenting ideas and concepts and leaving¨ implementation details to the reader. If anyone is¨ interested in pursuing this type of project, I would be¨ delighted to provide more detailed information and¨ discussion. Just contact me in one of the usual ways¨ indicated in the side-bar.