SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By Dr.Ivan
#111591
Hi there :)

I'm rather new in this field, so please bear with me.

Intro:
The primary aim of this project is to learn more about the basic electronic components and computation (plus having something completely awesome, yet entirely pointless to show my nerdier friends ;) ).

Aim:
To build a 2-bit ALU with NPN transistors, resistors and LEDs only.

Schematics:
http://en.wikipedia.org/wiki/File:2-bit_ALU.png, replacing the two 8-bit muxes with 4-bit muxes as per http://electrosofts.com/verilog/mux_circuit.jpg

Conditions:
A) Inputs (2 numbers, each 2 bits wide as well as the mathematical operation to perform, 2 bits wide) are set by simple SPST switches
B) The 2 bit output should be represented by 2 LEDs
C) All logic gates should be constructed from NPN transistors and resistors only (http://alansouthall.files.wordpress.com ... -03-pm.png). Each gate should have an LED indicating the state of the output pin.
D) Power source should either be a 9V battery or a USB port (5V)

My questions:
Is this project plan at all feasible? After sitting down and trying to simulate one of the muxes in such setup I found it tremendously difficult to make it work. It requires ridiculously high current, and output voltage is far too small to switch a LED on (all my LEDs require around 2.3-2.6V). I tried to adjust resistor values (replacing the 10k and 330 Ohm resistors demonstrated here with 10 and 100 Ohm resistors respectively), which helped to a certain degree (I can see change in output voltage), but it's still far too small to power a LED.

Should I perhaps instead use two power sources: one for logic and one for LEDs? Do you have any other tips to get me going?
By tecoist
#111604
If you are limited to NPN transistors and resistors, congratulations! You're trying to recreate one of the first integrated-circuit logic families, usually called Resistor-Transitor Logic or RTL. Yes, it's quite possible to build an ALU out of these suckers. At least one of the (tiny primitive) computers in the Apollo project was built out of RTL gates.

If your power supply choices are 9V and 5V, I vote for 5V. With RTL, all you get with higher voltages is more heat: you'll get less noise margin and drive, in fact, because the collector resistor gets bigger.

These gates will have very limited drive (fanout) capability. If you have to have an LED-per-gate, I'd build a little buffer for each LED rather than driving the LED directly: the buffer looks just like the inverter you've drawn, but with the LED in series with the collector resistor (not in parallel with the transistor as it is in your diagram). You don't need a separate power source for the LEDs, as such, just a better amplifier driving the LED. You can figure out the collector and base resistor values just from the voltage drops and current you need, rather than pulling random values out of your Big Box Of Resistors--Ohm's law is your friend here.

As you'll soon see in circuit simulation, RTL really really prefers NOR gates. I wouldn't even bother with the NAND, personally: I'd De Morgan NANDs into NORs.

Whee. I had fun building stuff very much like this when I was a kid, 40 years ago or so.

My only other tip would be to google resistor-transistor logic. I think there may still be some information on this logic family (and why it sucks pond water, to use the highly technical language of electrical engineering) out on the intarwebs. Motorola and Fairchild both made RTL logic gates, iirc.
By Dr.Ivan
#111612
Thank you for a thorough answer and some very useful tips!

Yes, indeed this is an RTL-based project - this is simply because I found schematics for the various gates to be much simpler (both in terms of understanding and construction) than what for example TTL or DTL is concerned. However I am now reading that RTL is a largely outdated logic, especially due to lower speed of operation. I am sure though that this will not have any impact on my simple project.

I have still one question. If you take a look at the gate schematic that I posted previously (link), you see that there is a 10k resistor on each input. My question is whether I must have these resistors on ALL gates, or only on those connected to the input switches? In other words, are such resistors needed when connecting output from one gate to another?

Otherwise I'll try to read up on RTL and come back with the results. Thanks again for the help!
By Dr.Ivan
#111652
Disregard my previous question, please - my brain appears to be in the LOW state at the moment, held firmly down with a pull-down resistor (oh god, the puns :lol: ).

Anyways, I have done as you suggested and simulated the muxer circuit with only NOR (and NOT) RTL-based gates, with buffer (is that the official term?) for each LED. It works like a charm! However, I'm beginning to see how huge the PCB for this will be (ain't gonna be cheap - I wanted to order it from BatchPCB and all)...
User avatar
By viskr
#111662
Yes your circuit would grow pretty quickly, but I can see it as a useful exercise, as most hardware design seems to be writing software in Verilog or VHDL these days. Too few engineers appreciate what it takes to build up even simple gates.

If you can find a copy of the TI TTL Handbook from the mid 1970s, most of those specs included the actual transistor schematics for the parts, including the 74181 which was a 4 bit ALU. Its one reference book that will never leave my shelf.

The next step up in integration is probably a good way to go. That would be using FPGAs to design with gates (yes you can still do it with schematics)
By Dr.Ivan
#111686
Well, yes, after spending the night trying to sensibly design a PCB board for the 4-bit multiplexer, I have come to the conclusion that it is actually easier to do on a protoboard and manually connect the components with wires. This is pretty much as laborious and costs a lot less than ordering a couple of square meters of PCB.

And, tecoist, you are spot on of course - the design will have to be modular, which by no means is a bad thing. This way I can test each part of the system separately. It looks like I'll have two main modules: a 4-bit mux and a 1-bit ALU. The final design will require two pieces of each module plus a protoboard which contains the control switches and output LEDs.

Fun fact: After recalculating hardware requirements, my BOM now contains: 196x NPN transistors, 196x 10 kOhm resistors, 146x 330 Ohm resistors as well as 42 LEDs. And that's not counting the control module.

@viskr: I couldn't find the handbook, however I was able to procure a copy of the 74181 datasheet - and it actually doesn't look too complicated! Perhaps I might build it some day (I have a bunch of ready-to-use NAND gates lying around...).
By SecretSquirrel
#111933
You can potentially reduce the component count by removing the four redundant gates in the logic section of the ALU. If you notice, the adder performs an AND of the two bits so there is no reason to include a separate stand alone AND gate. Simply tap the AND signal from the appropriate point in the adder. The same applies to the XOR. Reducing the number of XOR gates will certainly reduce the number of transistors needed.

I count 19 transistors for each MUX which can be reduced to 36 by sharing the inverters in the control logic, effectively make a single two bit 4-1 MUX instead of two one bit versions. You've got 8 transistors for each XOR, 3 for each AND, 3 for each OR. I count 28 transistors per 1 bit ALU. The LED buffers an another 40 transistors.

That should put the transistor count somewhere around 130 and you can reduce it even more if you look at the makeup of the XOR gates. An XOR block composed of NOR gates actually generate A+B internally meaning you could drop 6 transistors per ALU there. It also contains a NOR of A and B which which with the addition on another transistor will get you your discrete OR, saving you two more transistors.

If you don't put LEDs on each gate inside the MUX, I think you could get the transistor count down under 100, depending on whether your bigger concern is the parts count or having the final circuit physically resemble the "high-level" circuit to which you linked.

Sorry to semi-derail the discussion. I am very glad to see people still interested in understanding how logic works at this level.
By Dr.Ivan
#112067
Thank you for some great suggestions, SecretSquirrel! You are certainly not derailing the discussion. Since I am very new at this, all suggestions are most welcome!

Indeed, removing the LEDs would save me loads of work and parts, but I wanted to give this project some artistic quality (and, as you can imagine, LEDs are perfect for such task ;) ) - so I am rather reluctant to remove them. But, of course, I am going to be building some prototypes over the next few days and if I see that complexity exceeds my ability or requires huge amounts of space (in terms of protoboards especially), the LEDs will be the first aspect to be removed from the design. Otherwise I am not too worried about parts - these are easily obtained for very low prices at for example eBay.

Much of the same rationale goes for optimization - reduction in number of parts is in terms of real-world application a very sound idea, but in view of the goals for this particular project it is something I would like to avoid, since for me it reduces the charm of building something completely enormous and redundant.

Nonetheless I am really intrigued by these optimizations you mention - I am going to take a close look at your suggestions as soon as I get the time. If all goes smoothly with this project I might perhaps build a smaller optimized version or at least simulate it in some shape or form.
By SecretSquirrel
#112353
I suspected there was some artistic desire in the project. It has be considering laying out a similar board and driving it with a random number generator to get a good "blinky light" display. :) I might go surface mount to keep the board size down so I can hang it on the wall in my office.

--SS
By Dr.Ivan
#112492
Sounds really cool, SS! Nothing like a project to lighten up your working day! (sorry horrible pun...)

However I do see that I might run into a problem powering all of the LEDs. If all of the 52 LEDs (2.2-2.4V / 20mA) I am planning on using will be turned on at the same time they will use 52 x 20 mA = 1040 mA. However, I would really like to drive this puppy from a USB port (capped at 500mA) or a wall-wart-to-USB-converter (some of these are rated for charging 2 USB devices, equaling 1000mA). Thus, in short, I am limited to 1000mA... Now, all LEDs will most probably not be on at the same time, but still - it is sort of pushing the limits.

Also, is there any simple way to calculate current draw of the whole ALU?
By tecoist
#112499
Dr.Ivan wrote:Also, is there any simple way to calculate current draw of the whole ALU?
Do you have access to HSPICE or any sensible circuit simulator? It's so much nicer to let the computer do all the addition for you, I find.
By UhClem
#112518
Dr.Ivan wrote:Yes, indeed this is an RTL-based project - this is simply because I found schematics for the various gates to be much simpler (both in terms of understanding and construction) than what for example TTL or DTL is concerned. However I am now reading that RTL is a largely outdated logic, especially due to lower speed of operation. I am sure though that this will not have any impact on my simple project.
CMOS is simpler, uses less power, and you only need two parts (NMOS and PMOS FETs).

This is the text I used and I am amazed to find that the VLSI layout tool I used (MAGIC) is still around.
By tecoist
#112532
UhClem wrote:CMOS is simpler...
Tastes vary: to my taste, CMOS is slightly more complex. For an n-input logic gate, you end up with 2n transistors, as opposed to n+1 (NMOS) or n (resistor-transistor logic), and you get to wire up two transistor trees (P-side and N-side) instead of just one. Of course I welcome our new (25-year-old) CMOS overlords: there are many good reasons we switched from the "simpler" (to my taste) processes to CMOS.

I, too, celebrate magic's longevity. I think it must be about 25 years old, too, just like silicon-gate CMOS, but I'm too lazy to go look up Ousterhout's original paper to see.
By Dr.Ivan
#112676
@tecoist: Yeah, sure, I'll try to simulate it. Now, I don't have HSPICE, although I do hope to scrape together enough opensource tools to pull it off.

@UhClem/tecoist: Another point is that MOSFETs are more expensive than the resistors and transistors needed for RTL (after a quick search on eBay).