Online Book Reader

Home Category

Code_ The Hidden Language of Computer Hardware and Software - Charles Petzold [44]

By Root 1568 0
gate. The bottom switch triggers the second relay in the second AND gate.

If we think of the absence of a voltage as a 0, and the presence of a voltage as a 1, the output of the AND gate is dependent on inputs like this:

As with the two switches wired in series, the AND gate can also be described in this little table:

AND

0

1

0

0

0

1

0

1

It's also possible to make AND gates with more than two inputs. For example, suppose you connect three relays in series:

The lightbulb lights up only if all three switches are closed. This configuration is expressed by this symbol:

It's called a 3-input AND gate.

The next logic gate involves two relays that are wired in parallel like this:

Notice that the outputs of the two relays are connected to each other. This connected output then provides power for the lightbulb. Either one of the two relays is enough to light the bulb. For example, if we close the top switch, the bulb lights up. The bulb is getting power from the left relay.

Similarly, if we leave the top switch open but close the bottom switch, the bulb lights up:

The bulb also lights if both switches are closed:

What we have here is a situation in which the bulb lights up if the top switch or the bottom switch is closed. The key word here is or, so this is called the OR gate. Electrical engineers use a symbol for the OR gate that looks like this:

It's somewhat similar to the symbol for the AND gate except that the input side is rounded, much like the O in OR. (That might help you to keep them straight.)

The output of the OR gate supplies a voltage if either of the two inputs has a voltage. Again, if we say that the absence of a voltage is 0 and the presence of a voltage is 1, the OR gate has four possible states:

In the same way that we summarized the output of the AND gate, we can summarize the output of the OR gate:

OR

0

1

0

0

1

1

1

1

OR gates can also have more than two inputs. (The output of such a gate is 1 if any of the inputs are 1; the output is 0 only if all the outputs are 0.)

Earlier I explained how the relays that we're using are called double-throw relays because an output can be connected two different ways. Normally, the bulb isn't lit when the switch is open:

When the switch is closed, the bulb lights up.

Alternatively, you can use the other contact so that the bulb is lit when the switch is open:

In this case, the lightbulb goes out when you close the switch. A single relay wired in this way is called an inverter. An inverter isn't a logic gate (logic gates always have two or more inputs), but it's often very useful nonetheless. It's represented by a special symbol that looks like this:

It's called an inverter because it inverts 0 (no voltage) to 1 (voltage) and vice versa:

With the inverter, the AND gate, and the OR gate, we can start wiring the control panel to automate a choice of the ideal kitty. Let's begin with the switches. The first switch is closed for female and open for male. Thus we can generate two signals that we'll call F and M, like this:

When F is 1, M will be 0 and vice versa. Similarly, the second switch is closed for a neutered cat and open for an unneutered cat:

The next two switches are more complicated. In various combinations, these switches must indicate four different colors. Here are the two switches, both wired to a voltage:

When both switches are open (as shown), they indicate the color white. Here's how to use two inverters and one AND gate to generate a signal I'll call W, which is a voltage (1) if you select a white cat and not a voltage (0) if not:

When the switches are open, the inputs to both inverters are 0. The outputs of the inverters (which are inputs to the AND gate) are thus both 1. That means the output of the AND gate is 1. If either of the switches is closed, the output of the AND gate will be a 0.

To indicate a black cat, we close the first switch. This can be realized using one inverter and an AND gate:

The output of the AND gate will be 1 only if the first switch is closed and

Return Main Page Previous Page Next Page

®Online Book Reader