Moderators: phlip, Larson, Moderators General, Prelates

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.


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.



Full adder: A and B are added, C is the carry
New 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.
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!




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




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.
Choose resistance R so that Vcc/R<Imax, the maximum current your LED can safely handle (typically a few mA).

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.

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.
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 don't think any working transistor should show those characteristics.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.
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)?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:I don't think any working transistor should show those characteristics.
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)?
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?
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.

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: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.
(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).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.
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....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.
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:
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.)
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....

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.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.
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.

Hey, that's good news. (Was that with new transistors, or the old ones?)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?)[/quote]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.
eta oin shrdlu wrote:Does the NAND gate
work right too (LED lights iff both inputs are at +5V)?

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.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.


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: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
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: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 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.
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.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.
eta oin shrdlu wrote: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.
eta oin shrdlu wrote: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.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.

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: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.
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.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?
eta oin shrdlu wrote: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: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: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.

Users browsing this forum: No registered users and 3 guests