Early digital logic circuits employed relays to perform all of the required functions. A relay is constructed from three very basic components: an electromagnet, a switch, and a spring. But where most switches are activated by pushing a button or throwing a lever, the switch (or switches) in a relay change state when voltage is applied to the coil of the electromagnet. The voltage causes the iron core to become magnetized, which then pulls the metal switch contacts into position. And when the voltage is removed, the spring takes over and pulls the contacts back. Most relays contain at least two switches, though some have as many as four or more, offering a wide range of possible circuit combinations.
Since drawing a realistic picture of an electronic component is not always the most efficient way to convey a circuit, electronic engineers instead use a schematic diagram. Most schematic representations are really pretty close to what an equivalent picture might look like, and a relay is shown both ways for you to compare.
Figure 1 shows the schematic for a single-pole (one switch) double-throw relay. The term double-throw means that one element -- called the common -- will be connected to either of two possible contacts: normally open, or normally closed. That is, when the relay is at rest with no voltage applied to its coil, the common contact is connected to the normally closed contact. And when the relay is activated, the common will be connected to the normally open one instead.
One of the basic logic functions that a relay can perform is called a latch, which is shown in Figure 2. A latch is used to allow a "push to start" type of operation, for example in most microwave ovens. Without it, you'd have to stand there and hold the button for the entire time it's cooking. Sure, you could use a regular toggle switch instead, but then how would the oven be able to turn itself off after five minutes?
Here, a double-pole double-throw relay is needed, since one of the switches is required just to perform the latching function, and the other (not shown) can then do whatever you want. When the pushbutton switch is pressed the coil is energized by the power supply, causing both switches to change state.
Notice, however, that the lower set of contacts is connected in parallel with the pushbutton switch, thereby maintaining power to the coil after the button is released. The relay will stay in this activated state so long as the power source is not interrupted. Incidentally, you could consider this latching action to be a form of positive feedback, since the output is being used to reinforce the input.
Negative feedback can also be applied to a relay's operation, as shown in Figure 3. This oscillator circuit -- commonly known as a buzzer -- is created by wiring the switch contacts in series with the coil. When power is applied the coil will be energized, which causes the switch to change. Of course, the moment this happens power to the coil is interrupted, and the spring pulls the switch contacts back to a normal state. But this activates the coil all over again, and the process continues to repeat indefinitely. I realize this is pretty basic stuff, but then so are most logic circuits.
One of the most primitive logic building blocks is the gate, of which there are several types. Figures 4, 5, and 6 show relay circuits for AND, OR, and EXCLUSIVE OR gates respectively, and we're about to see how these terms came to be applied to programming. Of course, most logic circuits don't use a set of switch contacts for their output, but instead provide either of two possible voltages: the full power supply or nothing. That's why each of these logic circuits are shown with a connection to the supply.
Beginning with the AND gate, if inputs 1 and 2 are powered, then the output will be powered, or One. Otherwise it will be off or Zero. For the OR gate, if input 1 or 2 is high, then the output will be One. All an EXCLUSIVE OR gate cares about is whether the inputs are different, providing a One output when they are. As you can see, a gate can be used to make simple decisions, based on the information at its inputs.
Regardless of which type of gate is being considered, though, its output is always determined by the signals at its input. As you just learned, there are three different categories of gates: the AND gate, the OR gate, and the EXCLUSIVE OR. Inverted versions are also available, called NAND (which means NOT AND), NOR, and EXCLUSIVE NOR.
Where the schematic diagrams we've looked at show precisely how each relay is connected, the logic diagrams in Figure 7 are more appropriate for their solid state equivalents. And though each of the gates is shown with only two inputs, IC (integrated circuit) gates are available with up to eight or more inputs. Under each symbol is a truth table showing what happens at the output for each possible input combination. The inverted gates (NAND, NOR, X-NOR) are shown in Figure 8.
Relay gates employ a mechanical switch, though a solid state gate instead uses transistors. Remember, all transistors use a control voltage on one of the wires, to control the flow of electricity through the other two. Therefore, it is not difficult to simulate the action of a relay electronically.
Like diodes and transistors, an integrated circuit chip is also constructed from silicon and arranged in layers, though it is of course considerably more complex. Internally, an IC contains many individual transistors, diodes, resistors, and capacitors. All of the various components are interconnected when it is manufactured, which takes place in a "clean room" where the workers wear special clothing.
Inverted gates operate in essentially the same manner as the non-inverted types, with the output polarity simply reversed. The little circle on the right in each drawing indicates the inversion, meaning the output will be "not one" when the normal input requirements have been met.
This doesn't require a hobbyist to maintain a separate family of parts, because once you think about it, a positive AND gate is the same as a negative NOR gate, and vice versa. The only real difference between a positive and a negative gate is that the negative ones have an inverter at their output. An inverter is really the simplest circuit of all, and merely converts a "one" to a "zero", and a "zero" to a "one," as shown in Figure 9.
While it may seem difficult to believe, a computer's CPU is created solely from a collection of these gates, though of course many of them are required. Other, simpler circuits can also be derived from logic gates, so we'll continue our discussion with those.