Skip to content
You Start with one site
Amounts in Start with one site
Electronics · Concept

Logic gates

One idea Beginner 5 min read
Found this useful?

A car starts only when the key is turned and the brake is pressed. A room light comes on when one door switch or the other is pressed. Each of these is a small decision with a fixed rule, and a logic gate is the circuit that makes one such decision: it takes inputs that are each 0 or 1 and gives one output that is 0 or 1.

ANDThe output is 1 only when both inputs are 1.Key and brake
ORThe output is 1 when at least one input is 1.Either door switch
NOTOne input. The output is the opposite.0 gives 1, 1 gives 0

See it

Predict first

A lamp is connected to the output of an OR gate. Both inputs, A and B, are 1. Is the lamp on?

See it: one gate, two inputs, one output

Gate
Inputs A, B
Output Y

A thick line carries a 1 and a thin line carries a 0. The lamp is the output, Y. The table on the right lists the output for all four combinations of inputs, and the marked row is the one you have set. A small circle on the tip of a gate means NOT: the output is turned over.

The idea

A digital signal has only two values: a low voltage, written 0, and a high voltage, written 1. A gate applies one fixed rule to its inputs. AND gives 1 only when both inputs are 1. OR gives 1 when at least one input is 1. NOT has one input and gives the opposite.

Three more are built from these. NAND and NOR are AND and OR followed by NOT. XOR gives 1 when the two inputs differ.

A truth table lists the output for every combination of inputs.

rows = 2n

n is the number of inputs: 2 inputs give 4 rows, 3 inputs give 8 rows

Every digital chip is made of these few gates in very large numbers. One limit: a real gate needs a short time to answer, about 7 ns for a common type.

One worked number

The question

A pump may run only when the tank has water (A = 1) and the operator switch is on (B = 1). Which gate gives the run signal Y, and what is Y when the tank has water but the switch is off?

Show the worked solution, 3 steps
  1. Write what you want for all four cases

    Two inputs give 2² = 4 cases. The pump runs in one of them only: A = 1 and B = 1. So the Y column reads 0, 0, 0, 1.

  2. Find the gate with that table

    A single 1, in the row where both inputs are 1, is the table of AND.

  3. Read the row asked for

    Tank has water, switch off: A = 1, B = 0. AND gives Y = 0, and the pump stays off. Check it in the figure: choose AND, then change B to 0.

The mistake to avoid

OR does not mean "one or the other, but not both". That is the daily meaning of the word, and it is the rule of XOR. An OR gate also gives 1 when both inputs are 1. An alarm that must sound when either of two doors opens needs OR: with XOR it would go silent when both doors are open.

A second trap: an input with nothing connected is not a 0. It floats, and the gate may read it as either value. Every input needs a definite level, which is the job of a pull-up resistor (or a pull-down, its mirror to 0 V). Unused inputs of a gate chip also go to 0 V or to the supply.

Check yourself

Question 1

A safety circuit has three inputs: guard closed, pressure normal, start pressed. How many rows does its truth table have?

Question 2

A NAND gate has A = 1 and B = 0. What is its output?

Question 3

A tank has two level sensors that should always agree. You want a warning lamp that is on only when they disagree. Which gate?

Where you meet it

  • Machine interlocksA press or a conveyor runs only when the guard is closed and the stop button is released: an AND of several inputs. Where people can be hurt, that AND sits in a two-channel safety relay, never in a single gate.
  • Alarm panelsOne siren serves many sensors. Any one of them can set it off: an OR.
  • Data checksMeters and drives use XOR to detect a bit that changed on its way along a cable.
Key points
  • A gate takes inputs of 0 or 1 and gives one output by a fixed rule.
  • AND: both. OR: at least one. NOT: the opposite. XOR: the inputs differ.
  • A truth table lists every case. It has 2n rows for n inputs.
  • OR is also 1 when both inputs are 1. An unconnected input is not a 0.
Found this useful?

Discussion

    Comments show your name. Be kind, stay on the topic.