Relay-based Logic 07/30/01 Jeff Connelly from /usr/home/jeff/mnt/ad4s2d/jeff/xmax/e/logic/relay_logic.txt Electromechanical or solid-state relays are an easy way to have a small current switch on large current, and they also can be used as logic gates. COIL+ ----) o-------- NC ) \ ) o------ COM ) COIL- ----) o-------- NO When there is a significant potential difference between COIL+ and COIL- (hereinafter refered to as Vcoil), no matter what polarity, the coil will function as an electromagnet and short COM to NO, leaving NC floating. Normally NC (normally closed) is shorted to COM. NC = COM, NO = floating when Vcoil != 0 NC = floating, NO = COM when Vcoil != 0 Logic Levels ============ There are two logic levels in relay logic, one for input and another for output. Input Logic Levels: For the Coil -------------------------------- Inputs drive a coil. For each bit of input, there are two leads. The potential difference between the two leads determines the logic level at which the bit is at. In this document input A is the voltage between arbitrarly-designated A+ and A-. Usually coil polarity does not matter. Potential Difference Between A+ and A- Logic Level Little or no voltage 0 Enough voltage to drive coil 1 (voltage depends on coil) Output Logic Levels: Between the Contacts ----------------------------------------- Outputs are what you get out of a logic gate. Unlike most logic families such as Transistor-Transistor Logic or Diode Logic, output levels are not represented by voltage, but resistance between two leads. Continuity Between A- and A+ Logic Level Open circuit 0 Short circuit (no opens) 1 Voltage is usually put across the output contacts, but that is irrelivant to the logic gate's function. Relays however do have ratings which dictate the maximum current and voltage across the contacts. Coupling Relays --------------- Coupling one coil to another is no problem assuming the coils are the correct voltage. Contacts can be coupled together directly also. Coupling outputs to inputs requires a voltage source somewhere in the circuit which is at least that of the coil's voltage level. Gates ===== BUFFER/NOT Gate --------------- The PASS or BUFFER gate is the opposite of a NOT gate - when the input is high, the output is high. Useful for switching large current with small current, or converting an input logic level to output logic level. PASS gates also contain a NOT gate if the relay has an NC contact. ^ A+ ----) o-------- Q+ | ) \ -- Q- A ) o----+ | ) -- Y- v A- ----) o-------- Y+ | GND Inputs: A = A+..A- Outputs: Q = Q+..Q- = A' Y = Y+..Y- = A BUFFER config: -COM-NO NOT config: -COM-NC AND Gate (0001) -------- The AND gate is easy to implement because relays switch resistance, not (directly) current. Because of this, multiple relays can be combined and the resulting circuit of the relay's contacts will allow current to pass or not. In fact that's how all the gates here work. A+ ----) o------ -------o (---- B+ ) \ / ( ) o----- Q+ Q- ----o ( ) ( A- ----) o---------------------o (---- B- Inputs: A = A+..A- B = B+..B- Outputs: Q = Q+..Q- = A and B Config: 010-COM1-COM2 a AND (NOT b) (0010) ------------- Function #0010 is usually implemented with an AND gate, with a NOT on the second input. However, with relays we can implement the #0010 function with two relays instead of three: A+ ----) o------ Q+ -------o (---- B+ ) \ / ( ) o-----------------o ( ) ( A- ----) o------ Q- ------o (---- B- Inputs: A = A+..A- B = B+..B- Outputs: Q = Q+..Q- = A and (not B) Config: 010-NC2 -NO1 (NOT a) AND b (0100) -------------------- The BA' gate is similar to the AB' one except input A is inverted. As with AB', only two relays are needed: A+ ----) o------ Q+ -------o (---- B+ ) \ / ( ) o-----------------o ( ) ( A- ----) o------ Q- ------o (---- B- Notice the similarity to AB'. Inputs: A = A+..A- B = B+..B- Outputs: Q = Q+..Q- = (not B) and A Config: 010-NC1-NO2 NAND Gate (1110) --------- Output is 0 if both inputs are 1, else output is 1. Q+ Q- | | A+ ----) o-------+-------------o (---- B+ ) \ | / ( ) o----------+------o ( ) ( A- ----) o-------- --------o (---- B- Inputs: A = A+..A- B = B+..B- Outputs: Q = Q+..Q- = A nand B 110-NC -COM OR Gate (0111) ------- With an OR gate we provide two parallel channels for the resistance to occur through. 0 if both inputs 0, else 1. A+ ----) o------ Q+ -------o (---- B+ ) \ | / ( ) o--------+--------o ( ) ( A- ----) o----------+----------o (---- B- | Q- Inputs: A = A+..A- B = B+..B- Outputs: Q = Q+..Q- = A or B Config: 011-COM-NO NOR Gate (1000) -------- Activating any coil, or both, breaks the circuit. With no input output is 0. Note that the NOR gate is based on AND, but with NC contacts tied together instead of NO. NOR is function 1000 while AND is 0001 (binary). A+ ----) o---------------------o (---- B+ ) \ / ( ) o----- Q+ Q- ----o ( ) ( A- ----) o-------- ---------o (---- B- Inputs: A = A+..A- B = B+..B- Outputs: Q = Q+..Q- = A nor B Config: 010-NC1-NC2 XOR Gate (0110) -------- Yes, even an XOR gate can be constructed using merely two relays. The contacts interconnections are similar to those found in house wiring where two switches control one light. Output is 1 only if inputs differ. A+ ----) o---------\ /-------o (---- B+ ) \ \ / / ( ) o----- Q+ \Q- ----o ( ) / \ ( A- ----) o---------/ \-------o (---- B- or: Q+ | A+ ----) o----------+----------o (---- B+ ) \ / ( ) o-----------------o ( ) ( A- ----) o----------+----------o (---- B- | Q- Inputs: A = A+..A- B = B+..B- Outputs: Q = Q+..Q- = A xor B Config: 111-NC-NO XNOR Gate (1001) --------- Inverse of XOR gate. Output is 1 if inputs are equal, else 0. A+ ----) o---------------------o (---- B+ ) \ / ( ) o----- Q+ Q- ----o ( ) ( A- ----) o---------------------o (---- B- Inputs: A = A+..A- B = B+..B- Outputs: Q = Q+..Q- = A xnor B Config: 101-COM1-COM2 The Mathematics Behind Dual-Relay Gates ======================================= A two-relay circuit consists of two switches, each which can have two states: COM1 <-> NC1 when A=0 COM1 <-> NO1 when A=1 COM2 <-> NC2 when B=0 COM2 <-> NO2 when B=1 Therefore: AB Link relayA Link relayB 00 COM1<->NC1 COM2<->NC2 01 COM1<->NC1 COM2<->NO2 10 COM1<->NO1 COM2<->NC2 11 COM1<->NO1 COM2<->NO2 Given which wires are connected to each other relay and the Q+ and Q- points, we can find out which circuits and inputs give 0 by tracing the circuit to see if it's complete. Simplified dual-relay circuit: NC1 ------- x -------- NC2 A COM1 ------- y -------- COM2 B NO1 ------- z -------- NO2 x, y, and z are fusable links. When the following links are wires, then: x NC1<->NC2 = NC y COM1<->COM2 = COM (names are then shortened) z NO1<->NO2 = NO Let's take gate 001-COM1-COM2. "001" signifies xyz, so z is 1, so: NO1<->NO2 That's all we have to go by. Now make a list of links and simplify the circuit: AB Starting Given(xyz) Relay definition Ending 00 Q+<->COM1 NO1<->NO2 COM1<->NC1 COM2<->NC2 COM2<->Q- 01 Q+<->COM1 NO1<->NO2 COM1<->NC1 COM2<->NO2 COM2<->Q- 10 Q+<->COM1 NO1<->NO2 COM1<->NO1 COM2<->NC2 COM2<->Q- 11 Q+<->COM1 NO1<->NO2 COM1<->NO1 COM2<->NO2 COM2<->Q- AB Circuit with combined like terms linked together 00 Q+<->COM1<->NC1 NO1<->NO2 COM2<->Q- 0 01 Q+<->COM1<->NO1<->NO2 COM2<->Q 0 10 Q+<->COM1<-> NO1<->NO2 COM2<->NCC2->Q- 0 11 Q+<->COM1<->NO1<->NO2<->COM2<->Q- 1, closed! So the function number is 0001, the AND gate. Of course, there are many more configurations that make an AND gate. Dual-relay circuits are kinda like PLAs. >2-Input Gates -------------- If more inputs are desired, more relays can be used. Four-input AND gate: A+ ----) o------ -------o (---- B+ ) \ / ( ) o-----------------o ( ) ( A- ----) o-----+ +------o (---- B- | | C- ----) o-----+ +------o (---- D- ) ( ) o----- Q+ Q- ----o ( ) / \ ( C+ ----) o------ -------o (---- D+ Notice how the with the second relay, the NO contacts are facing up, while with the first they are facing downward. Also notice how the first AND gate's Q+ and Q- where connected together to make a complete circuit. However not all gates can be connected this way. All The Possible Relay-Logic Gates ================================== In the chart below the "leads" field says how the contact leads of one relay connects to the cooresponding leads to another. 0 means no connection, 1 means connected directly. Bits in order are: NC, COM, NO. Cross-connections cannot be represented here. After the dash the Q+ and Q- points are listed. For example 001-COM-COM means Q+ is COM on relay 1, Q- is COM on relay 2, NC and COM on both relays are not interconnected, but both NO's are. Truth Table Reference AB Q 00 a 01 b abcd=function number 10 c 11 d Functions marked with "+" can be simplified. See top of file for buffer and not gate. Clear and mark only require non-connecting or connecting leads, no relay. One goal with making this list is to find a set of configurations where all the useful functions are represented, and where all configurations in the set have either: a) the same through-wire configuration b) the same Q+ Q- config. The reason for this is to minimize the number of changes required to make all gates from a single configuration. Leads/Terminals Function Composition (when A=0,when A=1, then Q=?B) 001-NC1 -NC2 0000 - clear clear, clear 001-NC1 -COM1 1100 - NOT b mark , clear 001-NC2 -COM2 0101 - NOT a mark , clear 001-NC1 -NO 0000 - clear clear, clear 001-COM1-NC2 0000 - clear clear, clear 001-COM1-NO 0011 - pass A clear, mark 001-COM1-COM2 0001 - AND clear, pass - AND - 010-NC1 -NC2 1000 - NOR not , clear 010-NC1 -NO1 0011 - pass A clear, mark 010-NC1 -NO2 0000 - clear clear, clear 010-NC2 -NO1 0010 - AB' clear, not 010-COM -NO1 0011 - pass A clear, mark 010-COM1-COM2 0001 - AND clear, pass 010-NO1 -NO2 0001 - AND clear, pass - AND, NOR, AB' - 011-NC1 -NC2 1001 - XNOR not , pass 011-NC1 -NO 0100 - BA' pass , cleaer 011-NC2 -NO 0010 - AB' clear, not 011-COM -NO 0111 - OR pass , mark 011-COM -NC1 1100 - NOT a mark , clear 011-COM -NC2 0101 - NOT b not , not - XNOR, BA', AB', OR - 100-NC -COM1 1100 - NOT a mark , clear 100-NC -COM2 1010 - NOT b not , not 100-COM1-COM2 1000 - NOR not , clear 100-COM1-NO1 0011 - pass A clear, mark 100-COM1-NO2 0000 - clear clear, clear 100-COM2-NO2 0101 - pass B pass , pass - NOR - If wires=x0x, a NCx-NCx connection will always make a 0000 clear gate. 101-NC -COM1 1100 - NOT a mark , clear 101-NC -COM2 1010 - NOT b not , not 101-NO -COM1 1100 - NOT a mark , clear 101-COM1-COM2 1001 - XNOR pass , mark 101-COM1-NO 0011 - pass A clear, mark 101-COM2-NO 1010 - NOT b not , not - XNOR - 110-NC -NO1 0010 - AB' clear, not 110-NC -NO2 0100 - BA' pass , clear 110-NC -COM 1110 - NAND mark , not 110-NO1 -NO2 0001 - AND clear, pass 110-COM -NO1 0010 - AB' clear, not 110-COM -NO2 0100 - BA' pass , not 110-COM -NC 1110 - NAND mark , not - AB', BA', NAND, AND - 111-NC -NO 0110 - XOR pass , not 111-NC -COM 1110 - NAND mark , not 111-COM -NO 0111 - OR pass , mark - XOR, NAND, OR - NC1 A+ ----) o-------- -------o (---- B+ NC2 ) \ / ( COM1 ) o------ -----o ( COM2 ) ( NO1 A- ----) o---------------------o (---- B- NO2 NC1 A+ ----) o-------- --------o (---- B+ NC2 ) \ / ( COM1 ) o------ ------o ( COM2 ) ( NO1 A- ----) o-------- X--------o (---- B- NO2 Functions and their connections, most optimal: Function Leads/Terminals 0000+clear Q+, Q- 0001 AND 010-COM1-COM2 0010 AB' 010-NC2 -NO1 0011+pass A -COM-NO 0100 BA' 010-NC1 -NO2 0101+pass B -COM-NO 0110 XOR 111-NC -NO 0111 OR 011-COM -NO 1000 NOR 010-NC1 -NC2 1001 XNOR 101-COM1-COM2 1010+not B -COM-NC 1011 B+A' 1100+not A -COM-NC 1101 A+B' 1110 NAND 110-NC -COM 1111+mark Q+-Q- COMPLETE LISTING Function 0R 1R 2R:001 010 011 100 101 110 111 0000 clear Q+,Q- N/A 0001 AND COM1-COM2 COM1-COM2 NO1 -NO2 0010 AB' NC2 -NO1 0011 pass A COM-NO COM1-NO NC1 -NO COM -NO1 0100 BA' 0101 pass B COM-NO NC2 -COM2 0110 XOR 0111 OR 1000 NOR NC1 -NC2 1001 XNOR 1010 not B COM-NC 1011 B+A' 1100 not A COM-NC NC1 -COM1 1101 A+B' 1110 NAND 1111 mark Q+-Q- FOR COMPLETE TABLE SEE RLOGIC.HTML (html tables are just easier to make)