You are on page 1of 4

Application of Computer Architecture and

Organisation Using DE2 Board: Pong Games


Khairulanwar bin Mokhiri (CE150088), Mifzal bin Mohamad Zamri (AE150018), Mohammad Hazwan Hakim bin
Mihat (CE150024), Mohamad Nur Addin bin Md Zain (CE150045), Rengki Oktariady Bin Ahmadin (CE150036)

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 controls the paddle by toggle the
theory that we learned in Computer Architecture and Organisation in joystick. Another player will controls the paddle by using
this project. We tried to create pong game by using Altera DE2 board PS/2 port keyboard which is connected directly into DE2
as the main board and Arduino Uno as external board. This board. The paddle will move across the left or right side of the
assignment is required the students to understand about the screen. Players use the paddles to hit a ball back and forth.
connection between the hardware and study about the function of The goal is for the player to survive the game and not let ball
every parameters of the program code written to obtain the desired slip at the bottom of screen. Because of that this project work
result. by combination of hardware and software such as we using
DE2 as the main board, Arduino Uno as the I/O devices
I. INTRODUCTION joystick and VGA monitor, and apply the coding (VHDL
language) into the project as the output. The DE2 board used
Pong is one of the earliest arcade video games. Pong as the main board of the project and act as mini CPU to run
games using concept table tennis sports game featuring simple the game itself. The language used for this project is VHDL
two-dimensional graphics[1]. The player controls an in-game language. The monitor will connect to the DE2 board using
paddle by moving it vertically across the left or right side of VGA cable. The monitor will display the animation of the
game. The Arduino Uno will act as external board to connect
the screen. They can compete against another player with the joystick. For joystick part, the five female to female
controlling a second paddle on the opposing side. Players use wires will connect to the pins of the joystick module. Then,
the paddles to hit a ball back and forth. The goal is for each connect five male to male wires into the ends of the female
player to reach ten points before the opponent; points are wires and connect them to the Arduino. The figure 1 below
earned when one fails to return the ball to the other[2]. shows the system architecture of the project. At the end of this
This project focuses on build the pong games by using project, the joystick and PS/2 port keyboard will act as input
DE2 board as the main board and Arduino Uno as external to move the paddle left to right on the screen. The paddle will
board. The coding is in VHDL language. The project can be return the ball back and forth. The ball needs to move around
single or multiplayer games and use simple 2D graphics. the screen and bounce back when it touches an object (border
or paddle).
II. OBJECTIVE
The objectives of this project are:
• To build the Pong 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 Pong Games by using Altera DE2
board. This section will divide by three parts which is system
information, flowchart and system code.

Fig. 1. Pong Game System Architecture


B. Flowchart HEX0, HEX1, HEX2, HEX3, HEX4, HEX5, HEX6, HEX7
Figure 2 will show the flowchart of the Pong game. The );
system will start by the monitor display the start screen. Then, input CLOCK_27, CLOCK_50;
wait for a few seconds before start the games. For the start input PS2_CLK, PS2_DAT;
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, VGA_VS,
collision the monitor will display the end game message 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
The Arduino using C language. wire [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 module
VGA_G, 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 displays
// Module that renders graphics on-screen 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] Pong (March 16, 2018), Retrieved March 19 from
https://en.wikipedia.org/wiki/Pong
[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/

You might also like