Sie sind auf Seite 1von 4

Application of Computer Architecture and

Organisation Using DE2 Board:Tic Tac Toe Games


Raimi Naqiuddin Bin Norzali(CE150030),

A. System Information
In this project, the system is design for single player or
Abstract— For this assignment, we tried to apply the multiplayer. The player control by using switch keypad 4x4
theory that we learned in Computer Architecture and Organisation in Universial 16 Key Switch Keypad Keyboard. Another player
this project. We tried to create tic tac toe game by using Altera DE2 will take turn to press the keypad switch port keyboard which
board as the main board and Arduino Uno as external board. This is connected directly into DE2 board. The tic tac toe game
assignment is required the students to understand about the output are LED that organized in 3x3 grid design and the LED
connection between the hardware and study about the function of will turn ON based on Player either Player 1 or Player 2.
every parameters of the program code written to obtain the desired Because of that this project work by combination of hardware
result. and software such as we using DE2 as the main LED, and
apply the coding (VHDL language) into the project as the
output. The DE2 board used as the main board of the project
I. INTRODUCTION and act as mini CPU to run the game itself. The language used
Tic Tac Toe (also known as noughts and crosses or Xs and for this project is VHDL language. The monitor will connect
Os) is a paper-and-pencil game for two players, and these to the DE2 board using VGA cable. As stated above, the
game is a version has evolved a bit since the original version output of Tic Tac Toe game is constructed on breadboard
in ancient Egypt. The technique playing this game is by based on 3x3 grid design. The Arduino Uno will act as
external board to connect with the Keypad Switch.. As for
marked either X and O, who take turns marking the spaces in Keypad Switch part, the keypad wires will connect to the pins
a 3×3 grid. The player who succeeds in placing three of their of the Arduino Uno. Next, the Arduino Uno will be connected
marks in a horizontal, vertical, or diagonal row wins the to DE2 board but it has to be connected through Serial Port
game[1].The player will press the button as to indicate the then connected to ICB-HSM. The figure 1 below shows the
position of grid, and the player will be difference by using system architecture of the project. At the end of this project,
different label or mark which is X and O. They can compete the Keypad Switch will act as input to press the location of
against another player by take turn by both player. The goal is Tic Tac Toe. The LED on breadboard will light ON and
player have to compete each other by complete one line.
for each player to complete one line grid and the first player
complete the line is the winner.This project focuses on build
the tic tac toe games by using DE2 board as the main board
and Arduino Uno as external board. The coding is in VHDL
language. The project can be single or multiplayer games and
use simple 2D graphics.

II. OBJECTIVE
The objectives of this project are:
• To build the tic tac toe games by using DE2 as the
main board and Arduino Uno as the I/O devices
• To perform the hardware connection of the project.
• To apply the coding (VHDL language) into the
project

III. METHODOLOGY
Methodology part will discuss briefly about the system
methods used to build the tic tac toe Games by using Altera
DE2 board. This section will divide by three parts which is
system information, flowchart and system code.

Fig. 1. Tic Tac Toe Game System Architecture


B. Flowchart HEX0, HEX1, HEX2, HEX3, HEX4, HEX5, HEX6,
Figure 2 will show the flowchart of the Tic Tac Toe game. HEX7 );
The system will start by the monitor display the start screen. input CLOCK_27, CLOCK_50;
Then, wait for a few seconds before start the games. For the input PS2_CLK, PS2_DAT;
start game, the ball and paddle will in default position. The input [3:0] KEY;
position of ball will change depend upon user input. The game input [17:0] SW;
will decide if the ball has the valid collision, the system will output [9:0] VGA_R, VGA_G, VGA_B;
update the new ball and paddle position while, if no valid output VGA_CLK, VGA_BLANK, VGA_HS,
collision the monitor will display the end game message VGA_VS, VGA_SYNC;
output TD_RESET;
output [17:0] LEDR;
output [6:0] HEX0, HEX1, HEX2, HEX3, HEX4, HEX5,
HEX6, HEX7;

wire video_clock;
// convert CLOCK_27 to required clock speed
pll108MHz pll(.inclk0(CLOCK_27), .c0(video_clock));

assign VGA_CLK = video_clock;


assign VGA_SYNC = 0;

wire candraw;
wire start; // 1 = beginning of frame

wire ball_on;

// Location of pixel to draw


wire [10:0] x;
wire [10:0] y;
// Bats locations
wire [10:0] p1_y;
wire [10:0] p2_y;
// Ball location
wire [10:0] ball_x;
wire [10:0] ball_y;
Fig. 2. Pong Game Flowchart // Scores
wire [3:0] p1_score;
C. System Code wire [3:0] p2_score;
In this project, the system code will divide into two parts wire [1:0] winner; // 0 =
which is code for Altera DE2 board and code for Arduino none, 1 = P1, 2 = P2
Uno. Altera DE2 board code is for the pong game system and assign LEDR[17] = (winner > 0); // light up LEDR-
17 to alert user to reset game
display and using VHDL language. While, Arduino Uno code
is for moving the paddle which is connected with joystick. // Keyboard input wire
The Arduino using C language. [7:0] scan_code; wire
read, scan_ready;
• The code for Altera DE2 board [3]: reg [7:0] scan_history[1:2];
always @ (posedge scan_ready)
module pong( begin
CLOCK_27, scan_history[2] <= scan_history[1];
CLOCK_50, scan_history[1] <= scan_code;
KEY, end
SW,
PS2_CLK, assign TD_RESET = 1'b1;
PS2_DAT,
VGA_R, // VGA output
VGA_G, module vga v(
VGA_B, .clk(video_clock),
VGA_CLK, .vsync(VGA_VS),
VGA_BLANK, .hsync(VGA_HS),
VGA_HS, .x(x),
VGA_VS, .y(y),
VGA_SYNC, .can_draw(candraw),
TD_RESET, .start_of_frame(start) );
LEDR,
// Module to output info to the seven-segment
// Module that renders graphics on-screen displays sevenseg ss(
graphics g( .seg0(HEX0),
.clk(video_clock), .seg1(HEX1),
.candraw(candraw), .seg2(HEX2),
.x(x), .seg3(HEX3),
.y(y), .seg4(HEX4),
.p1_y(p1_y), .seg5(HEX5),
.p2_y(p2_y), .seg6(HEX6),
.ball_on(ball_on), .seg7(HEX7),
.ball_x(ball_x), .score_p1(p1_score),
.ball_y(ball_y), .score_p2(p2_score),
.red(VGA_R), .winner(winner)
.green(VGA_G), );
.blue(VGA_B),
.vga_blank(VGA_BLANK) ); endmodule

// Game logic module • The code for Arduino Uno [4]:


gamelogic gl(
.clock50(CLOCK_50), int pushPin = 7; // potentiometer wiper (middle
.video_clock(video_clock), terminal) connected to analog pin 3
.start(start), int xPin = 0;
.reset(SW[17]), int yPin = 1;
.p1_up((scan_history[1] == 'h1d) && int xMove = 0;
(scan_history[2][7:4] != 'hF)), // 'W' int yMove = 0;
.p1_down((scan_history[1] == 'h1b) && // outside leads to ground and +5V
(scan_history[2][7:4] != 'hF)), // 'S' int valPush = HIGH; // variable to store the value read
.p2_up(~KEY[3]), int valX = 0;
.p2_down(~KEY[0]), int valY = 0;
.p1_y(p1_y), void setup()
.p2_y(p2_y), {
.ball_on(ball_on), pinMode(pushPin,INPUT);
.ball_x(ball_x), Serial.begin(9600); // setup serial
.ball_y(ball_y), digitalWrite(pushPin,HIGH);
.p1_score(p1_score), }
.p2_score(p2_score),
.winner(winner) void loop()
); {
valX = analogRead(xPin); // read the x input pin
// PS/2 keyboard input module valY = analogRead(yPin); // read the y input pin
// Credit: valPush = digitalRead(pushPin); // read the push button
http://www.johnloomis.org/digitallab/ps2lab1/ps2lab1.html input pin
keyboard keybd(
.keyboard_clk(PS2_CLK), Serial.println(String(valX) + " " + String(valY) + " "
.keyboard_data(PS2_DAT), + valPush); //output to Java program
.clock50(CLOCK_50),
.reset(0),
.read(read),
.scan_ready(scan_ready),
.scan_code(scan_code) );

// Module to regulate keyboard input


// Credit:
http://www.johnloomis.org/digitallab/ps2lab1/ps2lab1.html
oneshot pulser(
.pulse_out(read),
.trigger_in(scan_ready),
.clk(CLOCK_50) );
IV. RESULT & ANALYSIS
In this project, the main output is the game display that will
be shown by VGA monitor. The code for the game display
will be insert into Altera DE2 board. After compile the code,
the pong game can be operated. The player can use PS/2
keyboard that connected directly into DE2 board as the
controller. Figure 3 below show the game display from the
VGA monitor.

Fig. 3. Pong Game Display

From the figure 3, the game operated with two players


control the different controller. Player 1 use the PS/2 port
keyboard while player 2 use the toggle switch in DE2 board.
However, this experiment requirement is the system must
have external board; in pong game (Arduino Uno) connected
to joystick as the controller for player 2.
After writing the code for the Arduino Uno and insert it to
the Arduino Uno board, the problem was occurred. The
problem is the DE2 board cannot detect the connection of
Arduino Uno. To do connection between DE2 board and
Arduino Uno, another board called Altera ICB-HSMC board
needed which is the price quite expensive.

VI. CONCLUSION
In this project, the objective to build pong games system by
using Altera DE2 board is achieved. However, the failure to
connect Altera DE2 board with Arduino Uno disturb the flow
of this project. Besides that, the theory learned in Computer
Architecture and Organisation course can be applied in this
project either to perform connection of hardware or writing
code for the pong game system.

REFERENCES
[1]Tic Tac Toe (March 22, 2018), Retrived March 23 from
https://en.wikipedia.org/wiki/Tic-tac-toe
[2] Vigneshraja (August 16, 2014) “Pong Game Using FPGA Kit”,
Retrieved March 19, 2018 from http://www.instructables.com/id/Pong-
game-using-fpga-kit/
[3] Pong (2018) Github Inc, Retrieved April 13 from
https://github.com/felix mo/Pong
[4] Syntaxian (2018) “PC Mouse Made with Arduino and Jouystick”,
Retrieved April 29 from http://www.instructables.com/id/PC-Mouse-
Made-With-Arduino-Uno-and-Joystick/

Das könnte Ihnen auch gefallen