Now you are considering with relays
A while in the past, my eldest son determined to construct a single-bit pc utilizing discrete transistors. The thought of a one-bit machine would possibly sound wacky, however the moniker doesn’t consult with a machine that may solely have two directions or two reminiscence cells. As a substitute, it stands for the “phrase” measurement of the arithmetic logic unit (ALU). Low bit widths lead to easier circuitry, however require operands wider than the {hardware} restrict to be processed in steps. One-bit ALUs are a bit excessive, however they’ve industrial precedent — notably together with the MC14500B microcontroller made by Motorola within the late Seventies.
That stated, right this moment’s publish is about one thing else: as dictated by the iron legal guidelines of sibling rivalry, his youthful brother quickly approached me and requested if I may assist him construct a computing machine that’s much more out of date. After some back-and-forth, we settled on a relay-based calculator. I used to be given additional directions: the PCBs have to be old-school and off-yellow, and all relays have to be see-through.
From the get go, I knew we wouldn’t be constructing a circuit that’s 100% relay-based. Doing so would make the challenge drag on for months — and particularly with these clear relays that retail for $6 a bit, it will value an excessive amount of. Nonetheless, I figured we are able to make use of relays to do the precise math!
Some of the basic constructing blocks of any digital computing machine is the adder circuit. Regardless of its unassuming identify, the circuit can also be ample to additionally implement subtraction, multiplication, and division of integers. A contemporary ALU will usually comprise quite a lot of different arithmetic circuits too, however the adder remains to be a serious star.
The addition of binary digits is conceptually just like working with decimal numbers, besides dumbed down. You may have two inputs with two potential values every; there may be one output digit with the identical property; and there’s a carry bit that may be both propagated to the following column or used to sign an overflow. The habits might be summed up utilizing the next reality desk:
In_A | In_B | Out | Out_C -------+-------+-------+------- 0 | 0 | 0 | 0 0 | 1 | 1 | 0 1 | 0 | 1 | 0 1 | 1 | 0 | 1
That is notionally an arithmetic operation, however a cursory look on the two rightmost columns reveals that it may be carried out utilizing easy Boolean logic:
Out = In_A XOR In_B Out_C = In_A AND In_B
In an digital circuit, when you’ve got a technique to assemble fundamental logic gates, an easy implementation is:
That stated, this circuit (a “half adder”) is incomplete within the sense that it doesn’t have a technique to take carry from the previous column under consideration; in different phrases, it might probably’t mechanically add multi-bit integers.
To construct an entire (“full”) adder, we have to take a considerably extra sophisticated strategy with a 3rd enter line:
In_A | In_B | In_C | Out | Out_C -------+-------+-------+-------+------- 0 | 0 | 0 | 0 | 0 0 | 1 | 0 | 1 | 0 1 | 0 | 0 | 1 | 0 1 | 1 | 0 | 0 | 1 | | | | 0 | 0 | 1 | 1 | 0 0 | 1 | 1 | 0 | 1 1 | 0 | 1 | 0 | 1 1 | 1 | 1 | 1 | 1
The primary half (In_C = 0) is identical as for a half adder. The second half differs. The equal Boolean algebra is much less elegant, however nonetheless straightforward to reverse engineer:
Out = (In_A XOR In_B) XOR In_C Out_C = (In_A AND In_B) OR (In_C AND (In_A OR In_B))
The digital implementation might be realized by following this components, or alternately, imagined as two half adders chained collectively, plus an OR operation utilized to their carry outputs:
A full adder might be arbitrarily stacked so as to add any variety of binary digits in a single cycle; or it may be used serially as part of a 1-bit ALU, just like my eldest son’s design talked about earlier on.
Relays have two properties that make them well-suited for constructing digital logic: they’re inherently binary of their operation, and so they can “amplify” enter alerts to be able to chain the units indefinitely. (To be honest, the units even have a lot of disadvantages: they’re sluggish, expensive, loud, and their contacts are susceptible to put on.)
There are numerous methods to implement relay-based logic, partially due to the number of relays available on the market and all of the other ways of encoding zeroes and ones. For instance, Konrad Zuse’s Z3 pc relied on unique four-pole double-throw (4PDT) units and “cheated” by additionally propagating a secondary, inverted carry sign — however the design pulled off a full adder with just two relays!
For my challenge, utilizing the bottom potential variety of relays wasn’t a very interesting objective. As a substitute, I needed to stay to commodity elements and preserve the structure clear. I additionally had the aforementioned requirement for relays with see-through housings.
After some analysis, I settled on a collection of compact G6C relays from Omron. The units can be found with a single SPST-NO change, or with a complementary pair of SPST-NO and SPST-NC terminals. Right here’s the SPST-NO design I used for the OR gate:
The operation of this circuit must be apparent: the output is related to the constructive provide rail if both of the relays is on. In any other case, the output floats.
One may additionally implement an OR gate with a single SPDT relay, though the pass-through structure for one of many inputs signifies that “fanout” (downstream loading of the output) have to be saved in examine:
An AND gate might be constructed equally, with one or two SPST-NO relays:
The development of an XOR gate is a little more concerned, usually benefiting from double-throw relays. Right here’s the answer I carried out with Omron’s complementary SPST-NO + SPST-NC topology:
The SPST-NO terminals carry out an OR operation, connecting the output to a standard rail (backside) when any of the relays is on. The SPST-NC aspect performs NAND, disconnecting that rail from the constructive provide when each relays are energized.
A extra compact model of primarily the identical structure might be drawn with SPDT relays, as proven under:
In the long run, I used twelve relays for essentially the most easy implementation of the six Boolean operations wanted to implement a full adder:
Out = (In_A XOR In_B) XOR In_C Out_C = (In_A AND In_B) OR (In_C AND (In_A OR In_B))
Right here’s the close-up of the adder part on the PCB. Word the “retro” curved traces and the deliberate absence of a solder masks:
Getting this structure performed in KiCad was a completely depressing expertise. I had some prolonged back-and-forth with the PCB producer too.
Nope, a minimum of not for now! All the “most important” board is proven under, full with keypad stickers, an old-school change, a uncommon radial electrolytic cap — and sure, an 8-bit microcontroller:
The microcontroller is there to care for quite a lot of auxiliary duties that might require a whole lot of further relays. This contains keypad scanning, digit decoding, operation sequencing, error dealing with, and reminiscence. That stated, the adder has a clearly-delineated position and is there to carry out precise math.
Right here’s the sequence of MCU operations for addition:
-
Set operand bit pointer to 0 (LSB),
-
Initialize the adder “carry in” line to zero,
-
Push operand bits onto the adder enter traces,
-
Wait round 20 ms for the relays to settle,
-
Learn again and retailer the adder output bit,
-
Propagate “perform” to “carry in”,
-
Advance the operand bit pointer to the correct,
-
Loop again to #3 till out of bits so as to add.
In different phrases, there isn’t a dishonest, though the MCU may in precept do the ALU work by itself.
After all, it’s not simply addition; different arithmetic operations might be performed with the identical circuitry. For instance, multiplication might be unwound right into a collection of progressive additions of bit-shifted values, considerably akin to a dumbed-down model of how we do “lengthy multiplication” by hand:
110 × 1011 = ? ↓ ↓ 110 × 1 → 110 110 × 1 → 110 110 × 0 → 000 110 × 1 → 110 ------- sum = 1000010
This bit shifting might be performed with an adder if one is so inclined; every left shift is equal to including the operand to itself (i.e., multiplying it by 2).
Subtraction is equally straightforward: it may be carried out the addition of two’s complement (which in flip might be computed by abusing the adder to function as a NOT gate.) And with subtraction performed, division can also be inside attain.
That’s the place I went a bit nuts and constructed a Rube Goldberg-esque machine only for the sake of it. The PCB accommodates a few 7-segment shows, however they’re pushed fully by relays:
To maintain the variety of knowledge traces in examine, show state is saved in 8-bit latches (six 74HC259 chips on the backside), so the relays are largely superfluous — however the concept was to make the getting into digits as satisfying as watching the ALU at work.
I’ll document an entire demo as soon as I end programming the MCU and construct an enclosure. Within the meantime, right here’s a fast video of a useful take a look at of the show module:
And right here’s a lower-quality (however audio-visually mesmerizing!) mobile phone video displaying the multiplication of 111 by 222:
It relies upon. If we accept primitive inputs and outputs — say, columns of fixed-position switches and indicators — then addition and subtraction might be performed in a single step with an adder circuit of a ample width. The whole variety of relays can be a low a number of of the variety of enter bits.
The image will get extra sophisticated if we need to implement multiplication and division. These operations are most virtually carried out as a collection of steps. You’d want a clock, a “microcode sequencer”, and an array of multiplexers that flexibly join registers to carry out hundreds, shops, and ALU operations.
Much more complexity arises if we need to help modern-style enter, with digits typed in left-to-right. As a result of the operands should be right-aligned throughout calculation, and the variety of digits to be entered isn’t identified beforehand, extra circuitry can be wanted to implement the required shifts.
In the long run, exact estimates are onerous, however extrapolating from early transistor calculators akin to Friden EC-130, I’d wager that round 500 relays can be wanted for the duty.
At $6 a bit, the relays I’m utilizing on this challenge wouldn’t be a clever alternative; that stated, subminiature sign relays, akin to Kemet EA2-5NU, would lead to a closing price ticket of underneath $1,000 — and in an affordable desk footprint, too.
Energy shouldn’t be a serious concern — we’re speaking tens of watts — however efficiency is a limiting issue. For subminiature relays, 200 Hz might be the higher restrict. For bigger relays, 50 Hz is lots.
As soon as I’ve this “introductory” challenge wrapped up, I could be tempted to present a 100% relay-based calculator a attempt…
For a categorized record of my different articles on electronics, click here.