Why does this two transistor AND gate not work as expected? - Page 1
Forum section: electronics / projects

author: dicky96
author_rank: Regular Contributor
timestamp: November 08, 2022, 06:05:20 pm
content: Hi guysI've been playing around with some discrete transistor logic gate circuits. However the AND gate circuit (this is a very common design found all over the internet) does not work as expected and I can't figure out why so I am hoping someone can help restore my sanity because I am pretty sure I do understand bipolar transistors, but I don't understand what is happening hereThe circuit is in the attachment - see Fig A (Q1 and Q2 are BC337)So supposedly this is an AND circuit, the LED should light, and I should get a logic 1 output at Y when both A and B are high (5V)What actually happens is this. When A and B are low (just not connected to anything) then the LED is out and voltage at Y is 0VFor the other logic states (all measured with DMM) and using patch wires to connect A and/or B to 5VA=5V B=0V LED Y=0V (LED is off)A=0V B=5V Y= 2.5V (LED lights half brightness)A=5V B=5V Y= approx 4.6V (LED is on bright)In the condition A=0V, B=0V I can measure the voltagesQ1 Collector is 5.1V, Base is 0V, Emitter is 2.5VQ2 Collector is 2.5V, Base is 0V, Emitter is 0VIn the conditions A=0V B=5VQ1 Collector is 5.1V, Base is 0V, Emitter is 2.5VQ2 Collector is 2.5V, Base is 0.75V, Emitter is 2.3V LED is onSo somehow Q1 turns on even when the base is 0VAhhh so I know what may say, the base connections are floating, even though my meter says they are 0V but let's make sure they are not floating - see Fig 2 (ignore the dashed line ad 390R resistor for now)And guess what? Adding the 10K from base to ground makes no differenceSo I remove Q1 and test it in my DCA55 - it is fine. But I replace it with a new one anyway - no differenceThen I think it may be something stupid with the veroboard (tracks not cut properly) but I can't find any problem thereBut not to be deterred, I then built the same circuit again on another patch of the veroboard using new components and this time I used S8050 transistors. Guess what? No difference.So I then tried adding a resistor (the one in dotted lines on Fig 2) and the brightness of the LEd reduces when A is low and B is high. Once I get down to 390R, the LED no longer lights apart from when both A and B are High (5V) when the logical AND is true and it lights brightly.But really the logic gate still isn't actually working.When A is 0V and B is 5V the output at Y should be below a logic 0 threshold (<0.8V seems acceptable for 5V logic) but it isn'tWhat I have isA=0V B=0V Y=0VA=0V B=5V Y=1.2V (indeterminate logic level)A=5V B=0V Y=0VA=5V B=5V Y=4.6V (acceptable logic 1)Using ohms law this actually tells me that the current 'leaking' through Q1 when base = 0V and it is supposed to be turned off is 1.2/390 = 3mA and this ties in perfectly with the half lit LEDI'm gonna try the same thing tomorrow using a couple of N channel Mosfets so I can see what that does, out of interestIn the mean time can someone please explain 1 - why the circuit does not work as expected and 2 - how to actually make an AND gate out of two transistors that actually works?ThanksRich

author: Andy Watson
author_rank: Super Contributor
timestamp: November 08, 2022, 06:19:11 pm
content: Remeber that BJTs can also be considered as two diodes. Re-draw Fig A but replace Q2 with a pair of diodes that are commoned at the base connection - you should be able to see why the LED turns-on when "power" is applied to input B.

author: chilternview
author_rank: Frequent Contributor
timestamp: November 08, 2022, 06:29:22 pm
content: In the case A=0v, B=5v, remember you have a PN junction from B to E (and B to C) so regardless of Q1 being off, current will flow from B input through Q2.Assuming Vbe of Q2 is about 0.6v and Vdiode is about 2v, the current is (5-2-0.6) / 1120 = 2.1mA which is enough to light your LED.

author: dicky96
author_rank: Regular Contributor
timestamp: November 08, 2022, 06:30:40 pm
content: True but the 'imaginary diodes' in an NPN transistor would be reverse biased so that does not explain ithttps://learn.sparkfun.com/tutorials/transistors/symbols-pins-and-construction

author: dicky96
author_rank: Regular Contributor
timestamp: November 08, 2022, 06:32:35 pm
content: @chilternIn that case where is the current coming from to flow through B-E junction of Q1 when B is 0VeditSorry I meant when the base of Q1 is 0V (measured)and emitter of Q1 is 2.5V+ (measured)

author: Andy Watson
author_rank: Super Contributor
timestamp: November 08, 2022, 06:35:42 pm
content: Quote from: dicky96 on November 08, 2022, 06:30:40 pmThey are not imaginary. BJT = BiPolar JUNCTION Transistor. There are two junctions - diodes. You can measure them with an ohm-meter if you like. Draw them on your diagram - you will find that at least one of the diodes is forward biased.

author: wraper
author_rank: Unknown
timestamp: November 08, 2022, 06:38:34 pm
content: Quote from: dicky96 on November 08, 2022, 06:30:40 pmThey are neither imaginary or reverse biased.

author: dicky96
author_rank: Regular Contributor
timestamp: November 08, 2022, 06:40:19 pm
content: I don't understandThese are the voltages I read on Q1 (showing the 'diode' junctions for NPN transistor)Which one is forward biased?See pic

author: Andy Watson
author_rank: Super Contributor
timestamp: November 08, 2022, 06:43:38 pm
content: I think your problem is with Q2.

author: dicky96
author_rank: Regular Contributor
timestamp: November 08, 2022, 06:52:31 pm
content: I'll accept any valid explanation as I can't figure it out at all so farBear in mind I built the circuit twice using different components (and different types of NPN tansistor BC337 and S8050) on different bits of veroboard and both behave the same wayI would be pretty unlucky to have two faulty Q2 with odd problemsActually ignore the base voltage on Q2 in the attached pic, I didn't measure what it is but it could not be 0.7VAnd looking at it now you are right - Q2 base must be above the emitter voltage so this is where the LED current comes from. YES! And Q2 base must also be above the 2.5V on the collector so that is where that voltage comes from tooOK how to make the circuit work properly? As this circuit is all over the net as an example of an AND gate

author: Andy Watson
author_rank: Super Contributor
timestamp: November 08, 2022, 07:05:17 pm
content: Here:

author: chilternview
author_rank: Frequent Contributor
timestamp: November 08, 2022, 07:21:31 pm
content: Just because it's been posted all over the internet by people who know no better doesn't mean it's correct. You might ask yourself why classic TTL logic doesn't use this sort of topology. Study a 7400 gate schematic, you'll learn a lot.With MOSFET's it's different, you can use stacked devices to form a simple (n)and gate, because there is isolation from gate to s/d.

author: bson
author_rank: Unknown
timestamp: November 08, 2022, 07:28:18 pm
content: Remove the LED.With just say 5V on B's base, 0V on A's base and Vbe = 0.6V, you will see 4.4V across 1kΩ+130Ω = 390µA. 390µA across 130Ω means Y will be at 0.5V.

author: dicky96
author_rank: Regular Contributor
timestamp: November 08, 2022, 08:05:15 pm
content: Thanks guys for the assistance - and I got it by myself in the end with the pointers in the right direction which is very satisfyingCheers

author: amyk
author_rank: Super Contributor
timestamp: November 09, 2022, 05:16:35 am
content: If you really want to experiment with RTL gates I recommend studying the Apollo Guidance Computer. You seem to have discovered yourself why they used all NOR and not a single AND of the form you came up with.

author: mikerj
author_rank: Super Contributor
timestamp: November 09, 2022, 12:01:39 pm
content: Quote from: dicky96 on November 08, 2022, 06:52:31 pmIf you really want to get it working with bipolar transistors you could replace Q2 with a PNP/NPN combination to ensure the base current does not pass through to the output. Otherwise remake the circuit using MOSFETs.

author: jmelson
author_rank: Super Contributor
timestamp: November 09, 2022, 03:52:04 pm
content: Your 1K base resistors are MUCH too low a value. Somewhere between 10K and 22K would be a better choice. Or, you could come up with a diode transistor NAND gate and then put an inverting transistor after it.Jon

author: Zero999
author_rank: Super Contributor
timestamp: November 09, 2022, 07:22:50 pm
content: Since the load is connected to 0V, it's better to use a PNP NOT on the output of an NPN NAND.

author: magic
author_rank: Super Contributor
timestamp: November 09, 2022, 07:54:27 pm
content: There seems to be a risk of Q1 and/or Q2 saturating and failing to drive the PNP, particularly if the latter's Vbe is higher than NPN's.Base resistors would be a good idea. Then, maybe even R2 could be removed, relying on β limits instead.Otherwise, it looks like this circuit could work.

author: ledtester
author_rank: Super Contributor
timestamp: November 11, 2022, 05:11:29 am
content: This page might be the reason why so many people are trying to construct AND gates by stacking transistors in series:http://hyperphysics.phy-astr.gsu.edu/hbase/Electronic/trangate.htmlIt supposedly references the Forrest Mims Engineering Notebook "Digital Logic Circuits". Indeed, on page 6 one finds:

author: Peabody
author_rank: Super Contributor
timestamp: November 11, 2022, 03:08:22 pm
content: Would it not work as expected if you move the LED and its resistor up to the top so the transistors sink current directly to ground?

author: Zero999
author_rank: Super Contributor
timestamp: November 11, 2022, 04:58:19 pm
content: Quote from: ledtester on November 11, 2022, 05:11:29 amYes, I remember it now. I have some of those books. They do contain a few errors.The circuit will work much better with higher value base resistors and a lower emitter resistor.The problem with using an emitter follower is the output voltage is always lower than the input voltage, which limits the number of gates connected in series.Quote from: Peabody on November 11, 2022, 03:08:22 pmBut then it would become a NAND gate.

author: Peabody
author_rank: Super Contributor
timestamp: November 11, 2022, 07:24:07 pm
content: Quote from: Zero999 on November 11, 2022, 04:58:19 pmWell, when both inputs are high, the LED will turn on, which is what the original circuit was supposed to do. That sounds pretty AND to me.

author: ledtester
author_rank: Super Contributor
timestamp: November 11, 2022, 07:31:39 pm
content: Quote from: Peabody on November 11, 2022, 07:24:07 pmYou just have to be consistent in how you define your logic HI and LOW. If a logic HI is something that can sink current from a load then consider how that would be the input to another logic gate.

author: Zero999
author_rank: Super Contributor
timestamp: November 11, 2022, 07:33:52 pm
content: Quote from: Peabody on November 11, 2022, 07:24:07 pmDoes the 7400 become a quad AND gate if LEDs are connected between the outputs and VCC?I think the idea is to use it as an AND gate like the 7408.

author: strawberry
author_rank: Super Contributor
timestamp: November 11, 2022, 08:19:17 pm
content: high base resistor, will be slow speed

author: Zero999
author_rank: Super Contributor
timestamp: November 11, 2022, 09:28:29 pm
content: Quote from: strawberry on November 11, 2022, 08:19:17 pmI don't think it's supposed to be fast. It's just a demonstration.