Documente Academic
Documente Profesional
Documente Cultură
Monsoon 2017
SUBMITTED BY
Reg. No. Name
M170251EC AVISHEK SARKAR
M170459EC KRISHNAJITH S S
SNAKE GAME
USING FPGA
This report describes the successful implementation of Snake game on a Xilinx Zybo Zynq – 7000 FPGA kit
and a VGA monitor. The game logic is written in Verilog and the hardware is described in Verilog HDL. The
game layout is shown above.
Page
No
Aim…………………………………………………………………………………………. 4
Schematic………………………………………………………………….……………… 6
Verilog Code……………………………………………………………………………… 7
Constraint File…………………………………………………………………………… 11
Simulation Waveform…………………………………………………………………… 12
Implemented Design……………………………………………………...……………… 12
Implemented Schematic…………………………………………………………………… 13
Synthesis Report………………………………………………………….……………… 13
Conclusion………………………………………………………………...……………… 16
References………………………………………………………………………………… 16
The ZYBO Zynq Board) is a feature-rich, ready-to-use, entry-level embedded software and digital circuit
development platform built around the smallest member of the Xilinx Zynq-7000 family, the Z-7010. The Z-
7010 is based on the Xilinx All Programmable System-on-Chip (AP SoC) architecture, which tightly
integrates a dual-core ARM Cortex-A9 processor with Xilinx 7-series Field Programmable Gate Array
(FPGA) logic. When coupled with the rich set of multimedia and connectivity peripherals available on the
ZYBO, the Zynq Z-7010 can host a whole system design. The on-board memories, video and audio I/O, dual-
role USB, Ethernet, and SD slot will have your design up-and-ready with no additional hardware needed.
Additionally, six Pmod ports are available to put any design on an easy growth path.
CRT-based VGA displays use amplitude-modulated moving electron beams (or cathode rays) to display
information on a phosphor-coated screen. LCD displays use an array of switches that can impose a voltage
across a small amount of liquid crystal, thereby changing light permittivity through the crystal on a pixel-by-
pixel basis. Although the following description is limited to CRT displays, LCD displays have evolved to use
the same signal timings as CRT displays (so the “signals” discussion below pertains to both CRTs and LCDs).
Color CRT displays use three electron beams (one for red, one for blue, and one for green) to energize the
phosphor that coats the inner side of the display end of a cathode ray tube.
A VGA controller circuit must generate the HS and VS timings signals and coordinate the delivery of video
data based on the pixel clock. The pixel clock defines the time available to display one pixel of information.
The VS signal defines the “refresh” frequency of the display, or the frequency at which all information on the
display is redrawn. The minimum refresh frequency is a function of the display’s phosphor and electron beam
intensity, with practical refresh frequencies falling in the 50Hz to 120Hz range. The number of lines to be
displayed at a given refresh frequency defines the horizontal “retrace” frequency. For a 640-pixel by 480-row
display using a 25MHz pixel clock and 60 +/-1Hz refresh, the signal timings shown in Fig. 11 can be derived.
Timings for sync pulse width and front and back porch intervals (porch intervals are the pre- and post-sync
pulse times during which information cannot be displayed) are based on observations taken from actual VGA
displays.
Figure 5: Signal timings for a 640-pixel by 480 row display using a 25MHz pixel clock and 60Hz vertical refresh.
Vivado Design Suite is a software suite produced by Xilinx for synthesis and analysis of HDL designs,
superseding Xilinx ISE with additional features for system on a chip development and high-level synthesis.
Vivado enables developers to synthesize (compile) their designs, perform timing analysis,
examine RTL diagrams, simulate a design's reaction to different stimuli, and configure the target device with
the programmer.
SCHEMATIC
wire VGA_clk,update_clock,displayArea;
wire[9:0] xCount;
wire[9:0] yCount;
wire [3:0] direction;
wire [9:0] randX;
wire [9:0] randomX;
wire [8:0] randY;
wire [8:0] randomY;
reg apple;
reg border;
wire R,G,B;
reg snake;
reg gameOver;
reg head;
reg [9:0] appleX;
reg [9:0] appleY;
reg inX, inY;
reg [9:0] snakeX;
reg [8:0] snakeY;
initial
begin
snakeX = 10'd20;
snakeY = 9'd20;
end
always@(posedge VGA_clk)
begin
border <= ((((xCount >= 0) & (xCount < 15) & ((yCount >= 220) & (yCount < 280))) |
(xCount >= 630) & (xCount < 641) &
((~yCount >= 220) & (~yCount < 280))) | ((yCount >= 0) & (yCount < 15) |
(yCount >= 465) & (yCount < 481)));
end
always@(posedge VGA_clk)
begin
if(reset | gameOver)
begin
appleX = 350;
appleY = 300;
always@(posedge update_clock)
begin
if(direction == 4'b0001) begin snakeX = snakeX - 5; end
else if (direction == 4'b0010 ) begin snakeX = snakeX + 5; end
else if (direction == 4'b0100) begin snakeY = snakeY - 5; end
else if(direction == 4'b1000) begin snakeY = snakeY + 5; end
end
always@(posedge VGA_clk)
begin
head <= (xCount > snakeX & xCount < (snakeX+10)) & (yCount > snakeY & yCount <
(snakeY+10));
end
always@(posedge VGA_clk)
begin
red = {5{R}};
green = {6{G}};
blue = {5{B}};
end
endmodule
integer check = 4;
integer a = 0;
always@(posedge clk)
begin
if(a<check)
begin
a <= a + 1;
VGA_clk <= 0;
end
else
begin
a <= 0;
VGA_clk <= 1;
end
end
endmodule
endmodule
VGA GENERATOR
module VGAgenerator(VGA_clk, xCount, yCount, displayArea, VGA_hSync, VGA_vSync);
input VGA_clk;
output reg [9:0] xCount, yCount;
output reg displayArea;
output VGA_hSync, VGA_vSync;
always@(posedge VGA_clk)
begin
if(xCount == maxH)
xCount <= 0;
else
xCount <= xCount + 1'b1;
end
always@(posedge VGA_clk)
begin
if(xCount == maxH)
begin
if(yCount == maxV)
yCount <= 0;
else
yCount <= yCount + 1'b1;
end
end
always@(posedge VGA_clk)
begin
displayArea <= ((xCount < porchHF) && (yCount < porchVF));
end
endmodule
RANDOM POINT
module Random(VGA_clk,randX,randY);
input VGA_clk;
output reg [9:0]randX;
output reg [8:0]randY;
always @ (i,j)
begin
randX <= i;
randY <= j;
end
endmodule
BUTTON INPUT
module ButtonInput(clk,l,r,u,d,direction);
input clk,l,r,u,d;
output reg [3:0] direction;
always@(posedge clk)
begin
if(l == 1) begin
direction <= 4'b0001; //left
end
else if(r == 1) begin
direction <= 4'b0010; //right
end
else if(u == 1) begin
direction <= 4'b0100; //up
end
else if(d == 1) begin
direction <=4'b1000; //down
end
endmodule
CONSTRIANT FILE
##Clock signal
set_property -dict { PACKAGE_PIN L16 IOSTANDARD LVCMOS33 } [get_ports { clk }];
#IO_L11P_T1_SRCC_35 Sch=sysclk
create_clock -add -name sys_clk_pin -period 8.00 -waveform {0 4} [get_ports { clk }];
##Buttons
set_property -dict { PACKAGE_PIN R18 IOSTANDARD LVCMOS33 } [get_ports { l }];
#IO_L20N_T3_34 Sch=BTN0
set_property -dict { PACKAGE_PIN P16 IOSTANDARD LVCMOS33 } [get_ports { r }];
#IO_L24N_T3_34 Sch=BTN1
set_property -dict { PACKAGE_PIN V16 IOSTANDARD LVCMOS33 } [get_ports { u }];
#IO_L18P_T2_34 Sch=BTN2
set_property -dict { PACKAGE_PIN Y16 IOSTANDARD LVCMOS33 } [get_ports { d }];
#IO_L7P_T1_34 Sch=BTN3
##VGA Connector
set_property -dict { PACKAGE_PIN M19 IOSTANDARD LVCMOS33 } [get_ports { red[0] }];
#IO_L7P_T1_AD2P_35 Sch=VGA_R1
set_property -dict { PACKAGE_PIN L20 IOSTANDARD LVCMOS33 } [get_ports { red[1] }];
#IO_L9N_T1_DQS_AD3N_35 Sch=VGA_R2
set_property -dict { PACKAGE_PIN J20 IOSTANDARD LVCMOS33 } [get_ports { red[2] }];
#IO_L17P_T2_AD5P_35 Sch=VGA_R3
set_property -dict { PACKAGE_PIN G20 IOSTANDARD LVCMOS33 } [get_ports { red[3] }];
#IO_L18N_T2_AD13N_35 Sch=VGA_R4
set_property -dict { PACKAGE_PIN F19 IOSTANDARD LVCMOS33 } [get_ports { red[4] }];
#IO_L15P_T2_DQS_AD12P_35 Sch=VGA_R5
set_property -dict { PACKAGE_PIN H18 IOSTANDARD LVCMOS33 } [get_ports { green[0] }];
#IO_L14N_T2_AD4N_SRCC_35 Sch=VGA_G0
set_property -dict { PACKAGE_PIN N20 IOSTANDARD LVCMOS33 } [get_ports { green[1] }];
#IO_L14P_T2_SRCC_34 Sch=VGA_G1
set_property -dict { PACKAGE_PIN L19 IOSTANDARD LVCMOS33 } [get_ports { green[2] }];
#IO_L9P_T1_DQS_AD3P_35 Sch=VGA_G2
set_property -dict { PACKAGE_PIN J19 IOSTANDARD LVCMOS33 } [get_ports { green[3] }];
#IO_L10N_T1_AD11N_35 Sch=VGA_G3
set_property -dict { PACKAGE_PIN H20 IOSTANDARD LVCMOS33 } [get_ports { green[4] }];
#IO_L17N_T2_AD5N_35 Sch=VGA_G4
set_property -dict { PACKAGE_PIN F20 IOSTANDARD LVCMOS33 } [get_ports { green[5] }];
#IO_L15N_T2_DQS_AD12N_35 Sch=VGA=G5
set_property -dict { PACKAGE_PIN P20 IOSTANDARD LVCMOS33 } [get_ports { blue[0] }];
#IO_L14N_T2_SRCC_34 Sch=VGA_B1
set_property -dict { PACKAGE_PIN M20 IOSTANDARD LVCMOS33 } [get_ports { blue[1] }];
#IO_L7N_T1_AD2N_35 Sch=VGA_B2
set_property -dict { PACKAGE_PIN K19 IOSTANDARD LVCMOS33 } [get_ports { blue[2] }];
#IO_L10P_T1_AD11P_35 Sch=VGA_B3
set_property -dict { PACKAGE_PIN J18 IOSTANDARD LVCMOS33 } [get_ports { blue[3] }];
#IO_L14P_T2_AD4P_SRCC_35 Sch=VGA_B4
set_property -dict { PACKAGE_PIN G19 IOSTANDARD LVCMOS33 } [get_ports { blue[4] }];
#IO_L18P_T2_AD13P_35 Sch=VGA_B5
set_property -dict { PACKAGE_PIN P19 IOSTANDARD LVCMOS33 } [get_ports h_sync];
#IO_L13N_T2_MRCC_34 Sch=VGA_HS
set_property -dict { PACKAGE_PIN R19 IOSTANDARD LVCMOS33 } [get_ports v_sync];
#IO_0_34 Sch=VGA_VS
Snake test(red,green,blue,h_sync,v_sync,clk,reset,l,r,u,d);
always
#1 clk = ~clk;
initial
begin
clk = 0; reset = 0;
l = 1; r = 0; u = 0; d = 0; #30;
l = 0; r = 1; u = 0; d = 0; #30;
l = 0; r = 0; u = 1; d = 0; #30;
l = 0; r = 0; u = 0; d = 1; #30;
$finish;
end
endmodule
SIMULATION WAVEFORM
SYNTHESIS REPORT
Start RTL Component Statistics
---------------------------------------------------------------------------------
Detailed RTL Component Info :
+---Adders :
3 Input 12 Bit Adders := 3
3 Input 11 Bit Adders := 1
2 Input 10 Bit Adders := 5
2 Input 9 Bit Adders := 1
+---Registers :
10 Bit Registers := 6
9 Bit Registers := 2
6 Bit Registers := 1
5 Bit Registers := 2
4 Bit Registers := 1
1 Bit Registers := 11
+---Muxes :
2 Input 10 Bit Muxes := 1
2 Input 9 Bit Muxes := 1
4 Input 4 Bit Muxes := 1
2 Input 4 Bit Muxes := 2
2 Input 1 Bit Muxes := 6
5 Input 1 Bit Muxes := 1
3 Input 1 Bit Muxes := 1
---------------------------------------------------------------------------------
Finished RTL Component Statistics
---------------------------------------------------------------------------------
REFERENCES
[1] Renuka A. Wasu, Vijay R. Wadhankar, “Design and Implementation of VGA Controller on FPGA”,
International Journal of Innovative Research in Computer and Communication Engineering, Vol. 3, Issue 7,
July 2015.
[2] Fangqin Ying, XiaoqingFeng, “Design and Implementation of VGA Controller Using FPGA”,
International Journal of Advancements in Computing Technology (IJACT), Vol. 4, No. 17, pp. 458-465, Sep
2012.
[2] Ila.Nagarjuna, Pillem. Ramesh, “An FSM Based VGA Controller with 640×480 Resolution”, International
Journal of Engineering and Advanced Technology (IJEAT), Vol. 2, Issue – 4, pp. 881-885, April 2013.
[3] [11] SamirPalnitkar, Verilog HDL: A Guide to Digital Design and Synthesis”, Sun Microsystems, Inc.,
USA, 2003.
[4] “ZYBO™ FPGA Board Reference Manual”, Revised April 11, 2016.