CEG 360/560 – EE 451/651Lab 3

Dr. Doom

Lab 3: Decomposing State machines: Pong Game

CEG 360/560 - EE 451/651

PURPOSE

Just like large procedures or subroutines in a programming language, large state machines are difficult to conceptualize, design, and debug. Therefore, when faced with a large state-machine problem, digital designers often look for opportunities to solve it with a collection of smaller state machines. The purpose of this lab is to design and build a clocked synchronous state machine of moderate complexity. This design can be approached using the basic techniques discussed in Mano, Ch. 4, but such an approach would be a significant effort. In this lab, students will simplify the design process by decomposing the overall design into two sub-designs: a data unit and a control unit. This is a two-week lab.

ASSIGNMENT

Consider the following simple hand-held electronic game version of Pong. The game controller has two synchronous input signals (LeftPlayerButton (LPB), RightPlayerButton (RPB)) that control game play, one asynchronous input signal (/RESET) that starts a new game, and eight synchronous output signals (L1 (LLAMP), L2, L3, L4, R4, R3, R2, R1 (RLAMP)) that are used to represent the position of the ball when the ball is in play and are used to display the two 4-bit scores at other times.

The state machine to be designed must realize the following operational characteristics:

  • Operation is symmetric for two players, L (Left) and R (Right).
  • When the ball is not in play, the score of the left play is displayed on L1-L4 and the score of the right player is displayed on R4-R1. The machine must keep track of whose serve it is.
  • When reset, both scores are initialized to 0. Left player always serves first.
  • The serving player serves by asserting their button (LPB or RPB); the other player's button is ignored until the serve. Once served, the "ball" shows up as single active output which moves in the direction of the serve one light per clock tick. The ball is always visible while in play (in other words, it never goes "off" either side. Once the ball is moving, the serving players button is ignored until the direction of play is reversed.
  • In order to return the ball, the returning player must push their paddle button when the ball is in the rightmost or leftmost position. If returned, the direction of the ball movement changes and the opposite player must now return the ball.
  • If the returning player pushed their button when the ball is not in the rightmost position OR if the ball "falls off the end", then play ends and the other player scores a point and gains control of the serve.
  • When either player's score reaches 15, the game is over and final score is displayed until the machine is reset.


Figure 1: Pong State Diagram.

States:The figure above shows the minimal state diagram of the state machine to control the

pong game. The defined states are:

  • STOPRThe game is stopped and it is R's turn to serve.
  • STOPLThe game is stopped and it is L's turn to serve.
  • RUNRThe ball is in play and it is R's turn to return.
  • RUNLThe ball is in play and it is L's turn to return.

PRELAB (WEEK ONE): Data unit design using Shift Registers

(10 pts.) The goal of the first week is to design the data unit for the Pong game project.

Data units are used for storing, combining and processing data. Usually, a data unit consists of multi-bit counters, shift-registers, and ALUs which increment, shift, or modify register contents according to the control signals applied to the unit. In designing the data unit for this project, you are subject to the following restrictions:

  • The data unit must contain two MSI shift-registers whose outputs are the output signals for the eight output signals. Use one shift register for the right-side lights and one for the left-side lights.
  • The data unit must also contain two MSI counters which are used to keep track of (and to display) the current score.
  • The data unit must be able to display either the balls' current position OR the current score.
  • As we are using shift-registers for state memory, we have the option of using both loading and shifting in determining our next state. The turn sequences for this design must be accomplished primarily by shifting. Some state assignments will require a synchronous load.

Construct a state diagram (or ASM chart) for the Pong game project as discussed above. Note that the state machine outputs are different in each state. Thus, we can use the output assignments as the assignment for the states! [This is referred to as an output-coded state assignment.] Construct a state table from the state diagram that shows the state-transitions for each state/input combination (feel free to use don't care notation where appropriate).

With this overall functionality in mind, construct a data unit capable of making the appropriate state transitions. Examine your state table to identify all possible transitions required by this design. Create a set of control signals that specifies a data unit operation for each of these transitions. Design a datapath that uses these control signals as inputs and implements the appropriate operations. Note that our decision to use two shift registers has an advantage in that the left lights and the right lights are two separate (small) sub-machines. Keep in mind that the data-path does not contain any next-state functionality, it need only be able to transition between the necessary states and have an appropriate set of control signals to control that transitions. Include a complete set of timing diagrams in your lab book. Construct your design using the laboratory simulation package and test it thoroughly.

IN-LAB (WEEK ONE)

(0 pts.) Demonstrate your overall design and the design of your data unit to your lab instructor. Be prepared to answer questions regarding the decisions you made as part of the design process.

PRELAB (WEEK TWO): Control unit design

(10 pts.) The goal of the second week is to design the control unit for the Pong game project.

Control units are sub-machines within a design that are used to control the operations of the data unit. The inputs to the control unit consist of primary inputs (usually) and feedback from the data unit (status signals). The outputs of the control unit consist (primarily) of control signals that select the appropriate data unit operation.

In order to complete our design, we must design a control unit to sequence our data unit appropriately (as determined by the current state and the values of the primary inputs). Design the next-state logic for the Pong game using an SSI or MSI implementation of your choice.

The decisions made during the design of your data unit influence the design of your control unit. As you work through your design and your understanding of the problem increases, you may see a "better" way to design your data path. Don't be afraid to go back and make changes. Designing the interface between your data and control unit is an iterative process.

When implementing your logic you may use discrete gates or MSI parts. Using discrete logical with minimal SOP (or POS) expressions will require the solution of complex Karnaugh maps. It is probably easier to implement your expressions using Multiplexors directly from the transition lists.

Graduate students only:

In games of the tennis family, it is the custom to require winning by a minimum of two points. Thus, if the score was tied at 14, merely winning the next point would not be enough. Two points in a row must be won. If the score is tied and two points are needed for victory, the score is said to be deuce. Modify your circuit to include deuce scoring.

  • A deuce condition should be indicated by having all of the score bits flash on (xF) and off (x0) if both players are tied in deuce.
  • If one player has the advantage (they only requires one extra point to win), their score bits should flash (x0, xF, repeat) but the disadvantaged player (the player who now requires three extra points to win) displays nothing (x0).
  • When a player wins from a deuce condition, the "winner" is indicated by having the lights for their side "pass the ball" (x0, x1, x4, x8, x4, x1,x0, repeat) while the other side displays nothing (x0).

IN-LAB (WEEK TWO)

(10 pts.) Demonstrate the design of your control unit to your lab instructor. Demonstrate the complete functionality of your Pong game state machine. Be prepared to answer questions regarding the decisions you made as part of the design process.