# AND with XOR gates not working together

I'm trying to make a circuit with both a AND gate and XOR gate as outputs. I thought about using a NOT gate, so that the OR gate only functions when AND is off (giving XOR).

I succeeded in making all these 3 gates work separatedly, but when I put them together, it doesn't work.

-If I remove the right parts of the following circuit, the AND works correctly. -If I remove the AND part, the OR functions correctly as well -However, if I keep all together, both leds are always turned on.

Then with my multimeter I saw that there was nothing going on from the AND part to the mosfet on the right (so nothing between M1's source and M2's gate). I would have expected to have a voltage diff of 0V between M2's D-S, but I got around 5V, so I can't seem to use it as a NOT to prevent current from going to the OR (XOR)..

I thought about adding resistors around but I really don't know how I can make it work. Would having P type mosfets help ? I'm a bit lost..

Thanks

Edit: Now added a pic showing the voltages I got (Gray: A and B, red: Only A, blue: Only B), with changes suggested by Immibis.

simulate this circuit – Schematic created using CircuitLab

• To start debugging properly, you should check the voltage in the gates of your mosfet with different input of your truth table. Plus 2 circuits working correctly separatly don't mean they will work put together, there must a be a problem of load somewhere – MathieuL Mar 17 '16 at 1:18
• If your "AND" LED is dropping a volt or two, and D4 is dropping about .7 Volts, that doesn't leave much for M2... – Tyler Mar 17 '16 at 2:07
• Consider if M2 gets to turn on and its drain is low, what happens to the voltages at D1 and D2. The implementation can feedback and alter the inputs. – rioraxe Mar 17 '16 at 2:29
• And I really do hope your power supply is shown backwards. – WhatRoughBeast Mar 17 '16 at 3:25
• 20k might be too high. Say your XOR LED draws 10 mA when on -- that means you need to drop .01 * 20000 = 200 V across that resistor – Swarles Barkely Mar 17 '16 at 4:33

## 3 Answers

Working with your latest (unconventional) circuit (with the extra resistors) you do not quite get the XOR function. Look at V(xor) between 3 and 4 seconds.

See LT Simulation below:

If however you were to eliminate D4 and add a resistor before your AND LED you get closer to what you are after.

See LT Simulation below:

simulate this circuit – Schematic created using CircuitLab

Figure 1. Crazy LED OR, AND + XOR logic.

This might work.

• OR: Pressing A or B will forward bias D1 or D2 respectively turning on the OR LED.
• AND: Pressing A will give positive supply to the AND LED. Pressing B will turn on M1 which will give a negative supply to AND LED. Both are required for the LED to light. M1 gate will discharge through D2, R7 and the OR gate when 'B' is released.
• XOR: With both A and B off or on there is no potential difference across XOR LED. If either one is on current can flow through the bridge, the XOR LED and to GND through the resistor on the line not pulled high.

I can't imagine what practical use this circuit could be.

• It seems like it could work, and I like your explanation. I'm designing an adder, so I need both AND and XOR on both inputs. – MB101874 Mar 17 '16 at 14:57
• Neither your circuit or mine is going to be any use for an adder because the signals aren't referenced to ground properly. For example, how would you feed your AND signal to another gate? Neither the top of the LED or the bottom of it gives the AND logic state. My XOR signal would be even worse. Edit your question and explain what the design constraints are. e.g., "I can use resistors, PNP, NPN, P and N-channel FETs," etc. Explain why you're using 12 V. Look at datasheets for CMOS or TTL logic and see how they made these gates in the 1970s. Explain why you can't use logic chips. – Transistor Mar 17 '16 at 15:07

Interesting circuit.

When both switches are off, there is no current flowing, so both LEDs are off.

When the gate-switch (for the AND-circuit) is on, and the other off, the path of least resistance is through the 1K resistor, D1, R6, and the XOR LED. If the LED's drop is 1.8V and the diode's 0.7V, then 1K + 20K resistors across 12-2.5 = 9.5V. This leads to around $$i_\text{XOR-LED}\approx\frac{9.5}{21\times10^{3}}\approx 0.45\;\text{mA},$$ which is much less than the usual 20 mA needed in order to light the LED.

When the gate-switch is off and the other is on, we have a similar situation.

When both switches are on, and the diodes disconnected, the resistor divider at the gate would switch M1 on; since the gate is close to 12V and the main current path is 1K-resistor, drain-source, then the AND-LED. Notice that the drain voltage will be around 1.9-2.0V, and thus the current in this path around $$i = \frac{v}{R} = \frac{12-2}{1000}=10\;\text{mA},$$ again a bit too low for the LED.

But when you connect the XOR-diodes, things happen to the circuit. Current is allowed to flow through the XOR-diodes and across the XOR-transistor. Because the 1M-resistors are so large, this is quite likely. Only a simulation or careful analysis will prove this, but my hunch is that M1 will be off and M2 on, at least judging by your troubleshooting efforts.

• When you say the gate-switch is on (A) but not B, what do you mean by 1K+1K resistors ? I thought the 2nd would be the one on B, but since it's off, it shouldn't be included in this calculation, right ? – MB101874 Mar 17 '16 at 14:56
• You are right, I misread the 20K resistor for a 1K one. – Pål-Kristian Engstad Mar 17 '16 at 18:02