CPSC 121: Models of Computation Lab #4: Multiplexers Collaboration: For this lab, you should work in teams of two. Each team member must be able to answer questions based on or use skills developed in the lab (including working The Magic Box). We suggest that team members adopt and regularly change driver and navigator roles, where the driver works with the lab tools while the navigator checks the driver s work, keeps the team on track, and manages references and resources. Because of limited supplies, you will not be able to work alone on the parts involving The Magic Box. Objectives In this lab, you design, build, analyze, and scale up a multiplexer circuit. Multiplexers allow computers to choose among multiple inputs, for example, when deciding which of the many bytes in memory to access, or which of the results from several operations we really want. Together with adders (subject of a later lab), multiplexers are among the key circuit elements in a modern computer. Pre-lab As usual, read through the lab beforehand. Complete your pencil-and-paper design of and truth table for a twoinput multiplexer, as outlined below and on the next page. Hand in your pre-lab design to your TA when you arrive to the lab. 1 Discussion Period Your TA will lead you in a class discussion pertaining to the work you ll be doing in this lab. In the groups you are divided into, write down your answers and hand in your group submission at the end of the discussion period. 2 Multiplexers A multiplexer allows a circuit to select one of two (or more) inputs, depending on the value of a select control input. That is, a two-input multiplexer has two data inputs d0, d1 and one control input s, and it outputs d0 if s is LOW (FALSE), and d1 if s is HIGH (TRUE). 2.1 Building a Two-Input Multiplexer You will now build a two-input multiplexer using basic gates (AND, OR, NAND, NOR, and XOR) and inverters. We provide a logic formula for a two-input multiplexer: y =( s d0) (s d1). You should verify that this formula produces the correct behaviour. TODO (prelab): Fill in a truth table for a two-input multiplexer 1
Design: Translate the logic formula y =( s d0) (s d1) into a circuit. TODO (prelab): Draw this circuit in the space provided. 2.2 Implement your Multiplexer in The Magic Box Ask your TAs for the neccessary Magic Box components, then determine the chips that you need, and wire up your design. Make sure that you leave room on your breadboard to add one more chip later. You will need it if you implement the four-input multiplexer in the challenge problems. Test: Connect the inputs of your multiplexer to switches from your Magic Box. Connect the output of your multiplexer to an LED of your Magic Box. Check that your multiplexer performs correctly. TODO: Demonstrate to one of your TAs that your circuit works. 2.3 How are Multiplexers Used? In this section we explore how multiplexers similar to the one you have designed are used in building computers. Specifically, we will look at where multiplexers show up in the computer we looked at in lab 1 and learn how the Arithmetic Logic Unit (ALU) is built around a single, large multiplexer. Open the file cpu.v from lab 1 in TKGate. TODO: How many multiplexers are there in the computer? Which modules are they located in? TODO: Open the ALU module and look at this multiplexer in detail and answer the following questions: 2
1. How many inputs does the multiplexer have? 2. For each input, list its number and describe the meaning of the output in the box below, ignoring for now the third column. 3. In a text editor, load the program we looked at in lab 1, cpu.mem. The op codes 10-17 correspond to the different options in the ALU multiplexer. The control signal for the multiplexer is 3 bits wide. This corresponds to three of the bits in the op codes in cpu.mem. Look at the commands, MUX inputs and bits in the opcodes and write down in the table your guess at what the 3-bit control signal for the ALU Multiplexer is for each input. MUX Input Number Operation Description Control signal 2.4 A Glitch in the System Start a new schematic in TKGate. Select New from the File menu. TKGate will ask you for the name of the new file. Use a meaningful name like muxdesign.v. TODO: Enter your two-input multiplexer design into TKGate. You can add labels to switches s,d0,d1 and outputs if you like by choosing Make/Comments. Run the simulator and verify that it operates as expected. In your testing, pay special attention to the case where both input switches are up and you flip the value of the control input back and forth from HIGH to LOW. You should see a glitch when you flip the control input from HIGH to LOW. The LED will briefly flicker yellow. Your next task will be to trace the circuit s operation to help explain why. 1. From the Simulate menu, choose Begin Simulation. A trace window will appear. Don t press Run quite yet. 2. Set all your inputs to ON. 3. Double-click each separate wire in your circuit: the four wires that lead from switches or to the LED, the wire between the inverter and the AND gate, and the two wires that lead from AND gates to the OR gate. You should see black diagonal lines (probes) on each wire. The labels like w0 next to each probe will become important in a moment. 4. Now press Run. In the scope window that we ve previously ignored, you will now see seven lines tracing out the values of each of your wires. 3
5. Click the + magnifying glass about three times to make the graph clearer. Where a line is high/green, the wire s value is HIGH and where a line is low/pink, the wire is LOW. The lines chart the wires values in time, with time moving forward to the right (and pausing each time the circuit finishes calculating). Each line s label matches one of the probes you attached to your circuit. 6. Find the line representing your circuit s output. You should see that it starts out as red with both high and low lines. This indicates that it has no value at this time. Although it s hard to see, at the very end of the graph, the line goes green, as expected to indicate the line is HIGH. 7. Now, flip your control input to OFF. The scope window should show the computations performed after your action. If you look again at the line for your circuit s output, you will see that it is HIGH/green for most of the time but towards the end goes to the red both high and low state again. TODO: Explain the cause of the glitch, why is the LED wire red near the end leading to a yellow light. Do this by describing what happens in the circuit from the time when the switch is flipped to OFF until the time when the circuit stabilizes and the trace ends with only green and pink lines. It might help to think about this in terms of the trip of the electrons flying out of the switch at the moment it is switched to OFF. How does the current travel through the circuit and what effect will this have on the voltage of the final wire leading to the LED? TODO: Show your simulation, trace, and explanation to your TA. 3 Challenge Problem Problem: TKGate Modules Your next design will be a four-input multiplexer. You can build this using your two-input multiplexer as a building block. TKGate calls such building blocks Modules. If you have not done so already, save your TKGate design for the two-input multiplexer you will be using it again shortly. Then, exit TKGate and start it again. You should get the tutorial screen. If it does not appear, go to Options from the File menu and select Novice Mode (the square to the left of Novice Mode should be red). Then try starting TKGate again. Now that you have the tutorial screen, click on Using Modules and go through the two screens of that tutorial. Once you have finished the tutorial, create a module for the two-input multiplexer that you designed earlier. 1. Open the file for your multiplexer. You should be in a module called main. 2. Select Copy from the Module menu. A dialog box will pop-up with main in the From field. Type mux2 in the To field and click OK. The module name mux2 will appear in the list of modules to the left of the schematic area. However, you are still editing main. 3. Double click on mux2 and you will now be editing the module that you just created. Note that the status line at the bottom now says Module: mux2 Replace the switches in this schematic with input ports labeled d0, d1, and s, and replace the LED with an output port labeled y. You now have a module for your two-input multiplexer. 4
4. Double click on main in the list of modules to resume editing the top-level module. Delete the circuit for the multiplexer. 5. Create a module instance of mux2. Add inputs d0, d1 and s, and an output called y, to the module instance. Make sure that the port names specified in the dialog match the names you gave the ports when you created the mux2 module. If they do not match, then you will get the message, No gates driving net some-name when you try starting the simulation. TODO: Connect switches to the inputs of your mux2 module instance and an LED to its output. Verify that it works correctly. Finally, show your TKGate simulation to your TA. 5