0%
0%

# Simple Relay ALU

Only 2 relays and a few diodes, but 10 functions including ADD and Shift Right. Simplest relay ALU ever designed ?

Similar projects worth following
1.7k views
Experiments were done with a design that has both input signals (A and B) connected to a single relay coil, so the relay will be active when both inputs have a different logic level. The result is a fully functional ALU, with only 2 DPDT relays (or 3 SPDT relays) and a few diodes.

INTRODUCTION

An ALU (Arithmetic Logic Unit) is an electronic circuit that performs arithmetic and bitwise operations on binary numbers (see Wikipedia: ALU).

This project describes three different ALU's that work with relays.

After simplyfing one of the Relay ALU designs of Dieter Mueller (see HERE), I experimented with a design that has both input signals (A and B) connected to a single relay coil, so the relay will be active when both inputs have a different logic level.

This has been done before, but for an ADD function only (like the 1-bit Relay Full-Adder described by John Stanley).

When I entered this project here at Hackaday, this ALU design had 5 functions. I described the operation of the circuit comprehensively in two logs.

Now that I changed the design to have 10 functions, I don't want to change all those descriptions. So the 5-function design is first explained below and in the first two logs. The third log ( found HERE ) explains the new 10-function design.

The fourth log describes another relay-based ALU design, this time without diodes.

FIRST DESIGN

The ALU can ADD, and can perform the basic logic operations. The operation is selected by the four inputs F0-F3 (that are in common for every bit):

The picture shows a single bit of the ALU. Several of these circuits can be chained together to form an ALU that operates on 4 or 8 bits (or any other number of bits).

GREEN wires show the A and B input signals.

DARK BLUE wires show the carry path.

ORANGE wires show the control inputs.

- Relay RL1 needs a flyback protection diode, see Flyback diode.

- Relay RL2 be must not be sensitive to the signal polarity. If the relay is polarity dependent, you could use a bridge rectifier (see picture below). The bridge will also act as flyback protection diode.

- If you do not use a bridge rectifier for RL2, you can not use a simple flyback diode because both polarities can be present. Easiest solution would be to mount a resistor in parallel to the coil, with the same resistance as the relay coil. This will limit the generated reverse voltage (but will also increase power consumption when the relay is ON).

- Using DC, 12 Volt is recommended.

- The inputs to the circuit must be 12 volts for a "1" (but F2 may be left floating for a "1")

- The inputs A, B and F2 must be connected to ground for a "0". The other inputs may be left floating for "0".

- In the function table, "X" means that the input may be either 0 or 1.

CARRY DELAY

The design has practically zero carry ripple delay, so the addition speed is independent from the bit-width of the numbers that are added. It shares this property with the famous Zuse Adder, described at this page of the Hamburg university and in this Relay-Computer-Two article.

OPERATION

The operation of the circuit will be discussed in detail in the logs. The first log will describe the ADD function, and the second one wil describe the logic functions.

SIMULATION

The design was successfully simulated in the Falstad simulator. In the Falstad File menu, select "Import from text" and paste the contents of the simulation file (available in the files section), to do the simulation yourself. The simulator shows the current that flows through the wires, and you can see the relay contacts switch !

### ALU_simulation.txt

Use this file in the Falstad simulator to simulate the 5-function ALU.

plain - 6.41 kB - 11/08/2018 at 12:44

• ### If you don't have any Dollars ?

If you don't have dollars (Sorry I mean diodes), and you don't want two different current directions in your A and B inputs... What would be an easy ALU circuit ?

The above circuit will do all possible logic functions, and will also ADD.

The controls are a lot like that of the 4-bit TTL ALU, as described in ITS FIRST Log. It also operates in much the same way.

If F4 has no power, then none of the RL3 relays will attract. In this case, the four inputs F0 - F3 determine which of the 16 possible logic functions is executed. Of course, the CY-IN of the first circuit must also not be activated.

For addition, F4 must be powered and the XOR must be selected as operation (F2 and F1 powered). Note that there is no built-up of carry delays.

If you also want a shift-right for your one-byte ALU, then add two 4-pole relays to select the normal ALU result or a shifted version of it.

Note that the upper contact of RL1 has been mirrored in the drawing, to make it easier for you to follow the current flow. Also note that the ground connection of the relays is not shown.

• ### 10 functions now, for a few diodes more...

roelh11/09/2018 at 15:51 1 comment

Yesterday I entered this project on Hackaday. But thinking never stops. I tried to find a use for the fourth contact on my 2 DPDT relays, but ended up with a similar 3 SPDT solution (good news for Yann), with 5 more functions.

The key is the bridge rectifier for the relay RL2. Two new control signals F4 and F5 can now control RL2, together with the two inputs:

With F4=1 and F5=0, RL2 attracts if A and B are different, just as before.

Now make F4=0. RL2 now always has ground, so will attract if either A or B is high, providing the OR function.

Now consider making F4=1 again, and make F5=0. RL2 now always has 12 volts, so it will attract if either A or B is low, providing a NAND function.

RL1 can still be controlled with the F2 and F3 signals. It controls the polarity of the output signal, so when RL1 is attracted it will transform XOR to XNOR, NAND to AND and OR to NOR.

If we now make F5=1 and F4=0, RL2 will always be attracted. This gives an always-zero (CLR) at the output when RL1 is OFF, and always-one (SET) if RL1 is ON.

In this final situation,  the voltage for the always-on comes from control F1. If we now make F1 low, this voltage is controlled by the SHR-IN input, that is connected to input A of the next bit. So it will give us the Shift-Right function (SHR). A 74181 can't do that ! Note that a Shift-left is already available because it is the same as adding a number to itself.

Only SUB and PassThrough functions are missing. A PassThrough function can be made by clearing the other operand and doing ADD or OR. Subtract might be done by doing a negate function first (XNOR with zero), or inverting the A or B signal in a previous circuit (as in the RISC Relay CPU).

• ### Description of the logic functions

For the logic functions, a Carry-out is generated just as for the ADD function. But the carry input is ignored because the relay RL1 is forced to an active or non-active state by inputs F2 and F3, so it is no problem that there might be a signal present on the Carry-out of the previous stage.

The simplest function to explain here is XOR:

The control input F2 must be logic 1 (or floating). This ensures that RL1 is always off. If A differs from B, relay RL2 will connect  the ALU-Result to the logic 1 provided by control F1. Otherwise, the result is not connected (meaning logic 0). The XOR function will be selected if either F0 or F1, or both are "1".

The next one is the XNOR function:

By making control input F3 active and F2 ground, relay RL1 will be always ON. Now, the ALU-result will be logic 1 when both inputs are equal, providing the XNOR function.

Now to describe the AND function:

The only difference with the previous (XNOR) situation is, that control F1 is now 0. The result is, that the signal on input B now flow through a diode to connection 1 of relay RL2. The ALU result will only be one if RL2 is OFF (so both inputs equal) and input B is 1. So, it is only one if both A and B are 1.

The last function is OR:

The only difference with AND is, that control F0 is now active. This causes an active ALU-result when A and B are different. When A and B are the same, the result is 1 if B is 1 (as in AND). Together, this delivers the OR function.

( The AND-gate, OR-gate pictures were taken from R. Lohberg and Th. Lutz: Hoe werkt een computer?, Kluwer (Netherlands) 1968. )

• ### Description of the ADD function

As a reminder, the ADD function has to produce two output signals according to the following table:

The next diagram illustrates how the CY_OUT signal is generated:

Only relay RL2 is involved for CY-OUT generation. RL2 is activated when the signals A and B are different (indicated in green in the function table).

When RL2 is activated, the Carry-output is the same as the Carry-input.

When RL2 is not activated, the Carry-output is the same as input B (indicated in yellow in the function table). It could also be connected to the A input, since A and B are equal when RL2 is not activated.

For the result output, I use two pictures, one for [Carry-in = 0]  and one for [Carry-in = 1].

Relay RL1 is connected to the Carry-in signal, so it is not attracted when Carry-in is 0. Input F1 provides logic 1 to connection 2 of RL2. Relay RL2 attracts when A differs from B, so the result is (A xor B) according to the table.

When the Carry-in is 1, RL1 is always attracted. This time, input F1 provides logic 1 to connection 1 of RL2. So the output is only logic 1 when both inputs A and B are equal.

Share

## Discussions

Stefano wrote 09/22/2019 at 10:27 point

Ciao Roelh! Your ALU designs are really genius!!
I'm preparing myself to build a relay computer, and I was wondering if you could have some nice alternative that might use 4PDTs (I've bought ALL of this type since price for the type I bought was almost the same and to minimize their quantity in general where possible). If possible would be nice also at least one of the two inputs +12V/disconnected instead of +12V/0V (this in order not to add 8 more relays since one of the values is coming from a punched card reader that would make contact or not, while the other is coming from a register).... The basic functions I'm interested ar "just" ADD, AND, SHR (for the rest I think I can manage with very limited calculations).

Are you sure? yes | no

roelh wrote 09/22/2019 at 20:11 point

I did send you a PM

Are you sure? yes | no

Stefano wrote 09/26/2019 at 05:09 point

12 4PDT relays for ADD, AND, OR, SHR; 16 for the same 10 functions.

Missing still the "at least one input disconnected" nice to have requirement, but nice to have using no diodes (even if I consider they ok to be used since they were invented in the very early 1900).
Sorry for the quality of schemas (I've just the mobile phone with me now) but hope they are understandable.

Are you sure? yes | no

Starhawk wrote 11/09/2018 at 18:50 point

You might look up one Harry Porter, who, unlike a similarly-named fellow, really exists and works his 'magic' with relay circuits. This (copied elsewhere) is his version of your logic block -- https://relaycomputer.co.uk/assets/img/posts/2013/2013-11-11-0000.png

...look, Ma, no diodes! I've always considered any semiconductors present in a relay logic circuit to be a form of cheating. If you absolutely must use some sort of diode outside of power circuitry, you're probably doing it wrong -- at the very least, there's another solution somewhere that can avoid them. Call me a purist, but I don't even like the idea of LEDs for indication -- whatever happened to grain o' wheat bulbs? or Christmas Tree lights...? or... there are plenty of incandescent solutions to that problem.

Are you sure? yes | no

roelh wrote 11/09/2018 at 19:55 point

Hi Starhawk,

my motivation of using diodes is that relay-computer builders need a lot of relays, that together might be difficult to afford for some of them. Diodes are really a lot cheaper, and can replace relays in some situations. Diodes are also simple to understand, unlike transistors or IC's. Whether you want to use diodes is your own choice, of course.

A "textbook" ALU performs 3 functions:

- produce several logic results

- produce the sum (sometimes also the difference)

- choose one of the logic results or the sum as output

The logic block that you mention only produces logic results and uses 7 relay contacts. It can not ADD and does not choose one of the results as output.

My circuit does all this (except difference) with only 3 relay contacts.

I found the computer of Harry Porter too big and too slow, that's why I am working on my own relay computer: https://hackaday.io/project/11012-risc-relay-cpu

If you want a simple ALU without diodes, let me know, and perhaps I can make a nice design for you.

Are you sure? yes | no

Starhawk wrote 11/09/2018 at 19:59 point

Harry Porter found the two-relay adder circuit invented by Konrad Zuse waaaay back when to be more than sufficient for his needs in regards to that -- as for output selection, a simple relay multiplexer/demultiplexer is not a challenge, either -- three to eight or eight to three (depending on your signal direction) takes all of three relays.

Are you sure? yes | no

roelh wrote 11/09/2018 at 20:05 point

The Zuse adder uses 8 contacts, choosing one out of 6 results will take 5 contacts, together with the 7 from the logic block this are 20 contacts.

If you use a lot of relays, then it's no challenge, indeed.

Are you sure? yes | no

roelh wrote 11/09/2018 at 20:33 point

I almost forgot that I already have a quite simple ALU with only 4 relays (6 contacts) and a single diode. The diode can be replaced by a relay contact. It can also subtract ! You find it here: https://hackaday.io/project/160506-4-bit-ttl-alu/log/155600-a-relay-alu

Are you sure? yes | no

rafununu wrote 11/15/2018 at 15:09 point

Diodes are needed inverted and parallel to the coils, that's it. As diodes aren't perfect, they can't be used in logic without a level shifter to compensate their threshold.

Are you sure? yes | no

Ted Yapo wrote 11/08/2018 at 13:43 point

Nice project. I'd like to take something like this and add it to my PC as a co-processor so I could write simple programs that used the relays for all the ALU functions while keeping the RAM, etc on the PC.

Are you sure? yes | no

roelh wrote 11/08/2018 at 13:50 point

I thought co-processors were used because they could calculate faster than the main CPU...

Are you sure? yes | no

Ted Yapo wrote 11/08/2018 at 14:01 point

Yes, yes, keep thinking inside the box :P

Are you sure? yes | no

Yann Guidon / YGDES wrote 11/09/2018 at 01:40 point

Bwhahahahahah !
@Ted Yapo  what box ? ;-)

Are you sure? yes | no

rafununu wrote 11/15/2018 at 15:07 point

The best co-proc is the chinese abacus ! You can control balls with actuators, with a strong power supply you'll be able to drive a 16bits unit.

Are you sure? yes | no

K.C. Lee wrote 11/15/2018 at 17:11 point

Abacus uses BCD math, so even a 10 column one is already 32-bit capable.

Are you sure? yes | no

Ted Yapo wrote 11/15/2018 at 17:21 point

A Chinese-style abacus has two five-beads per rod, so can represent up to 15 on each - meaning, you can do hexadecimal on it.  I have one hanging on my wall just in case.

Are you sure? yes | no

K.C. Lee wrote 11/15/2018 at 19:06 point

It is more like a scratch pad, so it is up to the human ALU.  You can even split up the columns to do SIMD packed math.

Are you sure? yes | no

Ted Yapo wrote 11/16/2018 at 17:26 point

You know someone is going to make an automatic abacus based on this discussion.  I am fearful that it will be me.

Are you sure? yes | no

rafununu wrote 11/08/2018 at 12:49 point

So, what's the goal ? such ALU's are known for decades.

Are you sure? yes | no

roelh wrote 11/08/2018 at 12:50 point

I am not aware that such a simple ALU design does exist. Please show me a reference !

Are you sure? yes | no

rafununu wrote 11/09/2018 at 15:28 point

I can't, it was long before Internet became popular ! We used such systems in electromechanical racks to control machines. Of course as soon as we could have transistors, they were largely implemented to replace logic made by relays. Next came ICs.

Are you sure? yes | no

Yann Guidon / YGDES wrote 12/09/2018 at 11:35 point

still, I'm very interested to find original old references :-)

part of the thrill of reinventing the wheel is to know how far we are from the old designs :-P

Are you sure? yes | no

## Similar Projects

Project Owner Contributor

### SPDT16: 16-bits arithmetic unit with relays

Yann Guidon / YGDES

Project Owner Contributor

### Super Micro Relay Computer

Stefano

Project Owner Contributor

### AMBAP: A Modest Bitslice Architecture Proposal

Yann Guidon / YGDES

Project Owner Contributor

roelh

# Does this project spark your interest?

Become a member to follow this project and never miss any updates