How Logic Gates are Built from Transistors

How Logic Gates are Built from Transistors

This article assumes an understanding of electronic logic gates. More about the subject can be found in this article:

If we recall the function of an AND logic gate:

The symbol for an AND logic gate

It has a truth table like this:

Input A Input B Output
0 0 0
0 1 0
1 0 0
1 1 1

So this means the output of the gate is “1” only when both of the inputs are at “1”.

If we now look at the following circuit consisting of a lamp and two switches. The switches are in series in the path to the lamp. The lamp will only light when both switches are pressed. If only one switch is pressed the lamp will not light.

A circuit showing the placement of switches in a circuit to form the equivalent of an AND logic gate.

If we consider the switches to be the inputs and the lamp the output, the circuit behaves like an AND gate.

Now let’s take a look at an OR gate.

The symbol for an OR logic gate

The truth table for the OR gate is as follows:

Input A Input B Output
0 0 0
0 1 1
1 0 1
1 1 1

OR gates output a “1” if either or both of inputs are “1”.

We could rearrange the circuit like this to behave like an OR gate:

An OR gate equivalent formed of two switches in parallel.

The bulb will light if either (or both) of the two switches are pressed. This circuit behaves like an OR gate.

A transistor is a component that can behave like an electronically activated switch. Instead of being activated by being physically pressed it is activated by a voltage. The component has three legs. The collector and emitter are like the connections either side of the switch through which the current flows when the switch is pressed. The base defines whether the switch is pressed. If there is a voltage at the base, this is equivalent to the switch being pressed. If there is no voltage then the switch is not pressed.

The electronic symbol for a transistor is show below (left) next to a switch for comparison:

Circuit showing the replacement of switches with transistors to form an AND gate.

We can replace the switches in the circuit for the AND gate with transistors like this:

Now we can see that only if both of the transistor inputs, A and B, have a voltage applied, will the current flow to cause the lamp to light.

This circuit is almost correct, however if we actually want to build the circuit in practice we need to add some additional components called resistors that restrict the flow of current. These components do not change the logic of how the circuit works at all, but are needed to deal with practical electrical problems that ocurr when using transistors:

Circuit diagram for an AND logic gate built from transistors, also showing the required resistors.

There is a resistor (rectangle symbol) at the base input to each of the transistors because the base can only handle a specific flow of current. If the flow of current is too high, the transistor will be damaged. The resistor limits how much current will flow to the base such that it is within the tolerances of the transistor.

There is a resistor connected between the output of the AND gate and the negative of the battery. This is known as a pull-down resistor and ensures that the output is set to zero (battery negative or ground) when one or both of the transistors are not activated and the AND gate should be outputting a “0”. If there were no connection to ground here then the output would be floating when both of the transistors were inactive.

A floating output means that the voltage present is undefined and could be anything. By adding a connection to ground we ensure that the output is definitely zero when the transistors are off. A resistor is needed to prevent a short circuit. In electronics we must never connect the two battery terminals together directly as this causes a large flow of current which would damage the circuit. We can see that if the output were directly connected to ground instead (without the resistor) we would get a short circuit in the situation when both of the transistors were turned on. The resistor limits the current flow to ground.

But what about a NOT gate (inverter)? How does that work?

The inverter can be built with only a single transistor using a circuit like below:

The way this works is when there is a zero at the input, the transistor is switched off and is blocking current from flowing between the collector and emitter. The positive from the battery passes through the top resistor. It cannot go through the transistor and so goes to the output, producing a “1”. However, when there in a positive voltage at the input (a “1”), the transistor is activated and current can flow. There is now a path to ground (where electricity prefer to travel) and so the output is now at zero. The resistor at the collector is required to stop the two battery terminals becoming directly connected when the transistor is activated and is called a pull-up (the “up” referring to the positive battery terminal).

Credt: Transistor image by Benedikt.Seidl