Digital Circuit Design
Summary: In this laboratory, you will use digital
circuit design software to explore some fundamental components of
The software we will use for this lab is called LogiSim, or
more formally, the "Logic Circuit Simulator." It is a nice program for
- Open a terminal window, and move to your directory for 105 labs:
- Copy LogiSim to your directory with the following command:
cp ~davisjan/share/csc105/logisim.jar .
- You can now run LogiSim with the command:
java -jar logisim.jar &
The larger portion of the window that appears with a grid of dots is
the circuit drawing area.
Part I: Getting Started with LogiSim
Take a look at the top of the window beneath the menus. You should
see some icons: a hand, an arrow, a line, the letter A, and digital
logic gates. This row of icons is also a sort of menu: you can click on
one of them to activate it and then place an item onto the drawing area
of the LogiSim window to add them to a circuit you are building.
Exercise 1: Input switches
- Let's start with the center icon, which is a green circle inside
a square. Click on this icon. Now you may click somewhere on the
drawing area. You should find that this creates a copy of the icon.
This icon represents a switch, and it is used to specify an input value
to a circuit.
- Click the "hand" from the row of icons to change into
"simulation" mode. (This also tells LogiSim that we do not want to draw
any more input switches.)
- Click in the inner square of the switch (on your drawing area)
to see how it works. Each time you click the switch, this should toggle
a green "light" on and off inside the switch. When the light is on,
this means the input voltage is high (true or 1); when it is off, the
voltage is low (false or 0).
Exercise 2: Wires
- Next let's experiment with adding wires to your circuit. To do
this, click the arrow icon.
- Move the mouse to the right side of your input switch where
there is a green dot along the side of the square. When you move your
mouse there, you should see a green circle appear. This tells you that
when you click, it will begin connecting a wire from that switch at
- Click and drag the mouse to the right to add a wire. Wherever
you release the mouse button will be the endpoint of the wire.
- Click at the right endpoint of your wire and drag the mouse
downward to add another wire segment, releasing it where you like. Note
that the green circle follows your mouse, telling you where a wire
would be atttached if you were to click.
- Continue clicking to add a few more wire segments.
Exercise 3: Moving Circuit Elements
- Clicking the arrow from the icon menu (which you have already
done) also allows you to reposition elements in your circuit drawing.
- You can now move your switch to a new location in the drawing
area by simply clicking and dragging it. Go ahead and give this a try.
- Unfortunately, you cannot move wires that way. Instead, you must
click and drag your mouse on the drawing window to draw a rectangle
around the wires you want to move, then lift the mouse button. Notice
that the wires inside the box are now selected (white boxes appear at
their endpoints). You can move move all of the selected wires by
dragging one to a new location. (You probably won't need to move wires
often, but go ahead and give it a try.)
- To unselect these wires, click anywhere on the drawing area
(except on another circuit element).
- Like many applications you may be used to, you can also select
multiple circuit elements (including wires), by holding down the Shift
key as you click on them. Give that a try.
Exercise 4: Deleting circuit elements
- Now lets delete some or all of the wires you just drew. To do
this, begin by selecting some of the wires using either strategy given
above. (Don't forget to make sure the arrow from the icon menu is
- To delete the selected elements, simply type the "Delete" key.
You may also use the usual cut/copy/paste clipboard operations found
under the edit menu.
Exercise 5: Output Pins (LEDs)
Another icon in the icon menu consists of two concentric circles (the
inside being green). This icon represents an LED (or light-emitting diode) that can be
used to show the logical output of a circuit you have drawn.
Similar to the light inside the switch, when the LED is on this
that it is receiving a logical one, and when it is off this indicates a
- Place an output pin (LED) somewhere in your drawing area.
- Draw a wire from your input switch to the LED.
- Now click the input switch to turn it on and off. (Don't forget
to switch to simulation mode.) If your circuit is connected correctly,
you should see the LED turn on and off as well.
Exercise 6: Logic gates
- Find the icon for an AND-Gate among the icons at the
bottom of the window, and click to drop a gate into your drawing area.
If you have look carefully, you should see tiny blue dots at each of
the input and output points of the gate. These are points where you can
connect the gate to other elements of your circuit.
- Connect two input switches to two input points of your AND-gate,
and an LED to its output point. You can do this by placing the various
elements in direct contact with each other, or by drawing wires between
the points you want to connect.
- Test all the possible input combinations (i.e., both switches
off, switch one on and switch two off, etc) to convince yourself that
your circuit and the AND-gate are working correctly.
- Finally, do the same with both the OR-gate and the NOT-gate
icons. (I.e., connect each of these icons to input switches and LEDs,
and then convince yourself that they generate the correct output for
each input combination).
Part II: Your First Digital Circuits
In this part, you will start drawing real circuits. You should
begin by creating a new drawing: select "New" from the File menu.
Draw a circuit diagram that uses two AND-gates to create a
"three-input AND-gate." While the default AND-gates in LogiSim have
several inputs, you should treat them as if they only had two inputs.
Recall that we discussed this circuit in class: its output
should be (x1 AND x2 AND x3), where x1, x2,
and x3 are the circuit's three input values.
- Test your circuit by trying all eight input combinations (i.e.,
all inputs off, only x1 on, etc). Your output LED should only
light up when all of the input switches are on.
- Save your circuit by selecting "Save" from the File menu. Please
give it the name AND-3.circ.
- Now, in the Linux terminal window, look at a listing of the
files in your 105 directory. You should see that a file named AND-3.circ
Recall from class the concept of the "XOR" operator. As shown in the
table below, (x1 XOR x2) should be true when exactly one of
inputs x1 and x2 are true.
||x1 XOR x2
- Please begin by creating a new drawing (select "New" from the
- Refer to your notes from class to remember what the circuit
diagram that implements the XOR operator (with AND, OR, and NOT-gates)
looks like. Then draw the circuit diagram, noting that is ok for wires
in your diagram to cross one another; the circuit will behave as if the
wires are not touching one another. However, if one wire starts from
somewhere along another wire, the two will be "soldered," as indicated
by a dot covering the intersection.
- Test your circuit to make sure that it produces the correct
output value for each of the input combinations.
- Save your drawing in a file called XOR.circ
Part III: Binary Adder
Recall the "half-adder" circuit we drew in class. This circuit has two
and two outputs. The inputs are two bits that we want to add together,
outputs are the "carry-out" and "sum" bits that result. The logic table
for the circuit is given below.
Please review your notes to remember what the circuit diagram for a
half-adder looks like. You should see that the circuit uses an
XOR-gate. Since you have just created an XOR-gate it would be possible
to cut and paste your XOR circuit to use here. However, there is also
another way: LogiSim provides an XOR gate, but you have to know where
to look for it. We'll do that next.
If the steps above did not work for you, please ask for help.
- Please create a new drawing. (You may close any of the others
after you create a new, blank drawing.)
- On the left side of your window is a tree with at least two
folders displayed, including one entitled "Base" and the other entitled
"Gates". Click the triangle to the left of the "Gates" folder to expand
- Now you should be able to scroll down and see a whole host of
gates, some familiar and some new.
- One of the gates that appears should be the XOR gate. You may
click it to select, just as you did the items from the icon menu. Now
you can drop XOR gates into your drawing.
- Once you have an XOR gate, implement a half-adder circuit in
LogiSim. You may find it helpful to arrange your two outputs such that
"carry-out" is to the left of "sum". This way, the two output bits can
be read as a normal two-digit binary number, making it easy to test
Remember that you can connect wires by starting one wire where
it touches another.
- Click the "A" in the menu to activate the text tool. Use this to
label the inputs and outputs of your half-adder (e.g., with the same
names that appear in the truth table above.)
- Test your circuit. It should display the sum of the two input
bits, which will always be 0, 1, or 2 (displayed in binary).
- Save your work to a file called half-adder.circ
Part IV: Flip-flops
Please review your notes to recall what the circuit diagram for a
flip-flop looks like. (Actually, it is worth noting that there are
several different ways to implement flip-flops, but we will work with
the version drawn in class.)
Here is the logic table for this circuit. Remember that the first
three columns are input values, and the last column is the sole output.
(Notice that I have left out the last two lines of the logic table,
where both x1 and x2 are 1, because these input
combinations are not used in practice.)
Before you implement the flip-flop circuit, it may
be helpful to notice the following.
- Select the AND-gate icon from the icon menu of icons. Note that
a table appears in the bottom-left portion of the LogiSim window.
- One of the entries in the table is "Facing", and it has the
value "East." Click on "East" to activate a pull down menu.
- You may select "West" to create AND gates that face the reverse
direction, as the circuit we drew in class does.
Now you are ready to build the flip-flop circuit. Please do so. Be
sure to label your inputs and outputs!
Test your circuit as follows:
Congratulations! You have created a one-bit memory element!
- Set x1 = 1 and x2 = 0. This should "set" the
output to 1.
- Now "lower" the x1 input value, so that both inputs
are off (0). You should see that the output value is unaffected by
this. It should continue to hold it's previous value (1).
- Now "raise" the x2 input to 1. At this point, you
should have x1 = 0 and x2 = 1. The result should be
that the output is "reset" to 0.
- Finally, "lower" x2 again, and you should find that
your circuit once again holds its previous value (0).
Save your work in a file called flip-flop.circ
You will be called upon to print some of your circuits for turn-in as
homework. You may follow these steps to do so:
- Start LogiSim, using steps (a) and (c) from Preparation
(if you haven't already).
- Open your drawing using "New" from the File menu (if it is not
- Select "Print..." from the File menu.
- A dialog box titled "Print Parameters" will appear. Leave
everything as it is and click "OK."
- Another dialog box titled "Print" should appear. From the pull
down menu called "Name:" be sure that the entry "duerer" is chosen.
- Click "Print"
- Repeat these steps, probably from (b) on, for any other files
you wish to print.
- The printer duerer is located in SCI 3810, the small
room adjacent to our classroom.
For Those With Extra Time
There is an old puzzle in which a farmer (F) must transport a wolf
(W), a goose (G), and a sack of corn (C) across a river, subject to
the conditions that the farmer can only transport one of W, G, or C
across the river at a time, and if unattended, the wolf will eat the
goose and the goose will eat the corn. Let F=0 indicate the presence
of the farmer on the west bank of the river and F=1 indicate presence
on the east bank. Make similar assumptions for W, G, and C.
Derive a truth table defining a function which gives 1 if the
farmer is in danger of losing the goose or the corn. Assume that if an
item (or farmer) is not on one side of the river it must be on the
other side. In other words, fill in the following table with the
How did you derive the truth table? You probably thought about
which settings of the variables F,W,C and G indicated an unsafe state.
For instance, (W AND G AND NOT F) would be one indicator
of an unsafe state.
Write a logical sentence using AND, OR, and NOT that expresses the
truth table above.
Implement your logic expression as a circuit in LogiSim. Verify that
it is correct by testing the possible states with input and output
A half-adder basically stands in isolation because it can't take the
carry from a previous column as input. The full-adder therefore
incorporates not only the two bits of a number to sum, but also the
carry-out bit from the previous column as a "carry-in" input bit.
The truth table for a full-adder would look like the following:
Complete the truth table for a full-adder. Essentially, you are
calculating the sum of the three bits for each row.
Using the truth table, draw a circuit for which the
carry-out value is true under the appropriate conditions. Note that if
you think carefully about the cases when carry-in is 0 and carry-in is
1 separately, you may be able to produce a simpler circuit.
Using the truth table, draw a circuit for which the sum value is true
under the appropriate conditions. Note that if you think carefully
about the cases when carry-in is 0 and carry-in is 1 separately, you
may be able to produce a simpler circuit.
Combine your two circuit designs, implementing them in LogiSim.
Test the input values to make sure they produce the right output value.