[ESRC][K55]TankGame Project
-
Upload
hong-nhung-le -
Category
Documents
-
view
226 -
download
1
Transcript of [ESRC][K55]TankGame Project
-
7/27/2019 [ESRC][K55]TankGame Project
1/30
HA NOI UNIVERSITY OF SCIENCE AND TECHNOLOGY
SHOOL OF ELECTRONIC AND TELECOMMUNICATION
EMBEDDED SYSTEM AND RECONFIGURABLE COMPUTING LAB
VHDL TRAINING COURSE
2013
Project:
TANK GAME ON FPGA
Members
Hieu Q. Nguyen
Dong T. Pham
Nhung H. Le
Ha Noi, August 09, 2013
-
7/27/2019 [ESRC][K55]TankGame Project
2/30
VHDL Training courseTank game Project
2
Contents
I. Introduction ................................................................................................................ 41. Target ....................................................................................................................... 42. Summary .................................................................................................................. 43. Requirement............................................................................................................. 4
3.1. Functional requirements: ................................................................................. 43.1.1. Hardware: ..................................................................................................... 4
3.1.2. Software: ............................................................................................................ 43.2. Nonfunctional requirement:.......................................................................... 5
II. Design system ............................................................................................................ 61.System block diagram .............................................................................................. 62.Detail system: ........................................................................................................... 73.Function of each block ............................................................................................. 8
III. Detail block ............................................................................................................. 91. VGA Monitor ........................................................................................................... 9
1.1 Introduction ..................................................................................................... 91.2. Operating principle ........................................................................................... 9
2. VGA block. ............................................................................................................ 122.1. Horizontal synchronization ............................................................................ 122.2. Vertical synchronization ................................................................................. 14
3. PS/2 Keyboard: ...................................................................................................... 163.1.1. Introduction: In our project, we use PS/2 keyboard to communicate
between players and games. .................................................................................. 163.2. Design the PS/2 block: ................................................................................... 16
4.Tank: ....................................................................................................................... 204.1.Direction: ......................................................................................................... 204.2. Movement ....................................................................................................... 20
5. Bullet: .................................................................................................................... 226. Display block ......................................................................................................... 23
6.1 Control exchange between screens .................................................................. 23
-
7/27/2019 [ESRC][K55]TankGame Project
3/30
VHDL Training courseTank game Project
3
6.2 Receive the position of object and display it on the screen ............................ 237. Item ........................................................................................................................ 258. Score ...................................................................................................................... 289. Check score: .......................................................................................................... 29
IV. Problem: .................................................................................................................. 30V. Development ............................................................................................................. 30VI. Conclusion ............................................................................................................... 30
-
7/27/2019 [ESRC][K55]TankGame Project
4/30
VHDL Training courseTank game Project
4
I. Introduction
1. Target
- Practice VHDL programming skills
- Improve peripheral device-communicating skill (VGA,PS/2)
- Improve soft skills (teamwork, presentation,)
2. Summary
Based on the classic games tank, we want to create a new tank games with
some innovation about the gameplay. The games is design for 2 players, each playerscontrol one tank. Mission of each player is to destroy the enemy by shoot enemy, each
time one player be shot, the players HP reduce. The players whose HP come to 0 will
lose. The innovation of our games is the tank can move and shoot follow 16 directions
(when classi tank games has only 4 directions). In addition, the another innovation is
the bullet. When bullet collide the wall, it will rebound, that makes the games more
excited. In game, there is also many items appear at random place on the map, the
items will strengthen the power of players.
3. Requirement
3.1. Functional requirements:
3.1.1. Hardware:
- Implement on kit DE1 of Altera
- Screen display VGA 640x480 pixels
- Keyboard standard PS/2
3.1.2. Software:
- Use Quartus 10.1 sp1
- Hardware Description Language: VHDL.
- Game is designed for two players playing at the same time.
- Items is generated randomly for each time playing.
- Map is designed by programmer
- Times of game is 5 minutes, game over when HP of one player turn to 0 or if the
time is up the winner is the player whose HP is greater.- Players 1 use up, down to move forward or back, use left, right key to rotate the tank
-
7/27/2019 [ESRC][K55]TankGame Project
5/30
VHDL Training courseTank game Project
5
s direction, use p to fire
- Players 2 use a, s to move forward or back, use a, d to rotate the tank s direction, use
left shift to fire
- The game can pause when press f
- Three kind of items+ Boot : Enhance movement speed of tank
+ Bottle: Immortal in 7 seconds
+ Double damage: Increase damage of tank
3.2. Non functional requirement:
- Short responding time for keyboard signal to help players to control character
smoothly.
- Frequency use 50MHz from CLOCK_50 on kit DE1, divide into 25 MHz
- Screen refresh rate: 60Hz- Playing screen:
+ Playing area: size 640 x 384 pixel, element stone and grass display in a
block of size is 16x16 and tank size is a block 32x32.
+ Information area: size 640 x 96 pixel, display items, names, HP of 2
players. Text size is 16 x 16.
-
7/27/2019 [ESRC][K55]TankGame Project
6/30
VHDL Training courseTank game Project
6
II. Design system
Block diagram
1.System block diagram
This game receives and processes data from keyboard, displays
images on VGA 640x480 monitor.
The main block of this program is tank game. The input
and output of this block are:
The input signal:
- CLOCK_50: 50 MHz clock from kit DE1.
- PS2_DAT: data signal of keyboard through PS2 pin.
- PS2_CLK: special clock of signal transferring type through
PS2 gate.
The output signal:
- VGA_HS: horizontal synchronous signal of monitor.
- VGA_VS: vertical synchronous signal of monitor.
- VGA_RGB: color signal of the pixel that is being processed
-
7/27/2019 [ESRC][K55]TankGame Project
7/30
VHDL Training courseTank game Project
7
2.Detail system:
-
7/27/2019 [ESRC][K55]TankGame Project
8/30
VHDL Training courseTank game Project
8
3.Function of each block
Block Function
VGA_sync Control VGA synchronous
PS/2
Receive signal from keyboard and send
control signal
Display
Exchange between screen
Display text, display map, tank, bullet,
HP
Tank Control tank s direction, position
Bullet Controlbullet s position
Score Calculate tank s HP
Check score Determine result of the game
Item Generate item on map randomly
-
7/27/2019 [ESRC][K55]TankGame Project
9/30
VHDL Training courseTank game Project
9
III. Detail block1. VGA Monitor
1.1 IntroductionVGA (video graphics array) is a video display standard introduced in the late1980s by IBM and is widely supported by PC graphics hardware and monitor. We will
design a basic 4096-color 640-by-480 resolution interface for CRT (cathode ray tube)
monitors.
1.2. Operating principle
Conceptual diagram of a CRT MonitorA vertical deflection coil and a horizontal deflection coil outside the tube
produce magnetic-field to control how the electron beam travels and to determine
where on the screen the electrons hit. In todays monitors, the electron beam traverses
the screen systematically in a fixed pattern, from left to right and from top to bottom.
-
7/27/2019 [ESRC][K55]TankGame Project
10/30
VHDL Training courseTank game Project
10
CRT scanning pattern
-
7/27/2019 [ESRC][K55]TankGame Project
11/30
VHDL Training courseTank game Project
11
The electron beam moves from the left edge to the right edge as the voltage
applied to the horizontal deflection coil gradually increases. After reaching the rightedge, the beam returns rapidly to the left edge when the voltage changes to 0.
Example for three-bit VGA color combination
-
7/27/2019 [ESRC][K55]TankGame Project
12/30
VHDL Training courseTank game Project
12
2. VGA block.
640x480 are the number of pixels that can be displayed on the screen. Eachhorizontal line has 640 pixels and each vertical line has 480 pixels. In fact, there are
800 pixels in horizontal line and 525 pixels in vertical line that need to be scaned. The
pixels and lines which are not displayed are called black border.2.1. Horizontal synchronization
A period of horizontal synchronous signal contains 800 pixels and can be
divided into four regions:
-
7/27/2019 [ESRC][K55]TankGame Project
13/30
VHDL Training courseTank game Project
13
Display: region where the pixels are actually displayed on the screen. Thelength of this region is 640 pixels.
Retrace: region in which the electron beams return to the left edge. Thevideo signal should be disabled (i.e., black), and the length of this region is96 pixels.
Right border: region that forms the right border of the display region. It isalso known as the front porch (i.e., porch before retrace). The video signal
should be disabled, and the length of this region is 16 pixels.
Left border: region that forms the left border of the display region. It is alsoknown as the back porch (i.e., porch after retrace). The video signal should
be disabled, and the length of this region is 48 pixels.
Note that the lengths of the right and left borders may vary for differentbrands of monitors.
-
7/27/2019 [ESRC][K55]TankGame Project
14/30
VHDL Training courseTank game Project
14
The horizontal synchronous signal can be obtained by a special mod-800
counter and a decoding circuit.The counts are marked on the top of the horizontal synchronous signa. We
intentionally start the counting from the beginning of the display region. This allows
us to use the counter output as the horizontal (x-axis) coordinate. This output
constitutes the pixel-x signal. The horizontal synchronous signal goes low when the
counters output is between 656 and 751.
2.2. Vertical synchronization
During the vertical scan, the electron beams move gradually from top to bottom
and then return to the top. This corresponds to the time required to refresh the entire
screen. The format of the vertical synchronous signal is similar to that of the horizontal
synchronous signal. The time unit of the movement is represented in terms of
horizontal scan lines. A period of the vertical synchronous signal is 525 lines and canbe divided into four regions:
Display: region where the horizontal lines are actually displayed on the screen.The length of this region is 480 lines.
Retrace: region that the electron beams return to the top of the screen. Thevideo signal should be disabled, and the length of this region is 2 lines.
-
7/27/2019 [ESRC][K55]TankGame Project
15/30
VHDL Training courseTank game Project
15
Bottom border: region that forms the bottom border of the display region. It isalso known as the front porch (i.e., porch before retrace). The video signal
should be disabled, and the length of this region is 10 lines.
Top border: region that forms the top border of the display region. It is alsoknown as the back porch (i.e., porch after retrace). The video signal should be
disabled, and the length of this region is 33 lines.
The vertical synchronous signal can be obtained by a special mod-525 counter and
a decoding circuit. Again, we intentionally start counting from the beginning of the
display region. This allows us to use the counter output as the vertical (y-axis)
coordinate. This output constitutes the pixel-y signal. The vertical synchronous signal
goes low when the line count is 490 or 491.
-
7/27/2019 [ESRC][K55]TankGame Project
16/30
VHDL Training courseTank game Project
16
3. PS/2 Keyboard:
3.1.1. Introduction:
In our project, we use PS/2 keyboard to communicate between players andgames.
Operating principle:
- When press a key, the make code is transmitted. If a key is pressed continuously the
make code is transmitted repeatedly.
- When release a key, the break code of key is transmitted.
3.2. Design the PS/2 block:
The design of the PS2 port receiving subsystem is somewhat similar to that of a
UART receiver. Instead of using the oversampling scheme, the falling-edge of the
ps2c signal is used as the reference point to retrieve data. The subsystem includes a
falling edge detection circuit, which generates a one-clock-cycle tick at the falling
edge of the ps2c signal, and the receiver, which shifts in and assembles the serial bits.
-
7/27/2019 [ESRC][K55]TankGame Project
17/30
VHDL Training courseTank game Project
17
Timing Diagram of a PS/2 port
The flowchart show behind is the ASMD chart of the PS/2 receiver block. .
The receiver is initially in the idle state. After the first falling-edge tick the FSMD
shifts in the start bit and moves to the dps state. Since the received data is in fixed
format, we shift in the remaining 10 bits in a single state rather than using separate
data, parity, and stop states. The FSMD then moves to the load state, in which one
extra clock cycle is provided to complete the shifting of the stop bit, and the psrx-
done-tick signal is asserted for one clock cycle
-
7/27/2019 [ESRC][K55]TankGame Project
18/30
VHDL Training courseTank game Project
18
ASMD of PS/2 receiver
Our PS/2 block have 3 mini block ps2_receiver, 2 buffer, and keyboard
controller.
-PS/2 receiver receive scan code from the keyboard. Scan code is sent to 2 buffer and
then to keyboard controller. Keyboard controller will read scan code and identify
which key is pressed and send it to output. This figure behind is the block diagram of
-
7/27/2019 [ESRC][K55]TankGame Project
19/30
VHDL Training courseTank game Project
19
PS/2 keyboard.
Block diagram of PS/2 block
-
7/27/2019 [ESRC][K55]TankGame Project
20/30
VHDL Training courseTank game Project
20
4.Tank:
4.1.Direction:
Tank s direction
- Tank can rotate 16 directions
- Each direction is numbered
- There is a signal name dir_reg which manage direction of tank
- Each time, right key(with player 1) or d key( with player 2) is press, direction
plus one
- Each time, left key(with player 1) or a key( with player 2) is press, direction
decrease one
- With each different dir_reg, the game will load the suitable image of tank to
the screen
4.2. Movement
- With different direction, the velocity according to x-ordinate and velocity
according y-ordinate is different
- To resolve this problem, we use 2 array is velocity_x and velocity_y with
index of two arrays is signal dir_reg to save the velocity
- The value of 2 array will show here
-
7/27/2019 [ESRC][K55]TankGame Project
21/30
VHDL Training courseTank game Project
21
velocity_x = { 0 , 1, 2, 2, 2, 2, 2, 1, 0 , -1 , -2 , -2, ,2 , -2, -2, -1, 0 };
velocity_y = { 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, 0, 1, 2, 2, 2, 2 };
- Each time key up is pressed and ref_tick = 1 then
tank_next_x
-
7/27/2019 [ESRC][K55]TankGame Project
22/30
VHDL Training courseTank game Project
22
5. Bullet:
- Each tank can fire 4 bullets at maximum, if a tank has already fire all 4
bullets, this tank have to wait for a while till the bullet disappears then tank cancontinue to fire
- Bullet will move follow the current direction of tank
- If wall is detected, the bullet will rebound
- If bullet move to corner of the wall, hit the tank or rebound four or five times,
the bullet will disappears
-
7/27/2019 [ESRC][K55]TankGame Project
23/30
VHDL Training courseTank game Project
23
6. Display block
Function of display block is- Control exchange between screen
- Receive the position of objects (tank, bullet, map, text) and display it on the
screen
6.1 Control exchange between screens
This figure behind now show you the FSM of screens
FSM state of screens
6.2 Receive the position of object and display it on the screen
Display block receive the position of objects and turn it into signal tank_on,
bullet_on, text_on, grass_on, wall_on and display it in different layer.
6.2.1 Grass and wall display
- Wall and grass is displayed in a 16x16 block
- We store image of each element in ROM using ROM 1 port LPM in Quartus
II. Input of component grass and stone is 4 bit least of pixel x and pixel y, output is 12bit equivalent to 12 bit colors. Base on control signal of each element, color of each
pixel will be assigned by output rgb from corresponding ROM.
6.2.2 Tank display
Tank s image
-
7/27/2019 [ESRC][K55]TankGame Project
24/30
VHDL Training courseTank game Project
24
- Tank is displayed in a 32x32 block
- We need to create 16 images equivalent 16 directions of each tank, there are
two tanks so we need totally 32 images of tank
- We also use ROM 1 port LPM in Quartus to store image- There are total 32 images of tank, so we need to reduce quality of images of
tank from 12 bit to 3 bit to fit the size of memory
- So we use Photoshop to create images 3 bit colors so we can resolve this
problem
6.2.3 Text display
Each character is 8x8 bit word of pixel data.
To display an "A" the character ROM would contain only the starting address
000001 for the font table for "A". The 8x8 font in the character generation ROM
would generate the letter "A" using the following eight memory words:
-
7/27/2019 [ESRC][K55]TankGame Project
25/30
VHDL Training courseTank game Project
25
7. Item
Item block has four blocks include item1_gen block, item2_gen block, item3_gen
block and item_process block. Item1 is double damage item. Item2 is heal item.
Item3 is fast boots item.
-
7/27/2019 [ESRC][K55]TankGame Project
26/30
VHDL Training courseTank game Project
26
In three blocks item1_gen, item2_gen, item3_gen is designed in order to test
appearance of three item. We use two signal pix_x and pix_y so appear items in
identified position. Signal tank_got_item is used so dispear items.
-
7/27/2019 [ESRC][K55]TankGame Project
27/30
VHDL Training courseTank game Project
27
Algorithms of eat item and appear items
Block item process show eat item process. Time implementation features of items is
decided by tank_got_item . After times tank_got_item =1 then item will appear and
features of items is finished.
Item_on =1 and tank_on=1 in this position then tank_got_item=1.
-
7/27/2019 [ESRC][K55]TankGame Project
28/30
VHDL Training courseTank game Project
28
8. Score
Score block show score of two player in playing process.
Signal in is tank_got_item and signal out is output in order to display score in play
screen. Tank_got_item has three type include HP_got_item, damage_got_item,
HP_decrease.
Score max =100. If HP_decrease =1 then score
-
7/27/2019 [ESRC][K55]TankGame Project
29/30
VHDL Training courseTank game Project
29
9. Check score:
-
7/27/2019 [ESRC][K55]TankGame Project
30/30
VHDL Training courseTank game Project
IV. Problem:
- Bullet dont rebound exactly
- Tank s movement is extremely not smooth
V. Development
- Make sound for games
- Improve items make game more interesting
VI. Conclusion
After a month, our groups finish project about tank game. The games can be
played extremely well though still have some problems. After this, we improve so
much about VHDL skills, teamwork, soft skill
Finally, we thanks so much to Mr. Trong, Mr. Luc, Mr. Tung helped me so
much in this time!
Group3 K55