EDA课程设计乒乓球游戏机.docx

上传人:b****5 文档编号:5026176 上传时间:2022-12-12 格式:DOCX 页数:19 大小:3.66MB
下载 相关 举报
EDA课程设计乒乓球游戏机.docx_第1页
第1页 / 共19页
EDA课程设计乒乓球游戏机.docx_第2页
第2页 / 共19页
EDA课程设计乒乓球游戏机.docx_第3页
第3页 / 共19页
EDA课程设计乒乓球游戏机.docx_第4页
第4页 / 共19页
EDA课程设计乒乓球游戏机.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

EDA课程设计乒乓球游戏机.docx

《EDA课程设计乒乓球游戏机.docx》由会员分享,可在线阅读,更多相关《EDA课程设计乒乓球游戏机.docx(19页珍藏版)》请在冰豆网上搜索。

EDA课程设计乒乓球游戏机.docx

EDA课程设计乒乓球游戏机

《基于FPGA的数字系统设计》项目设计文档

 

项目名称:

乒乓球比赛游戏机

 

姓名:

院系:

应用技术学院

专业:

电子信息工程

学号:

指导教师:

陈强

 

完成时间:

2012年06月19日

 

基于FPGA的数字系统设计项目成绩评价表

设计题目

乒乓球比赛游戏机

设计要求

设计一个乒乓球比赛游戏机,能模拟比赛的基本过程和规则并能自动裁判和记分,具体要求如下:

(1)使用乒乓球游戏机的双方在不同位置发球或击球;

(2)乒乓球的位置和移动方向由灯亮和依次亮的方向决定。

使用者根据球的位置发出相应的动作;

(3)比赛用11分为一局来进行,双方设置各自的记分牌,任意一方先记满11分就获胜此局。

当记分牌清零后,开始新的一局比赛;

(4)比赛结束后音乐自动响起。

设计过程

用8个LED排成一条直线,以中点为界,两边各代表参赛双方的位置,其中一只点亮的LED指示球的当前位置,点亮的LED依次从左到右,或从右到左,其移动的速度应能调节。

“球”(点亮的那只LED)运动到某方的最后一位时,参赛者应能果断地按下位于自己一方的按纽开关,即表示启动球拍击球,若击中,则球向相反方向运动;若未中,球掉出桌外,则对方得一分。

设置自动记分电路,甲乙双方各用两位数码管进行记分显示,每计满11分为1局。

甲乙双方各设一个发光二极管表示拥有发球权,每隔2次自动交换发球权,拥有发球权的一方发球才有效。

项目设计成绩评价

评价项目

指标

满分

评分

工作量、工作态度和出勤率

按期圆满的完成了规定的任务,难易程度和工作量符合教学要求,工作努力,遵守纪律,出勤率高,工作作风严谨,善于与他人合作。

30

课程设计质量

项目设计系统架构合理,设计过程简练正确,分析问题思路清晰,结构严谨,文理通顺,撰写规范,图表完备正确。

40

创新

工作中有创新意识,对前人工作有一些改进或有一定应用价值。

15

答辩

能正确回答指导教师所提出的问题。

15

综合成绩等级

指导教师:

年月日

目录

1项目名称、内容与要求………………………………………04页

1.1设计内容…………………………………………………04页

1.2具体要求…………………………………………………04页

2系统整体架构(ArchitectureDescription)……………04页

2.1设计思路…………………………………………………04页

2.2系统原理(包含:

框图等阐述与设计说明等内容)…04页

3系统设计(含HDL或原理图输入设计)………………………05页

3.1HDL代码…………………………………………………05页

3.2系统整体电路图(或RTL级电路图)…………………12页

4系统仿真(SimulationWaveform)…………………………13页

5FPGA实现(FPGAImplementation)………………………14页

6总结(Closing)………………………………………………16页

参考书目(Reference):

…………………………………………16页

 

一、项目名称、内容与要求

1.1项目名称

乒乓球比赛游戏机

1.2设计内容

设计一个由甲乙双方参赛,二人乒乓球游戏机。

用8个(或更多个)LED排成一条直线,以中点为界,两边各代表参赛双方的位置,其中一只点亮的LED指示球的当前位置,点亮的LED依次从左到右,或从右到左,其移动的速度应能调节。

当“球”(点亮的那只LED)运动到某方的最后一位时,参赛者应能果断地按下位于自己一方的按纽开关,即表示启动球拍击球,若击中,则球向相反方向运动;若未中,球掉出桌外,则对方得一分。

设置自动记分电路,甲乙双方各用两位数码管进行记分显示,每计满11分为1局。

甲乙双方各设一个发光二极管表示拥有发球权,每隔2次自动交换发球权,拥有发球权的一方发球才有效。

1.3具体要求

(1)使用乒乓球游戏机的双方在不同位置发球或击球。

(2)乒乓球的位置和移动方向由灯亮和依次亮的方向决定。

使用者根据球的位置发出相应的动作。

(3)比赛用11分为一局来进行,双方设置各自的记分牌,任意一方先记满21分就获胜此局。

当记分牌清零后,开始新的一局比赛。

(4)比赛结束后音乐自动响起。

二、系统整体架构(ArchitectureDescription)

2.1设计思路

根据系统设计的要求,乒乓球比赛游戏机的电路原理框图如下:

三、系统设计(含HDL或原理图输入设计)

3.1VHDL代码

比赛模块

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_arith.all;

useieee.std_logic_unsigned.all;--引用必要的库函数和包集合

entitycompeteis--实体名为pingpong

port(reset:

instd_logic;

clk_1:

instd_logic;

startbutton:

instd_logic;--开始游戏输入端口

serve:

instd_logic_vector(1downto0);--发球输入端口

hit1,hit2:

instd_logic;--甲和乙的击球输入端口

light:

outstd_logic_vector(1to8);--控制8个发光二极管的输出端口

music_begin:

outstd_logic;--控制音乐开始的输出端口

counta,countb:

outstd_logic_vector(3downto0));--2个用于控制4个7段译码器的输出端口

endcompete;

architectureoneofcompeteis

typepingpongis(waitserve,light1on,ballmoveto2,allow2hit,

light8on,ballmoveto1,allow1hit);

---设置7个状态,为枚举数据类型,记为pingpong

signalstate:

pingpong;

signali:

integerrange0to8;

signalcount1,count2,count3,count4:

std_logic_vector(3downto0):

="0000";

---内部计数器,是4位二进制变量

begin

process(clk_1)

begin

if(clk_1'eventandclk_1='1')then

ifcount3="0001"orcount4="0001"then

music_begin<='1';

endif;

if(reset='1')then

music_begin<='0';

endif;

endif;

endprocess;

process(clk_1)--状态机进程

--clk_1作为敏感信号触发进程

begin--进程开始

ifreset='1'then--异步置位

i<=0;count1<="0000";count2<="0000";count3<="0000";count4<="0000";

elsifclk_1'eventandclk_1='1'then--当处于时钟inclock上升沿时

ifcount1="1011"then

i<=0;count1<="0000";count2<="0000";count3<=count3+1;

elsifcount2="1011"then

i<=0;count1<="0000";count2<="0000";count4<=count4+1;

elsifstartbutton='0'then

i<=0;count1<="0000";count2<="0000";count3<="0000";count4<="0000";

else--以下case语句是程序中最关键的状态机部分

casestateis

whenwaitserve=>--进程处于等待发球状态

caseserveis

when"01"=>i<=1;state<=light1on;

when"10"=>i<=8;state<=light8on;

when"11"=>i<=0;

whenothers=>i<=0;

endcase;

whenlight1on=>--进程处于第一盏灯亮状态

i<=2;

ifhit2='1'then

i<=0;

count1<=count1+1;state<=waitserve;

else

state<=ballmoveto2;

endif;

whenlight8on=>--进程处于第八盏灯亮状态

i<=7;

ifhit1='1'then

i<=0;

count2<=count2+1;state<=waitserve;

else

state<=ballmoveto1;

endif;

whenballmoveto1=>--进程处于球向乙移动状态

ifhit1='1'then

i<=0;

count2<=count2+1;state<=waitserve;

elsifi=2theni<=1;

state<=allow1hit;

elsei<=i-1;

endif;

whenballmoveto2=>--进程处于球向乙移动状态

ifhit2='1'then

i<=0;

count1<=count1+1;state<=waitserve;

elsifi=7theni<=8;

state<=allow2hit;

elsei<=i+1;

endif;

whenallow1hit=>--进程处于允许甲击球状态

ifhit1='1'theni<=2;

state<=ballmoveto2;

elsecount2<=count2+1;i<=0;

state<=waitserve;

endif;

whenallow2hit=>--进程处于允许乙击球状态

ifhit2='1'theni<=7;state<=ballmoveto1;

elsecount1<=count1+1;i<=0;

state<=waitserve;

endif;

endcase;

endif;

endif;

endprocess;

counta<=count1;countb<=count2;

--进程处i信号控制发光二极管的亮暗

light<="10000000"when(i=1)else

"01000000"when(i=2)else

"00100000"when(i=3)else

"00010000"when(i=4)else

"00001000"when(i=5)else

"00000100"when(i=6)else

"00000010"when(i=7)else

"00000001"when(i=8)else

"00000000";--其他情况所有发光二极管都暗

endone;

分频模块

libraryIEEE;

useIEEE.std_logic_1164.all;

useieee.std_logic_arith.all;

useIEEE.std_logic_unsigned.all;

entitydivision16is

port(cp:

instd_logic;

clk_4:

outstd_logic);

enddivision16;

architecturedivision_bodyofdivision16is

signalcount:

std_logic_vector(3downto0);

begin

process(cp)

begin

if(cp'eventandcp='1')then

if(count="1111")then

count<=(others=>'0');

else

count<=count+1;

endif;

endif;

endprocess;

process(cp)

begin

if(cp'eventandcp='1')then

if(count="1111")then

clk_4<='1';

else

clk_4<='0';

endif;

endif;

endprocess;

enddivision_body;

译码器部分

libraryieee;

useieee.std_logic_1164.all;

entitydispis

port(d:

instd_logic_vector(3downto0);

q:

outstd_logic_vector(6downto0));

enddisp;

architecturedisp_arcofdispis

begin

process(d)

begin

casedis

when"0000"=>q<="0111111";

when"0001"=>q<="0000110";

when"0010"=>q<="1011011";

when"0011"=>q<="1001111";

when"0100"=>q<="1100110";

when"0101"=>q<="1101101";

when"0110"=>q<="1111101";

when"0111"=>q<="0100111";

when"1000"=>q<="1111111";

when"1001"=>q<="1101111";

whenothers=>q<="0000000";

endcase;

endprocess;

enddisp_arc;

数码管选择

LIBRARYIEEE;

USEIEEE.STD_LOGIC_1164.ALL;

ENTITYmux2IS

PORT(a,b:

INSTD_LOGIC_VECTOR(6downto0);

sel:

INSTD_LOGIC;

c:

OUTSTD_LOGIC_VECTOR(6downto0));

ENDmux2;

ARCHITECTUREexampleOFmux2IS

BEGIN

PROCESS(sel)

BEGIN

IF(SEL='1')THEN

c<=a;

ELSE

c<=b;

ENDIF;

ENDPROCESS;

ENDexample;

音乐模块(两只老虎)

libraryIEEE;

useIEEE.std_logic_1164.all;

useIEEE.std_logic_unsigned.all;

entitymusicis

port(music_begin:

instd_logic;

clk_4:

instd_logic;

clk:

instd_logic;

music_out:

outstd_logic);

endmusic;

architecturemusic_bodyofmusicis

constantm1:

integer:

=637;--955;

constantm2:

integer:

=587;--851;

constantm3:

integer:

=505;--758;

constantm4:

integer:

=468;--716;

constantm5:

integer:

=425;--639;

constantm6:

integer:

=379;--569;

constantm7:

integer:

=330;--506;

constantm0:

integer:

=0;

signalcounter:

integerrange0to67;

signalcount:

integerrange0to1000;

signalsub:

integerrange0to1000;

signalcarrier:

std_logic;

signalpat,pat1,pat2:

std_logic;

begin

process(clk)

begin

if(clk'eventandclk='1')then

if(carrier='1')then

sub<=count;

else

sub<=sub-1;

endif;

endif;

endprocess;

process(sub)

begin

if(sub=0)then

pat<='1';

else

pat<='0';

endif;

carrier<=pat;

endprocess;

process(clk)

begin

if(clk'eventandclk='1')then

pat1<=pat;

endif;

endprocess;

process(pat1)

begin

if(pat1'eventandpat1='1')then

pat2<=notpat2;

endif;

music_out<=pat2;

endprocess;

process(clk_4)

begin

if(clk_4'eventandclk_4='1')then

if(music_begin='1')then

counter<=counter+1;

else

counter<=0;

endif;

endif;

endprocess;

process(counter)

begin

casecounteris

when0=>count<=m0;when1=>count<=m1;

when2=>count<=m1;when3=>count<=m2;

when4=>count<=m2;when5=>count<=m3;

when6=>count<=m3;when7=>count<=m1;

when8=>count<=m1;when9=>count<=m1;

when10=>count<=m2;when11=>count<=m2;

when12=>count<=m3;when13=>count<=m3;

when14=>count<=m1;when15=>count<=m1;

when16=>count<=m3;when17=>count<=m3;

when18=>count<=m4;when19=>count<=m4;

when20=>count<=m5;when21=>count<=m5;

when22=>count<=m5;when23=>count<=m5;

when24=>count<=m3;when25=>count<=m3;

when26=>count<=m4;when27=>count<=m5;

when28=>count<=m5;when29=>count<=m5;

when30=>count<=m5;when31=>count<=m5;

when32=>count<=m5;when33=>count<=m6;

when34=>count<=m5;when35=>count<=m4;

when36=>count<=m3;when37=>count<=m3;

when38=>count<=m1;when39=>count<=m1;

when40=>count<=m5;when41=>count<=m6;

when42=>count<=m5;when43=>count<=m4;

when44=>count<=m3;when45=>count<=m3;

when46=>count<=m1;when47=>count<=m1;

when48=>count<=m0;when49=>count<=m1;

when50=>count<=m1;when51=>count<=m5;

when52=>count<=m5;when53=>count<=m1;

when54=>count<=m1;when55=>count<=m1;

when56=>count<=m1;when57=>count<=m0;

when58=>count<=m1;when59=>count<=m1;

when60=>count<=m5;when61=>count<=m5;

when62=>count<=m1;when63=>count<=m1;

when64=>count<=m1;when65=>count<=m5;

when66=>count<=m0;when67=>count<=m0;

endcase;

endprocess;

endmusic_body;

 

3.2系统整体电路图(或RTL级电路图)

 

 

四、系统仿真(SimulationWaveform)

功能仿真波形图

 

时序仿真波形图

五、FPGA实现(FPGAImplementation)

将程序下载到EDA2000实验箱

然后按照设定的管脚在EDA

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 军事

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1