Author Topic: Why does this two transistor AND gate not work as expected?  (Read 6966 times)

0 Members and 2 Guests are viewing this topic.

Offline dicky96Topic starter

  • Regular Contributor
  • *
  • Posts: 209
  • Country: es
    • Learn Electronics Repair
Why does this two transistor AND gate not work as expected?
« on: November 08, 2022, 06:05:20 pm »
Hi guys
I'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 here

The 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 0V
For the other logic states (all measured with DMM) and using patch wires to connect A and/or B to 5V

A=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 voltages
Q1 Collector is 5.1V, Base is 0V, Emitter is 2.5V
Q2 Collector is 2.5V, Base is 0V, Emitter is 0V

In the conditions A=0V B=5V 
Q1 Collector is 5.1V, Base is 0V, Emitter is 2.5V
Q2 Collector is 2.5V, Base is 0.75V, Emitter is 2.3V LED is on

So somehow Q1 turns on even when the base is 0V

Ahhh 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 difference  :-//

So I remove Q1 and test it in my DCA55 - it is fine.  But I replace it with a new one anyway - no difference
Then I think it may be something stupid with the veroboard (tracks not cut properly) but I can't find any problem there

But 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't 

What I have is

A=0V B=0V Y=0V
A=0V B=5V Y=1.2V (indeterminate logic level)
A=5V B=0V Y=0V
A=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 LED

I'm gonna try the same thing tomorrow using a couple of N channel Mosfets so I can see what that does, out of interest

In 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?

Thanks
Rich
« Last Edit: November 08, 2022, 06:09:18 pm by dicky96 »
Follow me on Youtube
 

Online Andy Watson

  • Super Contributor
  • ***
  • Posts: 2102
Re: Why does this two transistor AND gate not work as expected?
« Reply #1 on: November 08, 2022, 06:19:11 pm »
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.
 

Offline chilternview

  • Regular Contributor
  • *
  • Posts: 160
  • Country: gb
Re: Why does this two transistor AND gate not work as expected?
« Reply #2 on: November 08, 2022, 06:29:22 pm »
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.

 

Offline dicky96Topic starter

  • Regular Contributor
  • *
  • Posts: 209
  • Country: es
    • Learn Electronics Repair
Re: Why does this two transistor AND gate not work as expected?
« Reply #3 on: November 08, 2022, 06:30:40 pm »
True but the 'imaginary diodes' in an NPN transistor would be reverse biased so that does not explain it

https://learn.sparkfun.com/tutorials/transistors/symbols-pins-and-construction
Follow me on Youtube
 

Offline dicky96Topic starter

  • Regular Contributor
  • *
  • Posts: 209
  • Country: es
    • Learn Electronics Repair
Re: Why does this two transistor AND gate not work as expected?
« Reply #4 on: November 08, 2022, 06:32:35 pm »
@chiltern
In that case where is the current coming from to flow through B-E junction of Q1 when B is 0V

edit
Sorry I meant when the base of Q1 is 0V (measured)and emitter of Q1 is 2.5V+ (measured)
« Last Edit: November 08, 2022, 06:35:16 pm by dicky96 »
Follow me on Youtube
 

Online Andy Watson

  • Super Contributor
  • ***
  • Posts: 2102
Re: Why does this two transistor AND gate not work as expected?
« Reply #5 on: November 08, 2022, 06:35:42 pm »
True but the 'imaginary diodes' in an NPN transistor would be reverse biased so that does not explain it
They 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.
 

Online wraper

  • Supporter
  • ****
  • Posts: 17273
  • Country: lv
Re: Why does this two transistor AND gate not work as expected?
« Reply #6 on: November 08, 2022, 06:38:34 pm »
True but the 'imaginary diodes' in an NPN transistor would be reverse biased so that does not explain it

https://learn.sparkfun.com/tutorials/transistors/symbols-pins-and-construction
They are neither imaginary or reverse biased.

 

Offline dicky96Topic starter

  • Regular Contributor
  • *
  • Posts: 209
  • Country: es
    • Learn Electronics Repair
Re: Why does this two transistor AND gate not work as expected?
« Reply #7 on: November 08, 2022, 06:40:19 pm »
I don't understand  :-//
These are the voltages I read on Q1 (showing the 'diode' junctions for NPN transistor)

Which one is forward biased?

See pic

Follow me on Youtube
 

Online Andy Watson

  • Super Contributor
  • ***
  • Posts: 2102
Re: Why does this two transistor AND gate not work as expected?
« Reply #8 on: November 08, 2022, 06:43:38 pm »
I think your problem is with Q2.
 

Offline dicky96Topic starter

  • Regular Contributor
  • *
  • Posts: 209
  • Country: es
    • Learn Electronics Repair
Re: Why does this two transistor AND gate not work as expected?
« Reply #9 on: November 08, 2022, 06:52:31 pm »
I'll accept any valid explanation as I can't figure it out at all so far  :) 

Bear 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 way
I would be pretty unlucky to have two faulty Q2 with odd problems

Actually ignore the base voltage on Q2 in the attached pic, I didn't measure what it is but it could not be 0.7V

And 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 too

OK how to make the circuit work properly?  As this circuit is all over the net as an example of an AND gate
« Last Edit: November 08, 2022, 06:58:16 pm by dicky96 »
Follow me on Youtube
 

Online Andy Watson

  • Super Contributor
  • ***
  • Posts: 2102
Re: Why does this two transistor AND gate not work as expected?
« Reply #10 on: November 08, 2022, 07:05:17 pm »
Here:
 

Offline chilternview

  • Regular Contributor
  • *
  • Posts: 160
  • Country: gb
Re: Why does this two transistor AND gate not work as expected?
« Reply #11 on: November 08, 2022, 07:21:31 pm »
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.
 
The following users thanked this post: amyk

Online bson

  • Supporter
  • ****
  • Posts: 2311
  • Country: us
Re: Why does this two transistor AND gate not work as expected?
« Reply #12 on: November 08, 2022, 07:28:18 pm »
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.

 

Offline dicky96Topic starter

  • Regular Contributor
  • *
  • Posts: 209
  • Country: es
    • Learn Electronics Repair
Re: Why does this two transistor AND gate not work as expected?
« Reply #13 on: November 08, 2022, 08:05:15 pm »
Thanks guys for the assistance - and I got it by myself in the end with the pointers in the right direction which is very satisfying  :-+

Cheers
Follow me on Youtube
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8331
Re: Why does this two transistor AND gate not work as expected?
« Reply #14 on: November 09, 2022, 05:16:35 am »
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.
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3290
  • Country: gb
Re: Why does this two transistor AND gate not work as expected?
« Reply #15 on: November 09, 2022, 12:01:39 pm »
OK how to make the circuit work properly?  As this circuit is all over the net as an example of an AND gate

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

 

Offline jmelson

  • Super Contributor
  • ***
  • Posts: 2795
  • Country: us
Re: Why does this two transistor AND gate not work as expected?
« Reply #16 on: November 09, 2022, 03:52:04 pm »
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
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19672
  • Country: gb
  • 0999
Re: Why does this two transistor AND gate not work as expected?
« Reply #17 on: November 09, 2022, 07:22:50 pm »
Since the load is connected to 0V, it's better to use a PNP NOT on the output of an NPN NAND.
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 6916
  • Country: pl
Re: Why does this two transistor AND gate not work as expected?
« Reply #18 on: November 09, 2022, 07:54:27 pm »
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.
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3109
  • Country: us
Re: Why does this two transistor AND gate not work as expected?
« Reply #19 on: November 11, 2022, 05:11:29 am »
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.html

It supposedly references the Forrest Mims Engineering Notebook "Digital Logic Circuits". Indeed, on page 6 one finds:

1636616-0
« Last Edit: November 11, 2022, 04:40:25 pm by ledtester »
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2084
  • Country: us
Re: Why does this two transistor AND gate not work as expected?
« Reply #20 on: November 11, 2022, 03:08:22 pm »
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?
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19672
  • Country: gb
  • 0999
Re: Why does this two transistor AND gate not work as expected?
« Reply #21 on: November 11, 2022, 04:58:19 pm »
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.html

It supposedly references the Forrest Mims publication "Digital Logic Circuits". Indeed, on page 6 one finds:
Yes, 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.


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?
But then it would become a NAND gate.
« Last Edit: November 11, 2022, 06:16:44 pm by Zero999 »
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2084
  • Country: us
Re: Why does this two transistor AND gate not work as expected?
« Reply #22 on: November 11, 2022, 07:24:07 pm »
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?
But then it would become a NAND gate.

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

 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3109
  • Country: us
Re: Why does this two transistor AND gate not work as expected?
« Reply #23 on: November 11, 2022, 07:31:39 pm »
Well, 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.

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

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19672
  • Country: gb
  • 0999
Re: Why does this two transistor AND gate not work as expected?
« Reply #24 on: November 11, 2022, 07:33:52 pm »
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?
But then it would become a NAND gate.

Well, 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.
Does 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.
« Last Edit: November 11, 2022, 07:35:40 pm by Zero999 »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf