University of Pennsylvania
Department of Electrical
Engineering
Digital Design Laboratory
The
purpose of this lab is to:
Your task is to design a digital circuit that emulates a dice game for two players. Each player has two dice that s/he throws simultaneously. The players roll the dice in sequence, one player after the other, until one of the players win. The game is played according to the following rules.
Since two dice are used, the sum will be between 2 and 12. The value of the dice can be generated by two independent counters who count between 1 and 6, or by a single counter who counts between 2 and 12. Each player has it own pushbutton (Roll Dice Rd1 and Rd2 for player 1 and 2, respectively) to roll the dice. The counter starts when a push button, Rd1 or Rd2 (Roll dice) is pressed and continues counting until the button is released. The clock used for the counter has a high frequency so that one cannot see the value of the counters when the push button is pressed. The number that the counter displays when the button is released is the value of the dice and will determine the outcome of the throw according to the rules given above.
In order to be able to follow the game, you will display the value of the dice and the total points accumulated on seven-segment displays. Since only 4 seven-segment displays are available on the Digilab board, you will display these values either for player 1 or player 2, depending on who is currently playing. An LED will light up when player 1 plays and another LED will go on for the other player. In addition, a “Win Player 1” or “Win Player 2” LED will go on when player 1 or player 2 wins, respectively.
The value of the bet will be entered using two general-purpose switches. A reset button brings the circuit into the initial state and loads the Points Registers with the initial value of “45”.
A demo of the electronic dice game is to be given to the lab instructors at the end of the second week of the lab.
As with any complex digital system, the electronic dice game can be designed by using a modular and hierarchical design strategy. A common way to partition a system is into a datapath and a control unit. The datapath performs operations on the data and consists of registers (for storage, shift, counters), and combinational circuits (add, subtract, etc). The control unit determines the type of operation and the right sequence in which the datapath executes the operations. A schematic block diagram of such a partitioning is shown in Fig. 1 below. The control unit provides control signals to the datapath (such as Load, Shift, etc.) while the datapath provides the control unit with data inputs and status signals.
Figure 1: Partitioning of a digital system in a Datapath and Control Unit.
In addition to the control unit and datapath, a digital system further consists of memory and input/output units such as displays, etc. In the electronic dice game project you will not be using an external memory. However, output data will be shown on seven-segments displays and data will be inputted through switches and push buttons.
A possible block diagram of the datapath of the electronic dice game is shown in Fig. 2.
Figure 2: Datapath of the Electronic Dice Game
The datapath consists of a counter, registers, multiplexers and combinational circuits. The clock inputs at the registers and the counter are not shown. A 2-to-12 counter represents the sum of the dice and starts counting as soon as one of the Roll Dice push buttons has been pressed. The value of the dice (when the counter stops) is multiplied by the value of the bet of player 1 or 2, depending on which player is currently playing. The multiplied value is added or subtracted from the value stored in the point register. Negative values are presented in 2’s complement. Whether the value is added or subtracted depends on the results of the tests performed by the Test Logic. It is the control unit that generates the Add/Subtract signal. The Test Logic also checks the value of the point registers and provides input to the Control Unit, which determines whether a game is over or not, and which player wins.
Notice that the above block diagram is not the only way to realize the circuit. One can implement the dice game in various ways. For instance, you may want to use two 2-to-6 counters which are started by pressing two different buttons and then adding the two counts together. Instead of implementing the multiplier as a combinational circuit you can also implement it as a sequential circuit. You also may want to store the value of the bets into their own registers, etc. To a certain extent, it is up to you to decide how to realize the dice game.
The Control Unit initiates the game after it receives a signal from one of the Roll Dice push buttons. It goes through a sequence of states, depending on the status signals (TestA and TestB) from the Test Logic, which provides information about the value of the dice and the contents of the point registers. Based on the signals it generates, at the proper time, the control signals ST (Start counting or rolling the dice), LD1 (Load Register1), LD2 (Load Register2), and PL (player) determine the operation to be performed by the datapath.
Flow diagram of the Dice Game
In order to help you with the design of the state diagram of the control unit, it will be helpful to draw a flowchart of the dice game. The following figure shows a possible flowchart outlining the main steps and conditions during the game. Check this chart carefully. You can make some modifications to reflect your design approach. As with each design project there are no unique solutions. Notice that the flowchart of Fig. 3 is not an Algorithmic State Machine (ASM), although it can be used to derive a corresponding ASM.
Figure 3: Flowchart of the Dice Game
The data lines in the datapath are indicated in blue and fat lines in the block diagram of Figure 2. These are busses carrying the signals. Give the width of each bus.
b. What is the width of the bus at the output of the 2-to-12 counter and the output of the multiplier?
a. Assume that the Points Register of Player1 has 73 points and that of Player2 has 77 points stored. Player 1 has made a bet of 2 while player 2 has a bet of 3. Player 1 is next and throws a 4, followed by Player2 who throws an 8. Give the contents of the Point Registers after each throw.
In case a number is negative, express it in 2’s complement.
b. Same question as above except the current value of the Point Registers is 89 and 17 for Reg1 and Reg2, respectively. Player1 rolls a “2” while Player2 throws an “11” (decimal). The bets are the same as in part a.
In case a number is negative, express it in 2’s complement.
Tasks:
Your task is to design each module and put these modules together in an overall system. In designing the modules you can choose from a variety of methods, such as schematic with gates, use predefined blocks or use a VHDL description.
Based on the understanding of the above flowchart, draw the state diagram of the control unit.
Design a counter that counts in the sequence 2, 3, 4 . . .12, 2, etc. Since this counter counts only when one of the “Roll Dice” buttons is pressed, it should have a Count Enable (CE) input. Show the circuit schematic of such a counter. You can design this counter in a variety of ways. One way is to start from a state diagram that cycles through all 11 states. An alternative way is to use a 4-bit counter with parallel load with some external logic to accomplish the 2-to-12 count sequence. The Foundation Library has 4-bit counters with parallel load and Count Enable inputs available. All you need to do is to make it a 2-to-12 counter. Draw the circuit in your lab notebook.
This circuit multiplies a 4-bit number with a 2-bit number. Since this is a relatively small multiplier, a combinational circuit may be a good choice. There are various ways to design such a multiplier. One way is to use the schematic discussed in class (See M. Mano and C. Kime, section 3-11, pp 144-145 – or in any textbook on Digital Design). An alternative way is to use a VHDL description of the multiplier, either a structural or behavioral (concurrent) description – see VHDL Tutorial).
Draw the circuit schematic or give the VHDL code of the multiplier in your lab notebook.
Also here a variety of choices are available. You can use your previously designed adder circuit (or several of these) modified to make it an adder/subtractor. Alternatively you can write a VHDL code to perform this operation. Write your design choice in your lab notebook.
This circuit performs two checks. One is on the sum of the dice. It generates control signals to indicate if the sum is 3, 8 or 10; or 4, 6 or 11; or neither of these values. The other test is performed on the values of the two point registers. It checks which register reaches first the value 90 (or above) or 0 (or below).
The easiest way to design this circuit is to write a VHDL code using the “Process” construct. Write the code for the test circuit in your lab notebook.
The registers are used to store the points accumulated by each player. These registers should be registers with parallel load. At the start of the game, the registers are pre-set to the initial value of 45. You can build this register from D flip-flops (see e.g. Fig. 5-2 in Mano and Kime, or in similar textbooks on Digital Design). You just need to set or reset the individual flip-flops to the initial value of 45. An alternative way is to define the register in VHDL using the “Process” construct.
The Load signals will load the parallel inputs at the next clock cycle, as shown in the Fig. 4.
Figure 4: Timing of the Load signal for the Registers.
In order to be able to follow the operation of the game, you will display the value of the dice and the value of the accumulated points in the Points Registers. The value of the dice will be displayed on the first two seven-segment displays while the value of the Points Register will be shown on the last two seven-segment displays. Since only 4 seven-segment displays are available, you can also show these values for one player at a time. When player 1 or player 2 rolls the dice, you will show the dice and points for player 1 or player 2, respectively. This means that after the first player rolls the dice, the displays should show the value of his/her dice and value stored in the first player’s point register. Similarly after the 2nd player has rolled the dice. A LED will indicate whose values are being displayed.
This will require two decoders, one for the dice and one for the Points Register. These are similar to the decoders you have designed earlier for the 4-bit adder, except that the decoder for the Points Register has many more inputs.
A. Parts and Equipment:
1. PC
2. Xilinx Foundation Tools F2.1i
3. Digilab board, the Xilinx FPGA Demoboard (with XChecker cable and AC Adapter), XS40 or XS95 boards.
B.
Experiments:
Your goal is to design and implement the Electronic Dice Game on a FGPA. The lab is considerably more complex than the previous ones. It will be very important that you work systematically and give yourself enough time to design and debug the system. Debugging is a normal part of any design task.
You will partition the system in smaller modules. After you design each module, simulate it thoroughly and make sure that it works as expected. Do not skip this step since finding an error later on will be much more difficult. Once you have designed and simulated a module add it to the top circuit schematic and do a simulation of the partial schematic so that you make sure that the blocks work together. Simulating and testing your design progressively will make it easier to find errors. Errors may be the result not only of wrong circuit design but also due to timing or synchronization errors that may show up only when you link blocks together.
Open a new project, called MyDiceGm (8 characters only!) in the Schematic Flow mode. Place it in your folder in the user directory on the C: drive.
Play the game with the lab instructor and convince him/her that it works according to the rules specified for the game. No bribes allowed!
Hand
in:
You must hand in a lab report that contains the following:
1. Course Title, Lab no, Lab title, your name and date.
2. Section on the Pre-lab with answers to all questions (only those task that were not submitted online) [15pts].
3. Section on the lab experiment:
a. Brief description of the lab experiment including the goals.
b. Copy of the schematics (screen capture) and HDL source code of each macro (screen capture)
c. Simulation results with Screen capture of the major macros
d. Summary of the Device utilization.
e. Discussion of the results indicating that the circuit functions properly.
4. Conclusion.
The lab report is an important part of the laboratory. Write it carefully, be clear and well organized. It is the only way to convey that you did a great job in the lab.
©2001, Jan Van der Spiegel; Created November 15, 2001; updated December 11, 2001