VHDL课程设计报告乒乓球游戏机.docx
- 文档编号:9480030
- 上传时间:2023-05-19
- 格式:DOCX
- 页数:18
- 大小:90.48KB
VHDL课程设计报告乒乓球游戏机.docx
《VHDL课程设计报告乒乓球游戏机.docx》由会员分享,可在线阅读,更多相关《VHDL课程设计报告乒乓球游戏机.docx(18页珍藏版)》请在冰点文库上搜索。
VHDL课程设计报告乒乓球游戏机
VHDL课程设计报告
一.乒乓球游戏机
两人乒乓球游戏机是用8-16个发光二极管代表乒乓球台,中间两个发光二极管兼做乒乓球网,用点亮的发光二极管按一定的方向移动来表示球的运动。
在游戏机的两侧各设置两个开关,一个是发球开关(s1a,s1b),另一个是接球开关(s2a,s2b)。
甲乙两人按乒乓球比赛的规则来操作开关。
当甲方按动发球开关s1a时,靠近甲方的第一盏灯亮,然后发光二极管由甲向乙依次点亮,代表乒乓球在移动。
当球过网后,按设计者规定的球位乙方就可以击球。
若乙方提前击球或没击着球,则判乙方失分,甲方记分牌自动加分。
然后重新发球,比赛继续进行。
比赛一直进行到一方记分到21分,该局结束,记分牌清零,可以开始新的一局比赛。
任务和要求
二.电路的工作原理
设计一个乒乓球游戏机,该机模拟乒乓球比赛的基本过程和规则,并能自动裁判和记分。
要求如下:
1)使用乒乓球游戏机的甲乙双方各在不同的位置发球或击球。
2)乒乓球的位置和移动方向由灯亮及依次点燃的方向决定,球的移动速度为0.1-0.5s移动一位。
使用者根据球的位置发出相应的动作,提前击球或出界均判失分。
设计者可按过网击球来设计。
3)比赛用21分为一局来进行,甲乙双方都应设置各自的记分牌,任何一方先记满21分,该方就算胜了此局。
当记分牌清零后,又可以开始新的一局比赛。
三.VHDL设计思路与程序
在乒乓球球游戏机的实现过程中用到四个模块,分别为CORNA,CH41A,SEL,DISP,下面逐一对模块的功能进行描述。
CORNA:
该模块为游戏机中最重要的模块。
共有9个端口,分别为CLR,AF,AJ,BF,BJ,CLK,SHIFT,AH,AL,BH,BL。
模块负责对正常击球、过网击球、未击球予以判定,并进行记分、球的位置输出。
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitycornais
port(clr,af,aj,bf,bj,clk:
instd_logic;
shift:
outstd_logic_vector(7downto0);
ah,al,bh,bl:
outstd_logic_vector(3downto0)
);
end;
architecturecorna_arcofcornais
signalamark,bmark:
integer;
begin
process(clr,clk)
variablea,b:
std_logic;
variableshe:
std_logic_vector(7downto0);
begin
ifclr='0'then
a:
='0';
b:
='0';
she:
="00000000";
amark<=0;
bmark<=0;
elsifclk'eventandclk='1'then
ifa='0'andb='0'andaf='0'then
a:
='1';
she:
="10000000";
elsifa='0'andb='0'andbf='0'then
b:
='1';
she:
="00000001";
elsifa='1'andb='0'then
ifshe>8then
ifbj='0'then
amark<=amark+1;
a:
='0';
b:
='0';
she:
="00000000";
else
she:
='0'&she(7downto1);
endif;
elsifshe=0then
amark<=amark+1;
a:
='0';
b:
='0';
else
ifbj='0'then
a:
='0';
b:
='1';
else
she:
='0'&she(7downto1);
endif;
endif;
elsifa='0'andb='1'then
ifshe<16andshe/=0then
ifaj='0'then
bmark<=bmark+1;
a:
='0';
b:
='0';
she:
="00000000";
else
she:
=she(6downto0)&'0';
endif;
elsifshe=0then
bmark<=bmark+1;
a:
='0';
b:
='0';
else
ifaj='0'then
a:
='1';
b:
='0';
else
she:
=she(6downto0)&'0';
endif;
endif;
endif;
endif;
shift<=she;
endprocess;
process(clk,clr,amark,bmark)
variableaha,ala,bha,bla:
std_logic_vector(3downto0);
variabletmp1,tmp2:
integer;
begin
ifclr='0'then
aha:
="0000";
ala:
="0000";
bha:
="0000";
bla:
="0000";
tmp1:
=0;
tmp2:
=0;
elsifclk'eventandclk='1'then
ifamark>tmp1then
ifala="1001"then
ala:
="0000";
aha:
=aha+1;
tmp1:
=tmp1+1;
else
ala:
=ala+1;
tmp1:
=tmp1+1;
endif;
endif;
ifbmark>tmp2then
ifbla="1001"then
bla:
="0000";
bha:
=bha+1;
tmp2:
=tmp2+1;
else
bla:
=bla+1;
tmp2:
=tmp2+1;
endif;
endif;
endif;
al<=ala;
bl<=bla;
ah<=aha;
bh<=bha;
endprocess;
endcorna_arc;
SEL:
该模块实现为CH41A提供片选信号,通过输入脉冲信号循环输出000、001、100、101信号。
共有两个端口,分别是CLK,SELL。
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityselis
port(clk:
instd_logic;
sell:
outstd_logic_vector(2downto0));
end;
architecturesel_arcofselis
begin
process(clk)
variabletmp:
std_logic_vector(2downto0):
="000";
begin
ifclk'eventandclk='1'then
iftmp="000"then
tmp:
="001";
elsiftmp="001"then
tmp:
="100";
elsiftmp="100"then
tmp:
="101";
elsiftmp="101"then
tmp:
="000";
endif;
endif;
sell<=tmp;
endprocess;
end;
CH41A:
该模块实现信号的选择输出,根据SEL信号选通对应的信号。
共有6个端口,分别为SEL,D0,D1,D2,D3,Q。
libraryieee;
useieee.std_logic_1164.all;
entitych41ais
port(sel:
instd_logic_vector(2downto0);
d0,d1,d2,d3:
instd_logic_vector(3downto0);
q:
outstd_logic_vector(3downto0));
end;
architecturech41_arcofch41ais
begin
process(sel)
begin
caseselis
when"100"=>q<=d0;
when"101"=>q<=d1;
when"000"=>q<=d2;
whenothers=>q<=d3;
endcase;
endprocess;
end;
DISP:
该模块实现7段数码管的译码功能。
共两个端口,分别为D,Q。
libraryieee;
useieee.std_logic_1164.all;
entitydispis
port(d:
instd_logic_vector(3downto0);
q:
outstd_logic_vector(6downto0));
end;
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";
whenothers=>q<="1101111";
endcase;
endprocess;
enddisp_arc;
以上为乒乓球游戏机所用到的各个模块的VHDL语句。
若想实现乒乓球游戏机的功能,只有孤立的模块是不行的,还需要将各个芯片加以关联。
在此,以project为名的blockdiagram实现。
Project的VHDL描述为
libraryieee;
useieee.std_logic_1164.all;
librarywork;
entityprojectis
port(
AF:
instd_logic;
AJ:
instd_logic;
BF:
instd_logic;
BJ:
instd_logic;
CLK:
instd_logic;
CLR:
instd_logic;
S1:
outstd_logic_vector(6downto0);
SCLK:
instd_logic;
SHIFT:
outstd_logic_vector(7downto0)
);
endproject;
architectureprojectofprojectis
signalAH:
std_logic_vector(3downto0);
signalAL:
std_logic_vector(3downto0);
signalBH:
std_logic_vector(3downto0);
signalBL:
std_logic_vector(3downto0);
signalQ:
std_logic_vector(3downto0);
signalSELL:
std_logic_vector(2downto0);
componentch41a
port(
SEL:
instd_logic_vector(2downto0);
D0:
instd_logic_vector(3downto0);
D1:
instd_logic_vector(3downto0);
D2:
instd_logic_vector(3downto0);
D3:
instd_logic_vector(3downto0);
Q:
outstd_logic_vector(3downto0)
);
endcomponent;
componentcorna
port(
CLR:
instd_logic;
AF:
instd_logic;
AJ:
instd_logic;
BF:
instd_logic;
BJ:
instd_logic;
CLK:
instd_logic;
SHIFT:
outstd_logic_vector(7downto0);
AH:
outstd_logic_vector(3downto0);
AL:
outstd_logic_vector(3downto0);
BH:
outstd_logic_vector(3downto0);
BL:
outstd_logic_vector(3downto0)
);
endcomponent;
componentsel
port(
CLK:
instd_logic;
SELL:
outstd_logic_vector(2downto0)
);
endcomponent;
componentdisp
port(
D:
instd_logic_vector(3downto0);
Q:
outstd_logic_vector(6downto0)
);
endcomponent;
--StartConfigurationSpecification
forU0:
ch41auseentityWORK.ch41a;
forU1:
cornauseentityWORK.corna;
forU2:
seluseentityWORK.sel;
forU3:
dispuseentityWORK.disp;
--EndConfigurationSpecification
begin--architecture
U0:
ch41a
portmap(
SEL=>SELL(2downto0),
D0=>AL(3downto0),
D1=>AH(3downto0),
D2=>BL(3downto0),
D3=>BH(3downto0),
Q=>Q(3downto0));
U1:
corna
portmap(
CLR=>CLR,
AF=>AF,
AJ=>AJ,
BF=>BF,
BJ=>BJ,
CLK=>CLK,
SHIFT=>SHIFT(7downto0),
AH=>AH(3downto0),
AL=>AL(3downto0),
BH=>BH(3downto0),
BL=>BL(3downto0));
U2:
sel
portmap(
CLK=>SCLK,
SELL=>SELL(2downto0));
U3:
disp
portmap(
D=>Q(3downto0),
Q=>S1(6downto0));
endproject;
四.仿真验证程序与仿真结果
在乒乓球游戏机的设计过程中,corna模块是整个程序中的灵魂部分,这一点从语句所占的篇幅就可以看的出,所以为了更好地理解该程序,在老师的指点下,本人先对corna模块进行了仿真,仿真程序如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityt_cornais
end;
architecturet_cornaoft_cornais
componentcorna
port(clr,af,aj,bf,bj,clk:
instd_logic;
shift:
outstd_logic_vector(7downto0);
ah,al,bh,bl:
outstd_logic_vector(3downto0)
);
endcomponent;
signalclr,af,aj,bf,bj:
std_logic;
signalclk:
std_logic:
='0';
signalshift:
std_logic_vector(7downto0);
signalah,al,bh,bl:
std_logic_vector(3downto0);
begin
u0:
cornaportmap(clr,af,aj,bf,bj,clk,shift,ah,al,bh,bl);
clk<=notclkafter5ns;
clr<='0','1'after10ns;
af<='0','1'after20ns,'0'after250ns,'1'after260ns;
aj<='1';
bf<='1','0'after150ns,'1'after160ns;
bj<='1','0'after70ns,'1'after80ns,'0'after280ns,'1'after290ns;
end;
af,aj,bf,bj分别表示a发球,a接球,b发球,b接球。
Shift表示球的位置,ah,al,bh,bl表示a、b的分数情况,其中h表示十位,l表示个位。
在仿真中,依次测试了三种情况,分别是a发球后b正常击球,而后a没有再击球,对应图中0-150ns;b发球而a没有击球,对应图中150ns-240ns;a发球而后比过网击球,对应图中250ns-290ns。
上图中,显示了应有的输出波形,即a未正常击球时(150ns、250ns)bl加1。
且在b过网击球时(280ns)al加1。
在对corna模块进行了仿真之后,本人又进一步对project进行了仿真
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityt_projectis
end;
architecturet_projectoft_projectis
componentproject
port(
AF:
instd_logic;
AJ:
instd_logic;
BF:
instd_logic;
BJ:
instd_logic;
CLK:
instd_logic;
CLR:
instd_logic;
S1:
outstd_logic_vector(6downto0);
SHIFT:
outstd_logic_vector(7downto0);
SCLK:
instd_logic
);
endcomponent;
signalAF:
std_logic;
signalAJ:
std_logic;
signalBF:
std_logic;
signalBJ:
std_logic;
signalCLK:
std_logic:
='0';
signalCLR:
std_logic;
signalS1:
std_logic_vector(6downto0);
signalSHIFT:
std_logic_vector(7downto0);
signalSCLK:
std_logic:
='0';
begin
u0:
projectportmap(AF,AJ,BF,BJ,CLK,CLR,S1,SHIFT,SCLK);
clk<=notclkafter5ns;
sclk<=notsclkafter19ns;
clr<='0','1'after10ns;
af<='0','1'after20ns;--,'0'after250ns,'1'after260ns;
aj<='1';
bf<='1';--,'0'after150ns,'1'after160ns;
bj<='1';--,'0'after70ns,'1'after80ns,'0'after280ns,'1'after290ns;
end;
波形图如下:
五.逻辑综合
在最后一节课上对程序进行了综合,综合后的电路图为
六.收获体会
这次的课程设计是我在大学阶段第一次完整地通过计算机进行VLSI有关的电路设计,可以说不管是所用的操作系统,还是设计、综合的软件,都是我第一接触。
可以说,课程设计是一项富有挑战的工作,需要足够的耐心,以及一种认真、负责的态度。
由于我的程序代码很长,在课程设计的初期,理解程序成为我最大的障碍,我一度试图跳过这个步骤直接编写和连线,但是我发现如果不能从本质上理解程序的内容,接下来的工作更难进行,而且就算最终完成了课程设计,也不会得到什么收获。
于是乎我毅然决定继续读程序,最终我发现,理解程序并没有想象中的那么困难,因为程序中有很多功能都是处于平行地位的,只要理解了其中一个,其它程序就可以迎刃而解。
这点也足以让我对课程设计产生更大的兴趣。
其次,课程设计也增强了我的逻辑能力,在程序的编写中,会遇到一些程序调用另一个程序的现象,如果不清楚程序间彼此的逻辑关系,同样会带来很多困难。
最后,这次课程设计使我对Linux操作系统产生了新的兴趣,在课程设计期间,为了能尽快适应应用环境,我翻阅了一些linux的书籍并简单地学习了一些shell语句,并、由此对linux产生了浓厚的兴趣,并且有可能会在以后的时间继续深入地学习。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VHDL 课程设计 报告 乒乓球 游戏机