## Transistor Adding Machine

A place to discuss the science of computers and programs, from algorithms to computability.

Formal proofs preferred.

Moderators: phlip, Larson, Moderators General, Prelates

### Transistor Adding Machine

I spent last week playing around with my Arduino and thought to myself, How was this done before I could tell things what to do in C? So, I started reading about transistors and such. To shorten this mess that I could have otherwise posted, I'm trying to figure out how to use them. My friend (who oddly refuses to help me further) suggested that I make a simple binary adding machine. How would I go about beginning such a project? I'd assume that NPN transistors are preferable, and I'll probably need a lot of them. I think it would be easier to display the result of the calculation in binary as well using LEDs to indicate 1 or 0.
Last edited by bocochoco on Wed Dec 30, 2009 7:03 pm UTC, edited 1 time in total.

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistors

bocochoco wrote:(snip) make a simple binary adding machine. How would I go about beginning such a project? I'd assume that NPN transistors are preferable, and I'll probably need a lot of them. I think it would be easier to display the result of the calculation in binary as well using LEDs to indicate 1 or 0.

Here are some things that would be useful to look into:
Logic gates -- try making a binary adder out of these.
Adders -- this page gives information about half adders and full adders. Using these, you can string them together to make something of n number of bits.
NAND gate -- this page also has links to the other gates you can make, and it has a diagram of a NAND gate. The easiest gates to make (read: the ones with fewest transistors) are NOR, NAND, and NOT.
You'll either need to have two sets of switches, and have it just add "in real time" as you flip the switches to enter the number, or some form of memory cells. Memory cells, while not too complex, add a whole extra level of complexity to it, since you have to add in switches to store the number, etc. A logic gate simulator would be good to build this with online before implementing it in physical hardware, so you can be sure it works. I'd give you a link for one, but the page which had the list (for my class at university) is down (server maintenance). Good luck!
ntietz

Posts: 73
Joined: Sun Aug 31, 2008 6:05 pm UTC

### Re: Transistors

I'm sure this is wrong, but I think that I might at least be on the right track. I made a (messy) diagram in Dia using the logic I drew out for 2 bits + 2 bits.

bleh img tags dont work for svg's... http://bitfridge.com/2adder.svg

How wrong am I on this?
Last edited by bocochoco on Wed Dec 30, 2009 2:25 am UTC, edited 1 time in total.

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistors

There's a great program called Digital Works that lets you design circuits and test them. I used it in my Computer Architecture class and had a lot of fun with it. It abstract slightly, though - the smallest unit are the basic gates, not lines of semiconductor. But if you can accept that the CNOT and AND gates are already done for you, you can go crazy from there and reimplement XOR and such yourself.

For messing around at the lower level, there's a *great* flash game called KOHCTPYKTOP that lets you design circuits using metal and semiconductors directly. It's really awesome, but quite difficult. I'd recommend playing around with it just until you feel you've learned enough about stuff that low-level, then going back to Digital Works to actually *do* stuff in.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

Xanthir
My HERO!!!

Posts: 3989
Joined: Tue Feb 20, 2007 12:49 am UTC

### Re: Transistors

From what I read on that wikipedia page on Adders, it seems like I should construct a half-adder for the lowest order bit, and full adder's for all the remaining bits? Or do I have this backwards? As per my goal, I'm not going to use gate IC's, but construct the gates from transistors instead (As I have upwards of 300 of them). And yes, I do intend to build this without memory, rather using a series of dip switches for each number.

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistors

bocochoco wrote:From what I read on that wikipedia page on Adders, it seems like I should construct a half-adder for the lowest order bit, and full adder's for all the remaining bits? Or do I have this backwards? As per my goal, I'm not going to use gate IC's, but construct the gates from transistors instead (As I have upwards of 300 of them). And yes, I do intend to build this without memory, rather using a series of dip switches for each number.

Yeah, you need full adders for most of the bits, because a full adder can take in the carry bit from the last bit down.
You can build memory from transistors, but you'll probably need a few resistors and such to link the transistors together into proper logic gates.

lulzfish

Posts: 1214
Joined: Tue Dec 16, 2008 8:17 am UTC

### Re: Transistors

Seems like it would save me a few transistors if I used a half adder for the lowest order bit, since theres nothing carried to it.

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistors

Oh there is some excellent circuit simulator for Windows... it had a good UI and used SDL and was for a college thesis.. I can't seem to find it on the internet though.. maybe someone can mention it for me? (the name came from a greek god but I can't remember it)
My new blag(WIP, so yes it's still ugly..)
DEFIANCE!

This is microtext. Zooming in digitally makes it worse. Get a magnifying glass.. works only on LCD

Earlz
Gets Obvious Implications

Posts: 786
Joined: Sat Jun 09, 2007 8:38 am UTC
Location: USA

### Re: Transistors

Ok, so I read up on adders and the logic gates, and I drew a schematic with ExpressPCB. I tried to expand the XOR, AND, NAND, and OR gates from IC's into transistors as per what I am trying to do.

Link to picture (too big for forum)

I'm not very good with the software, but I think I got it right. Could somebody tell me if this is correct? I know that it's a lot to look at, but I'm not entirely sure I got the gates right. The drawing itself in the ExpressSCH format is here.

I read about another way to make a 1bit adder using two half-adders. It saves about 3 transistors if I counted right.
Schematic for that one.

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistor Adding Machine

I've made this exact project in the past (but only a half adder). I used only AND, OR, and XOR gates, not the NAND, NOR, and XNOR stuff which adds unnecessary confusion when trying to think about the results in your head.

If I recall correctly, each AND gate takes 2 transistors, each OR gate takes 2, and each XOR gate takes 6.

So, a half adder (1 XOR and 1 AND ) should have 8 transistors, and a full adder (2 XOR, 2 AND, and 1 OR) should have 18 transistors. Both of those schematics you posted have significantly more than 18, so I'm guessing that if they work, they are sub-optimal.

Code: Select all
`Full adder:  A and B are added, C is the carryNew C = (A and B) or ((A xor B) and C)Added = C xor (A xor B)^the (A xor B) should be the same gate for both calculations.`

I'm not really sure how to represent logic gates in plain text so I hope that's not confusing...

As far as the schematics go, I'll assume you know how to make the easy 2 transistor gates (AND, OR, A not B, B not A) The difficult one is the XOR gate. Think of it as this combination: (A not B) or (B not A) which uses 3 of the 2 transistor gates hence the 6 transistors. This was my approach anyway, hope that helps!
A programmer's last program: Goodbye World!
Quigibo

Posts: 29
Joined: Fri Nov 20, 2009 9:45 am UTC

### Re: Transistor Adding Machine

Quigibo wrote:If I recall correctly, each AND gate takes 2 transistors, each OR gate takes 2, and each XOR gate takes 6.

So, a half adder (1 XOR and 1 AND ) should have 8 transistors, and a full adder (2 XOR, 2 AND, and 1 OR) should have 18 transistors. Both of those schematics you posted have significantly more than 18, so I'm guessing that if they work, they are sub-optimal.

As far as the schematics go, I'll assume you know how to make the easy 2 transistor gates (AND, OR, A not B, B not A) The difficult one is the XOR gate. Think of it as this combination: (A not B) or (B not A) which uses 3 of the 2 transistor gates hence the 6 transistors. This was my approach anyway, hope that helps!

I was looking around for how to make the gates using 2 transistors, couldn't find them I found

And XOR gates built out of NAND gates. That's what i based my schematics from. At first, before doing much research on this, I figured that an AND gate could be built by putting two transistors in series and if the base is HIGH for both, the emitter for the second would be HIGH, but when I looked for a schematic of it, I found them being built using three transistors. Two in series and a third (as in the pictures above).

Is this accurate for AND, OR, and XOR gates? How did you draw XOR gates with only 6 transistors? This is how I initially thought they were drawn before I saw the stuff on wikipedia.

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistor Adding Machine

Your one-bit full-adder cell (a translation of the gate-level diagram on the adder page ntietz linked to above) looks to me like it should work. You can simplify things somewhat, though. The carry-out circuit, using an OR of two ANDs, is convenient for thinking about, but since NANDs and NORs use fewer transistors (you can omit the final inversion stage in your three-transistor layouts) it makes sense to use these instead. So right now you have C'=(S AND C) OR (A AND B) (where S=A XOR B); rewrite this as C'=(S NAND C) NAND (A NAND B) to use six transistors instead of nine in the bottom half of your adder.

Something you might want to add to your circuit is input resistors. As drawn, connecting the inputs (A, B, C) directly to the +5V rail is a bad idea; lots of current will flow through the input base-emitter junctions, which wastes power and might waste transistors too. You only need a few microamps to drive the transistors, so a ~10K resistor at each input will protect against this.

Your proposed AND and OR gates probably don't work as you want. You're thinking of the transistor as a base-controlled switch, but this simple model has some problems. The problem with the AND gate is easiest to see: the base-emitter junction is able to act as a diode, so your proposed AND gate will actually pull the current high whenever the lower input is high, independent of the upper input. One problem with the OR gate is that there's no pull-down resistor to provide a low-output sink; if both inputs are low the output is floating. (This may not be a problem; high-impedance outputs are sometimes acceptable.)

You can actually build a NOR gate out of just one transistor:
nor.png (4.77 KiB) Viewed 12232 times

This works because the transistor needs substantially less than Vcc/2 to turn on. For 5V rails and silicon transistors, you can extend this to three or four inputs; too many more and a single high input won't be able to drive the transistor any more. You can build an XOR out of NORs instead of NANDs and save some transistors in the top half of your adder circuit.

eta oin shrdlu

Posts: 399
Joined: Sat Jan 19, 2008 4:25 am UTC

### Re: Transistor Adding Machine

bocochoco wrote:I was looking around for how to make the gates using 2 transistors, couldn't find them

Here is an OR gate

Here is an AND gate

In that last picture ^ if you instead put the "Out" between the two transistors, its an A NOT B gate. Then you can always just switch A and B to make a B NOT A gate.
A programmer's last program: Goodbye World!
Quigibo

Posts: 29
Joined: Fri Nov 20, 2009 9:45 am UTC

### Re: Transistor Adding Machine

The circuit

probably won't make a very good AND gate. The problem is that B is able to pull Out up independent of A, because the base-emitter PN junction acts as a diode. Here the 10K resistor on B and the 4.7K emitter pull-down will act as a voltage divider, so if A is low and B is near Vcc then unloaded Out will be close to Vcc/3 (better estimate: (Vcc-Vbe)(4.7/(10+4.7))). This is too high to be a reliable low level for the NOR and NAND gates used in the adder circuit above, for example; depending on loading it may be interpreted as either high or low.

eta oin shrdlu

Posts: 399
Joined: Sat Jan 19, 2008 4:25 am UTC

### Re: Transistor Adding Machine

I hope that the transistors that I have will work for this. Not sure if theres a difference between the NPN's... I've got a lot of Mouser #512-KSD261CYTA that I got on ebay in a group with a lot of other little components. That being said, if they will work for what I am doing, what resistors would work best using +9v as the source voltage? I tried making a simple AND gate with two of them but the LED was lit regardless of the switches being on (though they did get slightly brighter when one of them was on).

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistor Adding Machine

Those transistors should be fine for your application. What circuit did you try to use for your AND gate? As I explained above, neither of the proposed two-transistor AND gates will actually work very well.

I'd suggest starting with the two-transistor NAND or NOR gate from your adder circuit, with an input resistance of about 10K. It's easiest to drive an LED by connecting it from collector to Vcc, with a current-limiting resistor in series, as shown below. This also has the effect of inverting the output: the LED will light iff A and B are high.
NAND-med.png (34.89 KiB) Viewed 12100 times

Choose resistance R so that Vcc/R<Imax, the maximum current your LED can safely handle (typically a few mA).

eta oin shrdlu

Posts: 399
Joined: Sat Jan 19, 2008 4:25 am UTC

### Re: Transistor Adding Machine

eta oin shrdlu wrote:Those transistors should be fine for your application. What circuit did you try to use for your AND gate? As I explained above, neither of the proposed two-transistor AND gates will actually work very well.

I'd suggest starting with the two-transistor NAND or NOR gate from your adder circuit, with an input resistance of about 10K. It's easiest to drive an LED by connecting it from collector to Vcc, with a current-limiting resistor in series, as shown below. This also has the effect of inverting the output: the LED will light iff A and B are high.
NAND-med.png

Choose resistance R so that Vcc/R<Imax, the maximum current your LED can safely handle (typically a few mA).

Just tried this, same results.I put a 4.7k resistor after the led. Connecting the bases through the 10k resistors to +9 does nothing, neither does disconnecting them entirely.

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistor Adding Machine

From your post I can't tell if the LED is always lit or never lit. Since you got the LED to light before, it's probably wired with correct polarity, but check that anyway; ground Q1's collector and make sure the diode lights (unless it's always lit, in which case you must have it right).

More likely either the transistors are miswired or they're bad. The data sheet linked at your Mouser link has a handy diagram showing the pin order (Emitter-Base-Collector, which is fairly standard for that package)... but there's a little note that says "suffix -C means center collector" (Emitter-Collector-Base). I think the C in your part number means that you've got the ECB type, though I'm not sure. Check this by checking the diode polarity for BE and BC. Use your diode and 4.7K resistor; connect the other end of the resistor to the transistor pin you think is the base. Now grounding either of the other transistor pins--either E or C--should make the LED light. If not, either you don't have the base, or the transistor is bad. (If you wired the transistors assuming they were EBC but they were actually ECB, then the LED should always light, possibly getting a little brighter if you ground A or B.)

You might want to try a one-transistor circuit for a start, just to reduce the number of possible problems. Just remove Q2 and the associated resistor; connect Q1's emitter directly to ground. This should light the LED whenever A is high.

eta oin shrdlu

Posts: 399
Joined: Sat Jan 19, 2008 4:25 am UTC

### Re: Transistor Adding Machine

eta oin shrdlu wrote:From your post I can't tell if the LED is always lit or never lit. Since you got the LED to light before, it's probably wired with correct polarity, but check that anyway; ground Q1's collector and make sure the diode lights (unless it's always lit, in which case you must have it right).

More likely either the transistors are miswired or they're bad. The data sheet linked at your Mouser link has a handy diagram showing the pin order (Emitter-Base-Collector, which is fairly standard for that package)... but there's a little note that says "suffix -C means center collector" (Emitter-Collector-Base). I think the C in your part number means that you've got the ECB type, though I'm not sure. Check this by checking the diode polarity for BE and BC. Use your diode and 4.7K resistor; connect the other end of the resistor to the transistor pin you think is the base. Now grounding either of the other transistor pins--either E or C--should make the LED light. If not, either you don't have the base, or the transistor is bad. (If you wired the transistors assuming they were EBC but they were actually ECB, then the LED should always light, possibly getting a little brighter if you ground A or B.)

You might want to try a one-transistor circuit for a start, just to reduce the number of possible problems. Just remove Q2 and the associated resistor; connect Q1's emitter directly to ground. This should light the LED whenever A is high.

I tried it with both one and two transistors in both ECB and EBC with your wiring diagram. In all cases the led was constantly lit and connecting A or B or both to either ground or +9v seemed to make no change at all.

Then, I tried it wiring the LED to the emitter, a 4.7k resistor to the collector from +9v, and the base to a 10k resistor. When I tried this with the transistor wired as ECB, the LED only lit when it was connected to the +9v through the resistor. I think this is how it was supposed to work. I wired it again to use two transistors in series, and when A was HIGH, the led was dimly lit, when A and B are both HIGH, the led was brightly lit, and with just B HIGH the led was not lit at all.

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistor Adding Machine

I'm not following that circuit description; a diagram might help. Actually a photo might help too, if you can get one with reasonable detail.

I still suspect a broken or miswired transistor; my advice is to first make sure you're sure which terminal is the base, using the method I described earlier. Warning: I didn't notice until now that the data sheet gives 5V as the emitter-base breakdown voltage; your 9V source is probably enough to burn out the junction if you connected it backwards. If you have access to a 4-5V source (like 3 AA batteries) you may want to use that for testing purposes.

test2.png (2.4 KiB) Viewed 12074 times
Start with the circuit at left; the LED should light (if it doesn't, you've labeled its terminals backwards). Now connect transistor terminal 1 at X and 2 at GND; then disconnect 2 and connect 3 at GND. If the LED lights both times, then terminal 1 is the base, otherwise not. Do the same thing with 2 at X (1 then 3 at GND) and then with 3 at X (1 then 2 at GND). If none of these three cases makes the LED light with both other terminals connected to GND, then the transistor is broken.

eta oin shrdlu

Posts: 399
Joined: Sat Jan 19, 2008 4:25 am UTC

### Re: Transistor Adding Machine

eta oin shrdlu wrote:I'm not following that circuit description; a diagram might help. Actually a photo might help too, if you can get one with reasonable detail.

I thought that might be hard to follow. Basically, I tried the transistors assuming that thy were ECB. With two transistors the led was lit regardless of whether or not A or B were actually connected to something. I tried it assuming that they were EBC, and got the same results. I tried it with one transistors assuming that they were ECB first, then EBC. In both cases here, the led was also constantly lit.

Following that, I tried plugging the + end of the led into the emitter and grounding the - pin, and wired the collector to +5v. With this circuit, the LED was lit only when I connected the base to +5v as well. I hope this was more clear.

eta oin shrdlu wrote:Start with the circuit at left; the LED should light (if it doesn't, you've labeled its terminals backwards). Now connect transistor terminal 1 at X and 2 at GND; then disconnect 2 and connect 3 at GND. If the LED lights both times, then terminal 1 is the base, otherwise not. Do the same thing with 2 at X (1 then 3 at GND) and then with 3 at X (1 then 2 at GND). If none of these three cases makes the LED light with both other terminals connected to GND, then the transistor is broken.

I'll have to try that when I escape the office. If I had doors on my cube I would probably just try it now though

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistor Adding Machine

bocochoco wrote:Basically, I tried the transistors assuming that thy were ECB. With two transistors the led was lit regardless of whether or not A or B were actually connected to something. I tried it assuming that they were EBC, and got the same results. I tried it with one transistors assuming that they were ECB first, then EBC. In both cases here, the led was also constantly lit.
I don't think any working transistor should show those characteristics.

You might want to try again with a new transistor, in case these are toasted. If you keep the voltages at or below 5V and add 4.7K resistors on each transistor pin (make all your connections to the other ends of these resistors instead of directly to the transistor), you should be able to run tests without letting the smoke out.

Following that, I tried plugging the + end of the led into the emitter and grounding the - pin, and wired the collector to +5v. With this circuit, the LED was lit only when I connected the base to +5v as well. I hope this was more clear.
Does the brightness change if you disconnect the collector from +5V (so that you just have +5V to base, emitter to diode +, diode - to ground)?

Can you post a photo? Do you have any other models of transistor around that you can use as a sanity check, in case this batch is just weird?

eta oin shrdlu

Posts: 399
Joined: Sat Jan 19, 2008 4:25 am UTC

### Re: Transistor Adding Machine

eta oin shrdlu wrote:I don't think any working transistor should show those characteristics.

I agree, doesnt sound like it should be that way.

eta oin shrdlu wrote:Does the brightness change if you disconnect the collector from +5V (so that you just have +5V to base, emitter to diode +, diode - to ground)?

No, the brightness is the same.

eta oin shrdlu wrote:Can you post a photo? Do you have any other models of transistor around that you can use as a sanity check, in case this batch is just weird?

The only other transistors I have are PNP's. I really dont know what the difference between NPN and PNP is other than the obvious difference in doped silicon types. I'll try to upload a picture of the breadboard when I get home from work. I'll shorten the wires so it's a bit easier to see how things are together. Breadboard There is a picture of the breadboard. I put it on flickr so I could add notes to it. With that circuit, if Base 1 is connected to +5V, the led lights and it will be brighter if Base 2 is connected as well. If just base 2 is connected, the led does not light.

eta oin shrdlu wrote:Start with the circuit at left; the LED should light (if it doesn't, you've labeled its terminals backwards). Now connect transistor terminal 1 at X and 2 at GND; then disconnect 2 and connect 3 at GND. If the LED lights both times, then terminal 1 is the base, otherwise not. Do the same thing with 2 at X (1 then 3 at GND) and then with 3 at X (1 then 2 at GND). If none of these three cases makes the LED light with both other terminals connected to GND, then the transistor is broken.

The first case scenario was true. With transistor terminal 1 at X and (2 or 3) at GND, the led lit up.

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistor Adding Machine

This would be so much easier in person....
bocochoco wrote:
eta oin shrdlu wrote:Does the brightness change if you disconnect the collector from +5V (so that you just have +5V to base, emitter to diode +, diode - to ground)?

No, the brightness is the same.
This makes it seem like you're not seeing any transistor gain; all you're seeing is the base current, passing through the base-emitter junction and then the LED. If the transistor were providing amplification, the circuits with the LED on the collector side should also light the LED (and potentially much more brightly than with just a low base current).

bocochoco wrote:
eta oin shrdlu wrote:Can you post a photo? Do you have any other models of transistor around that you can use as a sanity check, in case this batch is just weird?

The only other transistors I have are PNP's. I really dont know what the difference between NPN and PNP is other than the obvious difference in doped silicon types. I'll try to upload a picture of the breadboard when I get home from work. I'll shorten the wires so it's a bit easier to see how things are together. Breadboard There is a picture of the breadboard. I put it on flickr so I could add notes to it. With that circuit, if Base 1 is connected to +5V, the led lights and it will be brighter if Base 2 is connected as well. If just base 2 is connected, the led does not light.
(Thinking about PNPs now would probably just confuse the issue; we can return to them later if you'd like.) The breadboard wiring looks right (I assume the diode + is on top).

When you say that "base 1" lights the LED (whether or not base 2 is connected), do you mean the base of the transistor on the right, or the one on the left? The behavior you describe is, at least qualitatively, what should happen if transistor 1 is the one connected directly to the LED and transistor 2 is between transistor 1 and the voltage source; but your photo annotations have transistor 2 connected directly to the LED. Here's a diagram of your circuit:
e-LED.png (33.71 KiB) Viewed 12018 times

Q1 (and input lead A) is the one on the right in the photo; Q2 (and lead B) is the one on the left. If B is at +5V, then current will flow through Q2's base-emitter junction (which acts as a silicon diode, with about a 0.5V drop) and then through the LED. The transistor will attempt to draw much more current (up to about 100 times as much) from the collector, but if no current is flowing at A then Q1 will be off and this won't be possible. If A is also at +5V, however, then this will be possible and the LED should light up more brightly.

(I'm hoping that this is actually what you're seeing, and that transistors #1 and #2 are switched in your description, because this makes sense and means that the transistors might actually be working.)

Because the base resistances (10K||10K=5K) are close to the collector resistance (4.7K), you won't see a whole lot of gain; the transistors will saturate too soon. Try replacing the 10K base resistors with 100K resistors. Now with B=5V and A=0V (or disconnected), you will get a very small current (~25uA) through the LED: possibly enough to see, but not very bright. But with A=B=5V, you should get the transistor gain, and at least ~2mA through the LED, much brighter. (Based on your earlier tests I'm not sure this will happen, but it's what should happen.)

bocochoco wrote:
eta oin shrdlu wrote:Start with the circuit at left; the LED should light (if it doesn't, you've labeled its terminals backwards). Now connect transistor terminal 1 at X and 2 at GND; then disconnect 2 and connect 3 at GND. If the LED lights both times, then terminal 1 is the base, otherwise not. Do the same thing with 2 at X (1 then 3 at GND) and then with 3 at X (1 then 2 at GND). If none of these three cases makes the LED light with both other terminals connected to GND, then the transistor is broken.

The first case scenario was true. With transistor terminal 1 at X and (2 or 3) at GND, the led lit up.
OK, now I'm hoping that you labeled "terminal 1" the one at right in your pictures, the ones you've labeled as the base junctions in the annotations--is that right? If that's true, then that makes sense. Otherwise I'll have a lot more questions....

eta oin shrdlu

Posts: 399
Joined: Sat Jan 19, 2008 4:25 am UTC

### Re: Transistor Adding Machine

eta oin shrdlu wrote:When you say that "base 1" lights the LED (whether or not base 2 is connected), do you mean the base of the transistor on the right, or the one on the left? The behavior you describe is, at least qualitatively, what should happen if transistor 1 is the one connected directly to the LED and transistor 2 is between transistor 1 and the voltage source; but your photo annotations have transistor 2 connected directly to the LED. Here's a diagram of your circuit:
e-LED.png

Q1 (and input lead A) is the one on the right in the photo; Q2 (and lead B) is the one on the left. If B is at +5V, then current will flow through Q2's base-emitter junction (which acts as a silicon diode, with about a 0.5V drop) and then through the LED. The transistor will attempt to draw much more current (up to about 100 times as much) from the collector, but if no current is flowing at A then Q1 will be off and this won't be possible. If A is also at +5V, however, then this will be possible and the LED should light up more brightly.

(I'm hoping that this is actually what you're seeing, and that transistors #1 and #2 are switched in your description, because this makes sense and means that the transistors might actually be working.)

By Base 1 I mean the A input. With the A input at +5v, the LED lit dimly. With the A and B at +5v, the LED lit bright. With the B at +5v, the LED did not light at all.

eta oin shrdlu wrote:Because the base resistances (10K||10K=5K) are close to the collector resistance (4.7K), you won't see a whole lot of gain; the transistors will saturate too soon. Try replacing the 10K base resistors with 100K resistors. Now with B=5V and A=0V (or disconnected), you will get a very small current (~25uA) through the LED: possibly enough to see, but not very bright. But with A=B=5V, you should get the transistor gain, and at least ~2mA through the LED, much brighter. (Based on your earlier tests I'm not sure this will happen, but it's what should happen.)
OK, now I'm hoping that you labeled "terminal 1" the one at right in your pictures, the ones you've labeled as the base junctions in the annotations--is that right? If that's true, then that makes sense. Otherwise I'll have a lot more questions....

Yes, that is correct. I'll try replacing the resistors when I get out of work again. Stupid job keeping me from doing things...

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistor Adding Machine

I'd be tempted to build full adders for each and every step, because it would simply the debugging and design.

Just feed a constant 0 into the 'carry in' for the first adder.

How hard would it be to build a clock and a latch? Because a serial latch-adder might require fewer transistors than a semi-parallel adder-chain.

Ie, you have a sequence of latches connected to a clock. Each clock pulse the values go forward 1 step.

The adder adds together two values from two different latches, and outputs one bit to an output latch chain, and the other to a carry latch (which is used for input on the next cycle).

Toss in a "clear" bit that sets all of the latches to zero, and you have a circuit that is able to add as many bits as you feel like feeding it.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

Yakk

Posts: 10038
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

### Re: Transistor Adding Machine

bocochoco wrote:By Base 1 I mean the A input. With the A input at +5v, the LED lit dimly. With the A and B at +5v, the LED lit bright. With the B at +5v, the LED did not light at all.
Well, that makes me very sad. The other way would have made sense. As you describe it, current from Q1's emitter is somehow leaking through Q2 when it should be off, which makes no sense unless Q2 is dead... but then I don't understand why changing B would affect the LED. Maybe Q2's only mostly dead. I don't know if that's a likely failure mode, though.

Have you tried this circuit with new transistors, in case the first two you played with are toast? It probably makes more sense, actually, to try one at a time in a simple circuit:

If those don't both work as expected (LED lights brightly with input at +5V, off with input at 0V or disconnected) then there's no hope for a more complicated circuit to work the right way.

eta oin shrdlu

Posts: 399
Joined: Sat Jan 19, 2008 4:25 am UTC

### Re: Transistor Adding Machine

eta oin shrdlu wrote:Have you tried this circuit with new transistors, in case the first two you played with are toast? It probably makes more sense, actually, to try one at a time in a simple circuit:
ec-LED.png

If those don't both work as expected (LED lights brightly with input at +5V, off with input at 0V or disconnected) then there's no hope for a more complicated circuit to work the right way.

Both of those work as you described. Finally, something good happened. I think the problem all along may have been me not knowing the pinout for it, being ECB.

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistor Adding Machine

bocochoco wrote:
eta oin shrdlu wrote:Have you tried this circuit with new transistors, in case the first two you played with are toast? It probably makes more sense, actually, to try one at a time in a simple circuit:

If those don't both work as expected (LED lights brightly with input at +5V, off with input at 0V or disconnected) then there's no hope for a more complicated circuit to work the right way.

Both of those work as you described. Finally, something good happened. I think the problem all along may have been me not knowing the pinout for it, being ECB.
Hey, that's good news. (Was that with new transistors, or the old ones?)

Does the NAND gate

work right too (LED lights iff both inputs are at +5V)?

eta oin shrdlu

Posts: 399
Joined: Sat Jan 19, 2008 4:25 am UTC

### Re: Transistor Adding Machine

eta oin shrdlu wrote:Both of those work as you described. Finally, something good happened. I think the problem all along may have been me not knowing the pinout for it, being ECB.
Hey, that's good news. (Was that with new transistors, or the old ones?)[/quote]
Same old transistors. The two I started with when I began this nightmare of a project.

eta oin shrdlu wrote:Does the NAND gate
c-NAND.png

work right too (LED lights iff both inputs are at +5V)?

Works iff A + B are high. I still don't really understand why it works to begin with. I never thought about switching off a ground connection rather than a positive one. However, I noticed that if I only connect the second base to +5v, the led lights up very briefly and very dimly.

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistor Adding Machine

bocochoco wrote:
eta oin shrdlu wrote:Does the NAND gate

work right too (LED lights iff both inputs are at +5V)?

Works iff A + B are high. I still don't really understand why it works to begin with. I never thought about switching off a ground connection rather than a positive one. However, I noticed that if I only connect the second base to +5v, the led lights up very briefly and very dimly.
The brief flash might be a transient effect as some small capacitances discharge through Q1, though I wouldn't expect that to be visible; I'm not sure.

As to why it works, I'm not sure how much you already know about transistors, so I don't know where to begin. I guess I'll start with a reference to The Art of Electronics (Horowitz and Hill), which is probably the best introduction to circuits around.

eta oin shrdlu

Posts: 399
Joined: Sat Jan 19, 2008 4:25 am UTC

### Re: Transistor Adding Machine

Yet again, I drew a wiring diagram for an adder. NAND gates are universal, and are simple to make, so I constructed the adder out of them.

Look OK to you?

Each one requires
18 Transistors
18 2.2k Resistors
18 100k Resistors

Much more efficient than what I've drawn in the past, assuming that it works of course. I wonder if I would be able to use a single 2.2k resistor on the +5v line rather than 18 of them.

2.2k ohm and 100k ohm should work for this, correct?

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistor Adding Machine

I haven't had the chance to read through everything posted, but I can throw some things out there and give you and entire course of notes for reference.
First of all, for digital logic, CMOS transistors are preferred, and (at least the way I was taught) we used both n and p channel transistors. Technically, you can use any transistors you want, though.
Second, the difference between NPN and PNP BJTs, other than the silicon doping, is the quadrant of operation. Basically, a PNP has all negative voltages and currents of an NPN. This means one pulls up while the other pulls down, if you want to use them that way.
Third, here is Purdue's ECE 270 course page for information on all this lovely stuff. Check out traditional lecture notes, and Module 5 and 6 have a lot on adder circuits and simple computers, although we got to use GALs, because we frankly didn't have enough space on the bread boards to make a simple computer for the labs (which you can also check out).
"YES. DO IT WITH CONFIDENCE" ~fortune cookie

mochafairy

Posts: 1089
Joined: Tue Mar 25, 2008 11:27 pm UTC
Location: Ohio

### Re: Transistor Adding Machine

bocochoco wrote:Yet again, I drew a wiring diagram for an adder. NAND gates are universal, and are simple to make, so I constructed the adder out of them.

Look OK to you?

Each one requires
18 Transistors
18 2.2k Resistors
18 100k Resistors
Looks OK (there's a missing wire, on the base resistor of the third transistor down in the second column from left; and I only count 9 2.2k resistors). You can reduce the transistor count if you use the one-transistor NOR I drew earlier (NORs are also universal). For example, here's an "NXOR" (the negation of a two-input exclusive-OR) with four transistors:

Now (A NXOR B) NXOR C = A XOR B XOR C, so you can find the Sum bit with eight transistors. I think I can find Cout with two more, for a total of 10 transistors.

bocochoco wrote:I wonder if I would be able to use a single 2.2k resistor on the +5v line rather than 18 of them.
No, that won't work. The voltage across each of those 2.2k resistors is storing a "NAND" output; combining them would ruin that.

bocochoco wrote:2.2k ohm and 100k ohm should work for this, correct?
2.2k is possibly a bit small (or 100k a bit large). The ratio of these resistances is usually chosen to be around 10. If the base resistors are too large, the transistors won't be able to pull their collectors low; if too small, you waste power. The size and tolerance you've chosen are fine.

If you don't have a circuit simulator to let you try these things out, you should get one: for example, the free student version of PSPICE.

eta oin shrdlu

Posts: 399
Joined: Sat Jan 19, 2008 4:25 am UTC

### Re: Transistor Adding Machine

mochafairy wrote:First of all, for digital logic, CMOS transistors are preferred, and (at least the way I was taught) we used both n and p channel transistors. Technically, you can use any transistors you want, though.
CMOS (which is really a design method, using MOSFET transistors) is definitely preferred for large digital integrated circuits, for a bunch of reasons, including low quiescent power use and a symmetric signal-level scheme. It's not much fun to use large numbers of discrete-element MOSFETs, though, because they are more static-sensitive than BJTs.

eta oin shrdlu

Posts: 399
Joined: Sat Jan 19, 2008 4:25 am UTC

### Re: Transistor Adding Machine

eta oin shrdlu wrote:
bocochoco wrote:2.2k ohm and 100k ohm should work for this, correct?
2.2k is possibly a bit small (or 100k a bit large). The ratio of these resistances is usually chosen to be around 10. If the base resistors are too large, the transistors won't be able to pull their collectors low; if too small, you waste power. The size and tolerance you've chosen are fine.

You would recommend I use 1k and 10k rather than 2.2k and 100k? I plan on getting the resistors I need from mouser tonight.

eta oin shrdlu wrote:
mochafairy wrote:First of all, for digital logic, CMOS transistors are preferred, and (at least the way I was taught) we used both n and p channel transistors. Technically, you can use any transistors you want, though.
CMOS (which is really a design method, using MOSFET transistors) is definitely preferred for large digital integrated circuits, for a bunch of reasons, including low quiescent power use and a symmetric signal-level scheme. It's not much fun to use large numbers of discrete-element MOSFETs, though, because they are more static-sensitive than BJTs.

I looked up the CMOS NAND Gate, and it uses far more resources than the NMOS that I've already tested. Is there really a benefit to that route?

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistor Adding Machine

bocochoco wrote:You would recommend I use 1k and 10k rather than 2.2k and 100k? I plan on getting the resistors I need from mouser tonight.
1k and 10k should work. This will draw about (max) 5mA per gate, at Vcc=5V. I don't know how many adders you plan to make, but count them up and make sure your power supply will handle it. You could scale the resistors up without problems (e.g., to 10k and 100k), if all they're going to be doing is turning the transistors on and off as your circuit shows. But I assume you want to turn on some LEDs with the Sum bits, or something; if you make the collector resistors much larger than 10k then you won't get much light out of the LEDs. You could add an additional output stage to drive the LEDs, or any high-power devices, if you wanted.

bocochoco wrote:I looked up the CMOS NAND Gate, and it uses far more resources than the NMOS that I've already tested. Is there really a benefit to that route?
CMOS is most useful in VLSI designs, where power dissipation is a big problem. The two-transistor NAND gate you're using, for example, draws a constant current of Vcc/Rc when it's turned on. The CMOS NAND gate only draws current while it's switching; after that, there's no power dissipated.

eta oin shrdlu

Posts: 399
Joined: Sat Jan 19, 2008 4:25 am UTC

### Re: Transistor Adding Machine

eta oin shrdlu wrote:
bocochoco wrote:You would recommend I use 1k and 10k rather than 2.2k and 100k? I plan on getting the resistors I need from mouser tonight.
1k and 10k should work. This will draw about (max) 5mA per gate, at Vcc=5V. I don't know how many adders you plan to make, but count them up and make sure your power supply will handle it. You could scale the resistors up without problems (e.g., to 10k and 100k), if all they're going to be doing is turning the transistors on and off as your circuit shows. But I assume you want to turn on some LEDs with the Sum bits, or something; if you make the collector resistors much larger than 10k then you won't get much light out of the LEDs. You could add an additional output stage to drive the LEDs, or any high-power devices, if you wanted.

Well, I intend to chain 16 of them together. If you're going to do something, might as well go big right? powering LED's, yes. The LED's I have are driven by 3v. I think it would be easiest to add another transistor before it to use as a switch, and give each led its own +3v source.

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

### Re: Transistor Adding Machine

1. With 1k collector resistors, worst-case power draw is about 50mA per bit; for 16 bits, 800mA. You might want to go to 2.2k or 4.7k to reduce this.
2. Use a clean, modular layout and make it easy to test subcircuits; some of them won't work the first time you wire them up. Are you doing this on breadboard, perfboard, or what?
3. Good luck! Post pictures.

eta oin shrdlu

Posts: 399
Joined: Sat Jan 19, 2008 4:25 am UTC

### Re: Transistor Adding Machine

eta oin shrdlu wrote:1. With 1k collector resistors, worst-case power draw is about 50mA per bit; for 16 bits, 800mA. You might want to go to 2.2k or 4.7k to reduce this.
2. Use a clean, modular layout and make it easy to test subcircuits; some of them won't work the first time you wire them up. Are you doing this on breadboard, perfboard, or what?
3. Good luck! Post pictures.

I think I could get away with just adding a resistor in front of the LED if I needed.

Breadboard first, then transferring each one to a protoboard, and eventually if I can figure it out, ill transfer that onto a pcb. But that part isn't quite here yet. The protoboards I have are pre-shorted. I'll have to cut the traces where I dont want them. Will take some effort.

You've been a lot of help eta oin shrdlu (Still have no idea how to pronounce your name). I'll certainly post pictures of it as it gets further.

bocochoco

Posts: 317
Joined: Thu Aug 06, 2009 8:22 pm UTC

Next