Lab 2: Circuits Objectives to use a circuit simulator to verify circuits designed to implement a particular truth table to practice designing circuits to implement a particular logical formula A. Truth tables and circuits Figure 2.1: An example circuit. Complete a truth table for the circuit in Figure 2.1, with your predicted outputs in the “predicted” column below. This will not involve using the computer. (The “intermediate work” column is for any intermediate work you may want. Leave the “actual” column blank.) intermediate steps Input x y predicted output actual output z Your predicted outputs constitute a hypothesis for how the circuit will work. To gain further evidence for this hypothesis, construct a circuit using a simulator, using the steps below. Then, use this constructed circuit to complete the “actual” column, thus verifying your predictions. Explain any divergence from your hypothesis. Using the circuit simulator To test your hypothesis, we’ll use a program called Logisim for designing and simulating circuits. By the time you finish with the following steps, the Logisim screen should look something like Figure 2.2. Start the simulator in your web browser by choosing “Logisim” from the Computer Science Software Applications link, http://www.csbsju.edu/computerscience/launch/default.htm , or from the K-menu system via CSBSJU Menu->, Computer Science->, CSBSJU Launch Page. The best method for drawing a circuit is to draw all the gates first, working from right to left, then add the input and output boxes, and finally draw in the connecting wires, working from left to right. 2–1 2–2 2. Circuits Figure 2.2: Figure 2.1 drawn in Logisim. 1. We start by drawing the gates, working from right to left. The toolbar at the top of the screen contains a menu of logic gates. The rightmost gate is an AND gate, so click on the AND gate icon in the gate menu, and click in the drawing area to place it. (About an inch from the right and halfway between the top and the bottom is good.) Add the other gates too. If you make a mistake, right click on the part of the circuit you want to remove, and click on Delete. 2. Now add one input switch for each variable, over near the left side of the screen. (Be careful not to get part of the input box off the screen.) Click on the input gate icon (which looks like a rectangle with a one in the middle) and then click in the drawing area to place the two switches. 3. Finally, place an LED output box (the rightmost icon on the menu bar) to the right of the AND gate. If you place the tip of the cursor finger on the output of the AND gate, it can be attached directly. Otherwise, you can use wires to connect them. 4. To finish the circuit, we need to connect the gates with wires, and now we’ll work left to right. Wires can be connected in straight, vertical or horizontal segments only. The starting end of the wire must be connected to either the output node of a box or gate, or to another wire. If the wire is blue it is not connected properly. Be very careful to connect wires just to the end of the output node or to the edge of a gate. A wire that is too long won’t work correctly. Warning: You must not lay two wires over the top of each other. Wires can cross but they cannot lie directly on top of one another in the same direction. 5. Testing the circuit: If you have made all the connections correctly, the circuit is ready for testing. Clicking first on the double-arrow icon from the menu bar, you can click on the input boxes to toggle them between ’0’ and ’1’. The color of input boxes, wires, and output boxes indicates their values: green for ’1’ and black for ’0’. For each row of the truth table, set the inputs on the circuit to that row’s values, and record the circuit’s output in the “actual” column of the table. When you have tested all the possible inputs, compare the truth table’s predicted output with the actual output. If they differ, try to determine why. Is the table wrong (and where), is the circuit constructed wrong, or is the simulator wrong? If you can, correct the error. 2. Circuits 2–3 B. Another circuit Derive a truth table from the circuit diagram of Figure 2.3. Now construct the circuit and see if the output from the constructed circuit is the same. Show your instructor your truth table and circuit. Figure 2.3: Another circuit. intermediate steps Input x y predicted output z actual output C. Constructing a circuit Derive a Boolean expression corresponding to the following truth table, and simplify it. Using the logic simulator, build a circuit for the minimized formula and verify that the circuit indeed works as the truth table specifies. Save your circuit using the “Save. . . ” option in Logisim’s File menu. Show your instructor your Boolean expression and circuit. Finishing the lab Your lab instructor or TA must check your truth tables and circuit before you leave. Make sure bring this handout, your truth tables from Parts A and B, and your Boolean expression from Part C to the next lab.