EDA课程设计乒乓球游戏机vhd语言l.docx
- 文档编号:7283160
- 上传时间:2023-01-22
- 格式:DOCX
- 页数:16
- 大小:3.62MB
EDA课程设计乒乓球游戏机vhd语言l.docx
《EDA课程设计乒乓球游戏机vhd语言l.docx》由会员分享,可在线阅读,更多相关《EDA课程设计乒乓球游戏机vhd语言l.docx(16页珍藏版)》请在冰豆网上搜索。
EDA课程设计乒乓球游戏机vhd语言l
目录
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页
一、项目名称、内容与要求
二、系统整体架构(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,hit11,hit22:
instd_logic;--甲和乙的击球输入端口
light:
outstd_logic_vector(1to8);
sound:
outstd_logic;--控制8个发光二极管的输出端口
music_begin:
outstd_logic;--控制音乐开始的输出端口
counta,countb,countc,countd,counte,countf:
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,count5,count6:
std_logic_vector(3downto0):
="0000";
---内部计数器,是4位二进制变量
begin
process(clk_1)
begin
if(clk_1'eventandclk_1='1')then
ifcount1=1andcount5=1orcount2=1andcount6=1then
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<=0;count2<=0;count5<=0;count6<=0;
elsifclk_1'eventandclk_1='1'then--当处于时钟inclock上升沿时
ifcount1=10then
count1<=0;count5<=1;
elsifcount1=1andcount5=1then
i<=0;count1<=0;count5<=0;count3<=count3+1;count2<=0;count6<=0;
elsifcount2=10then
count2<=0;count6<=1;
elsifcount2=1andcount6=1then
i<=0;count1<=0;count2<=0;count4<=count4+1;count5<=0;count6<=0;
elsifcount3=4orcount4=4then
i<=9;music_begin<=1;startbutton=’0’;
elsifstartbutton='0'then
i<=0;count1<=0;count2<=0;count3<=0;count4<=0;count5<=0;count6<=0;
else--以下case语句是程序中最关键的状态机部分
casestateis
whenwaitserve=>
--进程处于等待发球状态
caseserveis
when"01"=>i<=1;state<=light1on;
when"10"=>i<=8;state<=light8on;
when"11"=>i<=0;
when“00”=>i<=0;sound<=”0”;
endcase;
whenlight1on=>--进程处于第一盏灯亮状态
i<=2;
ifhit2='1'orhit22=’1’then
i<=0;
count1<=count1+1;sound<=”1”state<=waitserve;
else
state<=ballmoveto2;
endif;
whenlight8on=>--进程处于第八盏灯亮状态
i<=7;
ifhit1='1'orhit11=”1”then
i<=0;
count2<=count2+1;sound<=”1”;state<=waitserve;
else
state<=ballmoveto1;
endif;
whenballmoveto1=>--进程处于球向甲移动状态
ifhit1='1'then
i<=0;
count2<=count2+1;sound<=”1”;state<=waitserve;
elsifi=2theni<=1;
state<=allow1hit;
elsei<=i-1;
endif;
whenballmoveto2=>--进程处于球向乙移动状态
ifhit2='1'then
i<=0;
count1<=count1+1;sound<=”1”;state<=waitserve;
elsifi=7theni<=8;
state<=allow2hit;
elsei<=i+1;
endif;
whenallow1hit=>--进程处于允许甲击球状态
ifhit1='1'theni<=2;
state<=ballmoveto2;
elsecount2<=count2+1;i<=0;sound<=”1”;
state<=waitserve;
endif;
ifhit11='1'theni<=2;
state<=ballmoveto2;
elsecount2<=count2+1;i<=0;sound<=”1”;
state<=waitserve;
endif;
whenallow2hit=>--进程处于允许乙击球状态
ifhit2='1'theni<=7;state<=ballmoveto1;
elsecount1<=count1+1;i<=0;sound<=”1”;
state<=waitserve;
endif;
ifhit22='1'theni<=7;state<=ballmoveto1;
elsecount1<=count1+1;i<=0;sound<=”1”;
state<=waitserve;
endif;
endcase;
endif;
endif;
endprocess;
counta<=count1;countb<=count2;countc<=count3;countd<=count4;counte<=count5;countf<=count6;
process(clk_1)
if(clk_1'eventandclk_1='1')then--进程处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";
Endprocess;--其他情况所有发光二极管都暗
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实验箱
然后按照设定的管脚在EDA2000实验箱上连接好实物图
输入脉冲,验证其功能
六、总结(Closing)
经过一学期的学习,在陈强老师的教导下,我对在系统编程技术这门课有了很深刻的理解,并能结合所学的知识设计了这次的乒乓球游戏机。
由于实验箱上脉冲端有限,于是我又想到了要设计一个分频器,我开始设计的是16分频和64分频,因为我需要一个4Hz和1Hz的脉冲信号,但是,这样做对整个电路而言没有任何效果,无论怎样都仿真不出波形,但是代码没错,单独仿真分频器也有波形输出。
当我准备放弃时,我又抱着侥幸心理只设计一个16分频的分频器,我把分频器接入电路,然后仿真,结果仿真波形出来了。
然后下载到实验箱验证时,结果甲乙两位选手的得分不能再同一排数码管上显示,后经过我冷静的分析,我想到了曾经做过的60进制计数器,于是我便加了个数码管选择器,这样甲乙二人的分数可以再同一排数码上显示了。
经过这次实训,我收获颇丰,学到了很多知识,特别是提高了综合分析应用的能力。
我学会了如何去完成一个任务,懂得了享受过程。
当遇到问题,冷静,想办法一点一点的排除障碍,到最后获取成功,一种自信心由然而生。
实训是对每个人综合能力的检验。
要想做好任何事,除了自己平时要有一定的功底外,我们还需要一定的实践动手能力,操作能力。
此次实训,我深深体会到了积累知识的重要性。
在短暂的实训过程中,让我深深的感觉到自己在实际运用中的知识的匮乏这时才真正领悟到“学无止境”的含义。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- EDA 课程设计 乒乓球 游戏机 vhd 语言