Final Project [Tic-Tac-Toe]

Similar documents
Experiment 8 Introduction to Latches and Flip-Flops and registers

Sequential Logic. E&CE 223 Digital Circuits and Systems (A. Kennings) Page 1

DIGITAL SYSTEM FUNDAMENTALS (ECE421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE422) LATCHES and FLIP-FLOPS

The basic logic gates are the inverter (or NOT gate), the AND gate, the OR gate and the exclusive-or gate (XOR). If you put an inverter in front of

CSE 352 Laboratory Assignment 3

EMT 125 Digital Electronic Principles I CHAPTER 6 : FLIP-FLOP

A clock is a free-running signal with a cycle time. A clock may be either high or low, and alternates between the two states.

Rensselaer Polytechnic Institute Computer Hardware Design ECSE Report. Lab Three Xilinx Richards Controller and Logic Analyzer Laboratory

ECE 341. Lecture # 2

Catch or Die! Julia A. and Andrew C. ECE 150 Cooper Union Spring 2010

PHYSICS 5620 LAB 9 Basic Digital Circuits and Flip-Flops

Sequential Digital Design. Laboratory Manual. Experiment #3. Flip Flop Storage Elements

CHAPTER 4: Logic Circuits

LED BASED SNAKE GAME

Sequential Design Basics

Introduction to Sequential Circuits

Unit 11. Latches and Flip-Flops

Report on 4-bit Counter design Report- 1, 2. Report on D- Flipflop. Course project for ECE533

Chapter 11 Latches and Flip-Flops

Department of Electrical and Computer Engineering Mid-Term Examination Winter 2012

LATCHES & FLIP-FLOP. Chapter 7

NORTHWESTERN UNIVERSITY TECHNOLOGICAL INSTITUTE

Engr354: Digital Logic Circuits

CHAPTER1: Digital Logic Circuits

FE REVIEW LOGIC. The AND gate. The OR gate A B AB A B A B 0 1 1

Digital Logic Design Sequential Circuits. Dr. Basem ElHalawany

Flip-Flops. Because of this the state of the latch may keep changing in circuits with feedback as long as the clock pulse remains active.

Computer Systems Architecture

Registers and Counters

ELCT201: DIGITAL LOGIC DESIGN

CHAPTER 4: Logic Circuits

EECS 270 Group Homework 4 Due Friday. June half credit if turned in by June

INTRODUCTION (EE2499_Introduction.doc revised 1/1/18)

IT T35 Digital system desigm y - ii /s - iii

Combinational vs Sequential

Sequential Digital Design. Laboratory Manual. Experiment #7. Counters

Digital Circuits ECS 371

Chapter. Synchronous Sequential Circuits

Introduction. NAND Gate Latch. Digital Logic Design 1 FLIP-FLOP. Digital Logic Design 1

Logic Design ( Part 3) Sequential Logic- Finite State Machines (Chapter 3)

COE 202: Digital Logic Design Sequential Circuits Part 1. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

Digital Networks and Systems Laboratory 2 Basic Digital Building Blocks Time 4 hours

Asynchronous (Ripple) Counters

CHAPTER 1 LATCHES & FLIP-FLOPS

DALHOUSIE UNIVERSITY Department of Electrical & Computer Engineering Digital Circuits - ECED 220. Experiment 4 - Latches and Flip-Flops

Introduction to Digital Electronics

Registers and Counters

Advanced Devices. Registers Counters Multiplexers Decoders Adders. CSC258 Lecture Slides Steve Engels, 2006 Slide 1 of 20

CPSC 121: Models of Computation Lab #5: Flip-Flops and Frequency Division

Other Flip-Flops. Lecture 27 1

cascading flip-flops for proper operation clock skew Hardware description languages and sequential logic

Laboratory 1 - Introduction to Digital Electronics and Lab Equipment (Logic Analyzers, Digital Oscilloscope, and FPGA-based Labkit)

Flip-Flops and Sequential Circuit Design

EE 367 Lab Part 1: Sequential Logic

PHY 351/651 LABORATORY 9 Digital Electronics The Basics

California State University, Bakersfield Computer & Electrical Engineering & Computer Science ECE 3220: Digital Design with VHDL Laboratory 7

ELCT201: DIGITAL LOGIC DESIGN

Unit 9 Latches and Flip-Flops. Dept. of Electrical and Computer Eng., NCTU 1

Experiment 7 Fall 2012

Microcontrollers and Interfacing week 7 exercises

Chapter 6. Flip-Flops and Simple Flip-Flop Applications

Digital Logic. ECE 206, Fall 2001: Lab 1. Learning Objectives. The Logic Simulator

Counters

Chapter 3 Unit Combinational

Chapter 2. Digital Circuits

MC9211 Computer Organization

DIGITAL CIRCUIT LOGIC UNIT 9: MULTIPLEXERS, DECODERS, AND PROGRAMMABLE LOGIC DEVICES

YEDITEPE UNIVERSITY DEPARTMENT OF COMPUTER ENGINEERING. EXPERIMENT VIII: FLIP-FLOPS, COUNTERS 2014 Fall

DIGITAL SYSTEM FUNDAMENTALS (ECE421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE422) COUNTERS

BCN1043. By Dr. Mritha Ramalingam. Faculty of Computer Systems & Software Engineering

INTRODUCTION TO SEQUENTIAL CIRCUITS

The NOR latch is similar to the NAND latch

RS flip-flop using NOR gate

EET2411 DIGITAL ELECTRONICS

Objectives. Combinational logics Sequential logics Finite state machine Arithmetic circuits Datapath

Electrical & Computer Engineering ECE 491. Introduction to VLSI. Report 1

SEQUENTIAL LOGIC. Satish Chandra Assistant Professor Department of Physics P P N College, Kanpur

Laboratory Exercise 7

Flip-Flops and Related Devices. Wen-Hung Liao, Ph.D. 4/11/2001

ECE 250 / CPS 250 Computer Architecture. Basics of Logic Design ALU and Storage Elements

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

Discussion of New Equipment

EXPERIMENT #6 DIGITAL BASICS

Experiment # 4 Counters and Logic Analyzer

Sequential Circuits: Latches & Flip-Flops

Review : 2 Release Date : 2019 Last Amendment : 2013 Course Code : SKEE 2742 Procedure Number : PK-UTM-FKE-(0)-10

Chapter 7 Counters and Registers

Clocks. Sequential Logic. A clock is a free-running signal with a cycle time.

Laboratory 10. Required Components: Objectives. Introduction. Digital Circuits - Logic and Latching (modified from lab text by Alciatore)

CS 261 Fall Mike Lam, Professor. Sequential Circuits

CPSC 121: Models of Computation Lab #5: Flip-Flops and Frequency Division

Laboratory 8. Digital Circuits - Counter and LED Display

Chapter 4. Logic Design

CprE 281: Digital Logic

Physics 323. Experiment # 10 - Digital Circuits

Chapter 5: Synchronous Sequential Logic

55:131 Introduction to VLSI Design Project #1 -- Fall 2009 Counter built from NAND gates, timing Due Date: Friday October 9, 2009.

Logic Design. Flip Flops, Registers and Counters

Chapter 7 Memory and Programmable Logic

Part 4: Introduction to Sequential Logic. Basic Sequential structure. Positive-edge-triggered D flip-flop. Flip-flops classified by inputs

Transcription:

Final Project [Tic-Tac-Toe] (In 2 dimension) ECE 249 Session: 3-6pm TA: Jill Cannon Joseph S Kim Ghazy Mahub

Introduction As a final project for ECE 249, we will develop a multi-player tic-tac-toe game with the knowledge we learned from the previous laboratory exercises. For our project, we will need a user interface, a game controller, a display for game and the winning status of the game. Design We tried to think a project, which can be developed with half for TTL implementation and half assembly code of HC12. We thought of creating a simple game and as a result, we came out an idea for making a tic-tac-toe game. Tic-Tac-Toe is played by two players and on a board with 9 spaces that are arranged in 3 rows and 3 columns. The players are assigned a marker that is either an X or O. The players then take turns placing their mark in an empty space until all the spaces are full, or until one player gets 3 of their marks in a horizontal, vertical, or diagonal row. If the later happens, that player is the winner of the game. However, if all the spaces on the board are filled and neither player has 3 of their marks in a row, then that game is over, and there is no winner. We will use TTL for showing the game status, and use HC12 micro-controller to control the game. Design Issues There are lots of question arise with our design. We separated our project into different parts, thought about every problems, and made a decision for each problem. The following are the design issues that we encountered. 1) What type of game we want to make? We have different options for our tic-tac-toe game. We can create either two human players game or AI (micro-controller) Vs. human player. We thought of creating both options for our project. We realized that creating AI control part in our project will be a challenging one, and we kept in mind AI part as the goal of our project. 2) What will we use for the player inputs? We decided to use the I/O box switches as our input device at first, and if time permits, we will change the keypad as our input device. We thought using I/O box switches was easier but later we found out that using keypad is more efficient and easier to write the assembly code.

3) How do we hold the player s inputs? We will use TTL for holding the data because in earlier laboratory exercises we used D and JK flip-flops to hold the data. LEDs are best suited for the data that we stored for our game and we will need two colors for two players. The design of our tictac-toe data storing device is shown in the TTL implementation part. 4) Where will the win/lose/tie output display and which device will we use? This is another important issue for showing the game s result. There are eight different ways to win the game and we decided to use VHDL instead of TTL because we just need to compute the input combinations. Using TTL is possible but we avoided for saving our debugging time. 5) How do we control the game for the computer move? We decided to use MC68HC12 for AI control part since we knew that we could write assembly code and achieve the desired outputs. We expected that it would be the hardest part of our project. Hardware/software distribution As we planned before, we will create our project with half for hardware part and half for software part. We took hardware part and the other team took software part writing both assembly and VHDL codes for our project. And also we developed the TTL implementation.

Implementation 1. Required Hardware Components 1) MC68HC12 micro-controller 2) Vantis Mach 211 CPLD 3) Keypad 4) Keypad decoder (74C992) 5) 9 Bi-color LEDs 6) 3 single color LED 7) 5 D flip-flops (74LS74) 8) 5 XOR (7486) 9) 1 inverter (7404). 2. Decisions for Hardware Choice Experiences in earlier laboratory exercises gave us a lot of knowledge for choosing devices. We knew that MC68HC12 micro-controller is capable of generating AI output and we chose it as our control device. As we stated earlier, we chose Vantis CPLD for checking wining output combination and to get the simple TTL implementation. Before choosing the keypad, we used I/O box switches for the user interface but later while developing the assembly code, we found out that using keypad and keypad decoder is much more easier and it simplifies the assembly code a lot. The problem in implementation of assembly code is discussed in detailed later. We could use either JK flip-flops or D flip-flops as our data-storing device but we chose D flip-flop to get the simple logic. Bi-colored LEDs are necessary for our project because we need to show the input of different players. XOR chips are also necessary for giving the player turn output. The detailed design for TTL implementation will discuss later. 3. TTL implementation Block Diagram Block Diagram Data Available input Space 1 input Space 1 LED LED 1 WIN LED Bit 3 input Space 2 LED 2 Player A Bit 2 input Space 3 LED 3 Bit 1 input Space 4 LED 4 WIN LED Keypad Bit 0 input Space 5 LED 5 Player B input Space 6 LED 6 MC68HC12 Microcontroller Protoboard input Space 7 LED 7 Tie LED Tic-Tac-Toe Grid input Space 8 LED 8 input Space 9 LED 9 Vantis MACH 211 (VHDL) total 18 LEDs (both green and red) Reset Bit

Tic-Tac-Toe Grid Tic-Tac-Toe Grid 1 2 3 4 5 6 7 8 9 We used D flip-flop as our data-storing device as shown below. 1 3 2 3 CLK TOGGLE 2 D Q 5 74LS74 ground LED 1a (green) LED 1b (red)

The data-storing device will store the data such that: if the clock input of D flip-flop becomes Hi, D flip-flop will store the TOGGLE input in D latch. As a result of storing data, one of the LED will light up. If the TOGGLE input is Hi, the left LED will light up, and if the TOGGLE input is Low and Clock is Hi, the right LED will light up. Therefore, we will have two different outputs for show the result. This design has one error and it is as follows. If the clock input is Hi and goes back to Low, Q output of D flip-flop will be Hi and as a result, the left LED will light up. At the same time, the output of XOR will be Hi, and therefore, the right LED will also light up and we will get the yellow colored LEDs instead of red or green. We can ignore that error because in our tic-tac-toe game, if one player selected a space, the clock input cannot be Low anymore. The complete diagram for all nine datastoring device is shown on the attached sheet. Player Turn Controller The TTL implementation for player turn controlling signal is simple. We cascade the XOR chips so that it will give the toggle output if one of the space is selected. This part is the simplest TTL implementation that we designed for giving the player turn. Each input is connected to the clock input of D flip-flop so that it will generate a toggle output if one player selects the empty space. Player Turn Controller 1 2 3 4 5 Toggle Output 6 7 8 9 Input from Microcontroller Output to Tic-Tac-Toe Grid

Testing and Debugging For the first 3 weeks of our project period, we developed the tic-tac-toe game like below. 1 Our circuit will be responsible for lighting LEDs to mark where each player has played as well as tracking the past plays of the game in order to be able to declare a winner. The microcontroller will be used for decision making function. A feature that we might add to our Tic-Tac-Toe game would be a LED display to prompt players. Input will come from switches. Output will be a LED display. These LEDs will be able of displaying red to indicate which player has used the space. If the space has not been taken, the LED will pulse between on and off. But, as we were testing this circuit for 3 weeks, we confronted to the problems, and also our circuit logic didn t match with software part either. First, logic behind the circuit was too much complicated, so that it was easier to make mistakes when we circuit them. In real, we couldn t figure out what the problems are and how to debug. Second, we realized that using I/O switches are more difficult because the inputs have nine bits and we have to use two ports of microcontroller as our input ports. Moreover, in the assembly code, we have to load two accumulators whenever we want to check the game situation. Therefore, we considered encoding the nine bit inputs into six bits but in the mean time, we found out that using keypad will only give the five bits outputs and we changed our plan for using the keypad. The keypad will be worked as we expected and other team developed the assembly code based on the output of keypad. When we test our code with circuit, we faced another problem because the keypad sometimes gives two inputs and sometimes only one input. Later, we found that it is because we are not connecting the complement of Data available bit into its input, and not adding capacitors to the required inputs. Wiring of eighteen inputs to CPLD chip also consumed some amount time. After getting all the parts working, we successfully demonstrated the two-player version of our game. We were about to finish the AI Vs. player version but due to time constraint, we did not succeed in debugging the code. The problem we thought was the memory location that we chose to store the data was incorrect. Writing a good AI control code with the limitation of HC12 micro-controller is a challenging one, and we found out that the micro-controller can handle only a certain amount of instructions. We tried to fit our code between memory locations of 0800 and 09FF our code barely fit in between those locations. Our code can make the micro-controller move for one input 1 Details of previous circuit and description of hardware is attached in Appendix A

but unfortunately, the AI part stops execution its output after that. We debugged the AI part of our code up to the last minute but we were not that lucky. Conclusion We were very pleased to say that our project went smoothly except without being able to develop a successful AI Vs. human player version. We incorporated all the experiments that we learned throughout the semester: choosing suitable device, combining hardware and software together to achieve the project goal, and writing VHDL and assembly codes. Our TA also helped us a lot to finish this final project. While we were stuck with problems with circuit, Jill helped us for debugging and using the keypad and its decoder. Without Jill s help, we will not able to finish the two-player version of this game. Throughout the whole ECE 249 laboratory, Jill helped us in debugging circuits, explaining all the devices that we did not understand, and on the top of all this, he is one of the best TAs that we ever had.

Appendix A. Details of previous circuit and description of hardware part with diagram In order to describe the circuit, I will start at the left of the drawing and work my way across, explaining the components as I go. At the left most portion of the circuit layout, there are 4 switches. These switches are the inputs for the two 4 to 16 decoders (74154) that will be used to select the space on the tic-tac-toe board that the player would like to play in. Since there are only 9 spaces that the player can play in, only outputs 1 through 9 from the decoders will be used. Once the player has selected the spot that they want to play in, they will flip the PLAY switch (right side of drawing) in order for their move to be recorded and displayed. (The players must select a space with a number of 1 through 9 and that space must not have already been played in, otherwise the circuit will cause the player's turn to be forfeited.) The decoder's outputs then are routed to a 9-bit storage register consisting of nine JK flip-flops (74112). The inputs of the flip-flops are NOR gated (7402), so that the players cannot play over a previously played spot. All of the JK flip-flops are clocked by a single pulse clock that will only allow them to be updated after a player flips the PLAY switch. The outputs of all 18 JK flip-flops are then run into three quadruple 2-line to 1- line MUXs (74157). Finally the MUX outputs will be wired to the tic-tac-toe board. The select input of each of the MUXs will be wired to a slow clock. As the clock oscillates, the MUXs will oscillate between outputting the contents of the player 1's register and player 2's register. When the RESET switch (right side of drawing) is flipped, player 1's register is cleared and player 2's register is preset. As the clock pulses, the output to the inputs to the tic-tac-toe board will oscillate between 1 and 0. This will cause the LEDs on the board to flash on and off. The flashing LED's are to show that a spot has not been played in. When player 1 plays, the JK flip-flop corresponding to the spot they played in will be updated with a 1 when the PLAY switch is flipped. Once player 1 plays in a spot, the gating on player 2's register will block player 2 from being able to play in the same spot. The registers for player 1 and player 2 will now contain the same logic value for the same spot on the tic-tac-toe board. When the clock causes the MUXs to pulse back and forth between registers, the LED in that spot will stay on. When player 2 plays in a spot, the same type of logic will be performed, except the spot that player 2 plays in will be a logic 0 and the spot will be marked by the LED staying off as the slow clock pulses.

Appendix A. In the bottom right corner of the drawing, the one pulse clock is shown. The clock will be triggered by the PLAY switch. The one pulse clock will also clock a JK flip-flop that is hard wired to have its output change whenever it receives a clock pulse. This JK flip-flop is wired to the enables of each decoder as will as an LED. This LED will show which player's turn it is as the game is played. * The logic diagram for this hardware is on the next page.