4 Bit calculator with Relays - Page 1
Forum section: electronics / projects

author: echen1024
author_rank: Super Contributor
timestamp: August 04, 2013, 03:44:12 am
content: I have been thinking to build a full 4 function calculator with memory out of nothing but relays for the logic. I want to know how feasible this is and the estimated number of parts needed to build. A simple schematic would be nice as well. I sort of miss the clacking relays used to control logic and have decided to control my nostalgia with this project.

author: IanB
author_rank: Super Contributor
timestamp: August 04, 2013, 04:30:21 am
content: About 500 relays will get you a stored program computer, so a 4 function calculator should be achievable with somewhat fewer relays than that:

author: Psi
author_rank: Super Contributor
timestamp: August 04, 2013, 07:43:01 am
content: Quick and dirty math for a 8 bit full adder.2 relays = 1 nand gate9 nand gates per full adder9*8*2 = 144 relaysYou can probably make it with less, since you can build more than just nand from relays.Edit,yep, you only need 9 relays to make a full adder.Found this using google image search. So an 8 bit adder would need 72 relays assuming this diagram actually works.

author: IanB
author_rank: Super Contributor
timestamp: August 04, 2013, 08:09:33 am
content: That seems like a lot of relays. Surely it can be simplified? For example, here is a 6 bit adder done with hinged wooden gates and marbles. There is one latch per bit and some extra gates for the input register and the result register:I wonder how many (or few) parts you would need to construct an electrical analog of this...?

author: Rerouter
author_rank: Super Contributor
timestamp: August 04, 2013, 09:17:26 am
content: i just spent 20 odd minute trying to work it out, there is a way, just i could not manage to nut out the bloody reset for next bit,you have a latching relay for your register, a selector relay driven by the latch that determines whether the input goes to register or reset/increment, then i got stuck....edit:as-long as the input is monostable, this works as far as that marble one worked, (4 relays per bit Booyah!)http://tinyurl.com/psfksc8edit2:had to clean it up to remove an error condition, drag up the simulation speed to see it (needed to show from starting condition)http://tinyurl.com/pndnzoa

author: SeanB
author_rank: Super Contributor
timestamp: August 04, 2013, 09:37:32 am
content: Quote from: Psi on August 04, 2013, 07:43:01 amUsing multipole relays you can cut it down to 6 relays, here you just need 2 pole units, though probably it would be better to standardise on a 4 pole unit in a plug in base, so you have a standard relay for most purposes. You can use a screw base or a solder in base for the relays, so you can have them PCB mounted for ease of wiring, or just use a standard industrial relay backplane system to have the relays on the one side and the wiring as point to point on the back side. Simple enough to do just using symmetrical DIN rail strips and an end to hold them spaced apart, with clip on holders. Relay wise you can buy cheap industrial relays like Omron MY4IN relays in assorted coil voltages, and have a built in indicator LED. I just bought 2 replacement ones Thursday, the old ones were failing after around 2 million cycles at 1A inductive load, about what the datasheet specifies. these replaced some Brown Boveri units that did over 30 years service, but are now no longer available or have rebuild parts in stock.

author: amyk
author_rank: Super Contributor
timestamp: August 04, 2013, 10:27:12 am
content: A 6-relay (SPDT), 2-diode full adder. Signaling is "open-emitter".

author: Psi
author_rank: Super Contributor
timestamp: August 04, 2013, 12:21:05 pm
content: And that's why this forum is awesome.Someone asks a question and everyone works together to find/improve a solution in a few hours.I wonder which would be more efficient in terms of relays used, a hardware add/subtract system which does mul/div out of add/sub. Or a hardware add/sub/mul/div system.It would depend how much extra logic is needed to hardcode the mul/div loops and store the counts. You'd also need a clock and a tiny bit of ram, it would becomes more like a cpu.The extra long relay chatter when doing mul/div would be cool though.

author: echen1024
author_rank: Super Contributor
timestamp: August 04, 2013, 08:18:46 pm
content: I'm about to go to China in 2 months, so I'll probably just come home with about 400 relays in case I screw up and a crap load of Veroboard/Breadboard. I think the most difficult things here will be the multiplier and divider. Might just use bit shifting for that. And to crank up the complexity one more level, how about one with memory/pi/log/trig calculations. I should just store it all in an 11U server rack with a couple of massive fans.

author: Psi
author_rank: Super Contributor
timestamp: August 04, 2013, 08:47:02 pm
content: If you use diodes as part of your gates you will need to consider the voltage drop of each section. To many sections in a row and the drop will be so great relays will stop pulling in.Using schottky diodes and high voltage relays will of course help .Or you could buffer the output periodically with an extra relay.

author: IanB
author_rank: Super Contributor
timestamp: August 04, 2013, 09:39:47 pm
content: Quote from: echen1024 on August 04, 2013, 08:18:46 pmThe standard way to multiply two numbers is shift and add (just the same way that you do long multiplication on paper). Division is the same, only you reverse the procedure to do subtract and shift. Here is the multiplication example:Code:// compute z = x * y by shift and addz = 0;while (x){if (x & 1) z += y;x >>= 1;y <<= 1;}(And a complete program in case you want to try it)Code:#include <iostream>using namespace std;int main(){// compute z = x * y by shift and addint x = 19;int y = 73;int z = 0;cout << x << " * " << y << " = ";while (x){if (x & 1) z += y;x >>= 1;y <<= 1;}cout << z << endl;}

author: echen1024
author_rank: Super Contributor
timestamp: August 05, 2013, 01:07:20 am
content: And also, a stupid question, what type of relay and diode would you guys recommend for this, and a digi-key part number would be helpful as well. Thanks for all your help.

author: Rerouter
author_rank: Super Contributor
timestamp: August 05, 2013, 02:10:17 am
content: for the diodes, i would reccomend the lowest voltage drop you can get away with, without becoming excessivly expensive,

author: Psi
author_rank: Super Contributor
timestamp: August 05, 2013, 02:14:24 am
content: I guess it will depend on the design and the max number of relays pulled in by the contact of a single relay.Since that will govern the max current through a diode.

author: ElectroIrradiator
author_rank: Frequent Contributor
timestamp: August 05, 2013, 09:17:58 am
content: Something to keep in mind, if you aim for maximum reliability, is to use flyback / catch diodes across each (group) of relay coils. Without these the back-EMF when the coils are de-energized may over time burn the controlling contact sets. You also run the risk of potentially burning out diodes, depending on how the circuits are wired.Personally I'd just use inexpensive yet rugged 1N4007 (1A) or 1N5408 (3A) standard diodes. Speed is irrelevant here, and if you manage to make a long string of series connected diodes in a complex piece of logic, then just amplify the signal with another relay.The only way to get noticeably lower voltage drops, compared to an 1N5408, would be to use Schottky diodes, and I'd rather not use those around relays. Schottky diodes are usually not very rugged when it comes to high voltage spikes.Do check whether the rather thick leads on the 1N5408 series bothers you before deciding to use those.

author: amyk
author_rank: Super Contributor
timestamp: August 05, 2013, 12:09:43 pm
content: Quote from: Psi on August 04, 2013, 12:21:05 pmA hardware multiply/divide implementation is basically quadratic in the size of the input, so if you're going for small size it would be better to do shift+add/sub. On the other hand, doing it in hardware is much faster. (This is why e.g. the 8088's multiply and divide instructions were so slow: it used the ALU, and because there was just one bus connecting everything, many of the clock cycles are just moving the values around between internal registers.)If you can get 4-pole double-throw relays, aZuse adderis probably the most efficient: only 2 relays per bit!

author: GK
author_rank: Super Contributor
timestamp: August 05, 2013, 12:59:56 pm
content: Quote from: echen1024 on August 05, 2013, 01:07:20 amDon't get cheap relays and/or ones designed for switching heavy current (eg automotive relays). Contact oxidation can be a real issue switching small currents. Telecom style "signal" relays would be the best; sealed with gold plated contacts.

author: echen1024
author_rank: Super Contributor
timestamp: August 05, 2013, 05:38:48 pm
content: Quote from: GK on August 05, 2013, 12:59:56 pmThe main issue I'm seeing here is that the signal relays are quite expensive compared to the current switching ones. As far as I'm concerned, I'm probably going to do the bit-shifting multiply/divide due to the long relay chatter sounding quite fun. Is there a specific signal relay that can be had for cheap that would fit this purpose?

author: woodchips
author_rank: Frequent Contributor
timestamp: August 05, 2013, 06:48:54 pm
content: Definitely a good idea to put surge suppressor, varistors, smarties, call them what you will across every coil. Just normal silver alloy contacts will be adequate, worked in telephone exchanges for many years. Just make sure there is a minimum current through every contact when closed, wetting current. The design of the relay should result in a small amount of wiping action as they operate, otherwise the oxide film won't get scraped away.

author: SeanB
author_rank: Super Contributor
timestamp: August 05, 2013, 06:59:05 pm
content: Relay driving a relay is not a signal switching application, but a low power one. Will have enough current to keep the contacts clean. I just replaced 2 relays that have done 2 million cycles at low load, as one was possibly sticking, and replacing it was easier. just use either a RC snubber across the coil or the contacts, or use a zener diode across the coil, or a transient suppressor diode.

author: GK
author_rank: Super Contributor
timestamp: August 06, 2013, 01:50:11 am
content: It is still a concern as some high current relays can be quite bad. 10A+ DPDT automotive relays can be had in quantity for peanuts (due to the mass manufacture) but should probably be avoided. This was an issue in the last model of Nissan Patrol 4WD. We've had all three Patrol's out in the field and in one morning or two all three(!) vehicles wouldn't start due to the relay issue. The designers stuffed up by just using the same model high current relay (Inventory minimization I guess) to switch high current stuff (lights, horn, etc) as well as low current circuits, which in part activate/trigger the ECU. Basically you get in the vehicle in the morning, turn the key but the glow plug indicator light (IIRC) stays permanently lit and the starter remains locked out. In other words, totally dead engine. The fix is to get under the dash beneath the steering column and swap the relays in the high current circuits with the ones in the low current circuits. Then (fingers crossed) you would be OK for a couple of weeks!

author: Psi
author_rank: Super Contributor
timestamp: August 06, 2013, 02:05:19 am
content: It really depends how much use the machine is going to have.Obviously you want to design it to last a long time but dont want to be paying $20 per relay.In this application i doubt it's ever going to get to 100,000 actuation since it's more of a fun thing to play with than something your going to be crunching numbers on every day.There's nothing wrong with buying cheap stuff from ebay/aliexpress, you just have to check its suitable for your projectPersonally, i would buy like 2-3 each of ~5 different small but cheap relays from aliexpress or ebay (that are available in high quantities).Then wire them all up to a clock so they switch 5 times a second continuously with 20mA or so through the contacts. Leave it running for 2 days or so and then check them. (864,000 actuations)Then you can grade them based on how many failed of each type and pick the one with zero failures.

author: Paul Moir
author_rank: Frequent Contributor
timestamp: August 06, 2013, 01:54:47 pm
content: For ultimate high performance and reliability, you might put a little thought into the transient protection since just a diode will slightly increase release time. A TVS or zener/diode combination is a little bit better, and is only twice the work or three times the cost.Everything you never wanted to know about relays, about page 30Coil Suppression can Reduce Relay LifeThanks for the interesting discussion!

author: echen1024
author_rank: Super Contributor
timestamp: August 06, 2013, 03:40:12 pm
content: I just don't think this will be my everyday number cruncher. I'm in high school, and don't think that the teacher would look very highly upon me bringing a clacking box the size of a desk everyday that has only 4 functions. So in this case, reliability is less of an issue when selecting a relay.

author: minibutmany
author_rank: Regular Contributor
timestamp: August 06, 2013, 04:06:34 pm
content: There is a book out by the microsoft press calledcode. It runs through an imaginary build of a computer completely out of relays, and describes all the logic of 8 bit adders, RAM ect. and how they fit together in a practical system. I would highly recommend it to anyone building any sort of computer, but it also makes for a good pleasure read

author: woodchips
author_rank: Frequent Contributor
timestamp: August 06, 2013, 05:43:59 pm
content: Is that the only title, Code? Is there an author or anything else to make finding it easier. Thanks.

author: amyk
author_rank: Super Contributor
timestamp: August 06, 2013, 07:43:01 pm
content: I think he's referring tohttp://www.charlespetzold.com/code/

author: IanB
author_rank: Super Contributor
timestamp: August 06, 2013, 08:00:26 pm
content: Quote from: woodchips on August 06, 2013, 05:43:59 pmGuess what comes up as the first result if you go to amazon.com and search for "microsoft press code"?Honestly, some people today couldn't learn to put one foot in front of the other without instructions...

author: echen1024
author_rank: Super Contributor
timestamp: August 06, 2013, 08:10:32 pm
content: Quote from: IanB on August 06, 2013, 08:00:26 pmThat's exactly what I did. And we don't have that book here in conservative Texas at the library. I show my neighbors a relay calculator they'll thank god for making things work.

author: dfmischler
author_rank: Frequent Contributor
timestamp: August 06, 2013, 08:40:47 pm
content: Quote from: echen1024 on August 06, 2013, 08:10:32 pmIt's amazing what you can find with a little smart googling.

author: echen1024
author_rank: Super Contributor
timestamp: August 06, 2013, 08:56:07 pm
content: Quote from: dfmischler on August 06, 2013, 08:40:47 pmI found it on Amazon. Problem solved.

author: c4757p
author_rank: Super Contributor
timestamp: August 06, 2013, 09:01:39 pm
content: Quote from: echen1024 on August 06, 2013, 08:10:32 pmAnd chastise you for spending the time with such useless pursuits instead of helping to spread the Good News.

author: echen1024
author_rank: Super Contributor
timestamp: August 07, 2013, 04:23:41 am
content: Quote from: c4757p on August 06, 2013, 09:01:39 pmExactly.

author: woodchips
author_rank: Frequent Contributor
timestamp: August 07, 2013, 09:54:19 pm
content: Who are Amazon?

author: IanB
author_rank: Super Contributor
timestamp: August 07, 2013, 10:57:14 pm
content: Quote from: woodchips on August 07, 2013, 09:54:19 pmI'm not sure. I have heard they may operate some kind of on-line store that sells books and stuff, but who knows what's going on with this new-fangled internet thing...?

author: echen1024
author_rank: Super Contributor
timestamp: August 08, 2013, 12:03:22 am
content: Quote from: IanB on August 07, 2013, 10:57:14 pmIt's some weird website I found after intensive googling. And I own stock in them...?

author: woodchips
author_rank: Frequent Contributor
timestamp: August 08, 2013, 10:31:57 am
content: Ah, better not ask who Google are either I suppose. But using Altavista I did find some on line shop called Amazon. Searching for "Microsoft Press code" came up with 6 different titles on the first page. So without knowing anything more, like the author's name, didn't actually get me any further.

author: dfmischler
author_rank: Frequent Contributor
timestamp: August 08, 2013, 10:59:25 am
content: Charles Petzold