eda课程设计基于vhd语言的乒乓球游戏机设计大学论文.doc
-
资源ID:91627796
资源大小:3.75MB
全文页数:14页
- 资源格式: DOC
下载积分:8金币
快捷下载
会员登录下载
微信登录下载
三方登录下载:
微信扫一扫登录
友情提示
2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
|
eda课程设计基于vhd语言的乒乓球游戏机设计大学论文.doc
目 录1 项目名称、内容与要求 04页1.1 设计内容04页1.2 具体要求04页2 系统整体架构(Architecture Description) 04页2.1 设计思路04页2.2 系统原理(包含:框图等阐述与设计说明等内容)04页3 系统设计 (含HDL或原理图输入设计)05页3.1 HDL 代码05页3.2 系统整体电路图(或RTL级电路图)12页4 系统仿真(Simulation Waveform)13页5FPGA实现(FPGA Implementation) 14页6 总结(Closing)16页参考书目(Reference):16页一、项目名称、内容与要求二、系统整体架构(Architecture Description)2.1设计思路 根据系统设计的要求,乒乓球比赛游戏机的电路原理框图如下:三、系统设计 (含HDL或原理图输入设计)3.1 VHDL 代码比赛模块library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all; -引用必要的库函数和包集合entity compete is -实体名为pingpong port(reset:in std_logic;clk_1:in std_logic;startbutton:in std_logic; -开始游戏输入端口serve:in std_logic_vector(1 downto 0); -发球输入端口hit1,hit2,hit11,hit22:in std_logic; -甲和乙的击球输入端口light:out std_logic_vector(1 to 8); sound:out std_logic;-控制8个发光二极管的输出端口music_begin:out std_logic;-控制音乐开始的输出端口counta,countb,countc,countd,counte,countf:out std_logic_vector(3 downto 0); -2个用于控制4个7段译码器的输出端口end compete;architecture one of compete istype pingpong is (waitserve,light1on,ballmoveto2,allow2hit,light8on,ballmoveto1,allow1hit);-设置7个状态,为枚举数据类型,记为pingpong signal state:pingpong;signal i:integer range 0 to 8;signal count1,count2,count3,count4,count5,count6:std_logic_vector(3 downto 0):="0000" -内部计数器,是4位二进制变量beginprocess(clk_1) begin if(clk_1'event and clk_1='1') then if count1=1 and count5=1 or count2=1 and count6=1 then music_begin<='1'end if; if(reset='1')then music_begin<='0' end if; end if; end process; process(clk_1) -状态机进程 -clk_1作为敏感信号触发进程begin -进程开始if reset='1' then -异步置位i<=0;count1<=0;count2<=0;count5<=0;count6<=0;elsif clk_1'event and clk_1='1' then -当处于时钟inclock上升沿时 if count1=10 thencount1<=0;count5<=1; elsif count1=1 and count5=1 then i<=0;count1<=0;count5<=0;count3<=count3+1;count2<=0;count6<=0;elsif count2=10 then count2<=0;count6<=1; elsif count2=1 and count6=1 theni<=0;count1<=0;count2<=0;count4<=count4+1;count5<=0;count6<=0; elsif count3=4 or count4=4 then i<=9;music_begin<=1;startbutton=0;elsif startbutton='0' theni<=0;count1<=0;count2<=0;count3<=0;count4<=0;count5<=0;count6<=0;else -以下case语句是程序中最关键的状态机部分case state iswhen waitserve=> -进程处于等待发球状态case serve iswhen "01"=> i<=1;state<=light1on;when "10"=> i<=8;state<=light8on;when "11"=>i<=0;when “00”=> i<=0;sound<=”0”;end case;when light1on=> -进程处于第一盏灯亮状态i<=2;if hit2='1' or hit22=1 theni<=0;count1<=count1+1;sound<=”1”state<=waitserve; elsestate<=ballmoveto2;end if;when light8on=> -进程处于第八盏灯亮状态i<=7;if hit1='1' or hit11=”1” theni<=0;count2<=count2+1;sound<=”1”;state<=waitserve;elsestate<=ballmoveto1;end if; when ballmoveto1=> -进程处于球向甲移动状态if hit1='1' theni<=0;count2<=count2+1;sound<=”1”;state<=waitserve;elsif i=2 then i<=1;state<=allow1hit;else i<=i-1;end if;when ballmoveto2=> -进程处于球向乙移动状态if hit2='1'theni<=0;count1<=count1+1; sound<=”1”;state<=waitserve;elsif i=7 then i<=8;state<=allow2hit;else i<=i+1;end if;when allow1hit=> -进程处于允许甲击球状态if hit1='1' then i<=2;state<=ballmoveto2;else count2<=count2+1;i<=0;sound<=”1”;state<=waitserve;end if; if hit11='1' then i<=2;state<=ballmoveto2;else count2<=count2+1;i<=0;sound<=”1”;state<=waitserve;end if;when allow2hit=> -进程处于允许乙击球状态if hit2='1'then i<=7;state<=ballmoveto1;else count1<=count1+1;i<=0;sound<=”1”;state<=waitserve;end if; if hit22='1'then i<=7;state<=ballmoveto1;else count1<=count1+1;i<=0;sound<=”1”;state<=waitserve;end if;end case;end if;end if;end process;counta<=count1;countb<=count2;countc<=count3;countd<=count4;counte<=count5;countf<=count6; process(clk_1) if (clk_1'event and clk_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"End process; -其他情况所有发光二极管都暗end one;分频模块library IEEE; use IEEE.std_logic_1164.all;use ieee.std_logic_arith.all;use IEEE.std_logic_unsigned.all;entity division16 isport( cp:in std_logic; clk_4:out std_logic );end division16;architecture division_body of division16 issignal count:std_logic_vector(3 downto 0);beginprocess(cp)beginif(cp'event and cp='1')then if(count="1111")thencount<=(others=>'0');elsecount<=count+1;end if;end if;end process;process(cp)beginif(cp'event and cp='1')then if(count="1111")thenclk_4<='1'elseclk_4<='0'end if;end if;end process;end division_body;译码器部分library ieee; use ieee.std_logic_1164.all; entity disp is port(d:in std_logic_vector(3 downto 0); q:out std_logic_vector(6 downto 0); end disp; architecture disp_arc of disp is begin process(d) begin case d is 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" when others=>q<="0000000" end case; end process; end disp_arc;数码管选择LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY mux2 IS PORT(a,b: IN STD_LOGIC_VECTOR(6 downto 0);sel: IN STD_LOGIC;c:OUT STD_LOGIC_VECTOR(6 downto 0);END mux2;ARCHITECTURE example OF mux2 IS BEGIN PROCESS(sel) BEGINIF(SEL='1')THEN c<=a;ELSE c<=b;END IF;END PROCESS;END example;音乐模块(两只老虎)library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all;entity music is port ( music_begin:in std_logic; clk_4:in std_logic; clk:in std_logic; music_out:out std_logic ); end music;architecture music_body of music is constant m1:integer:=637;-955; constant m2:integer:=587;-851; constant m3:integer:=505;-758; constant m4:integer:=468;-716; constant m5:integer:=425;-639; constant m6:integer:=379;-569; constant m7:integer:=330;-506; constant m0:integer:=0; signal counter:integer range 0 to 67; signal count:integer range 0 to 1000; signal sub:integer range 0 to 1000; signal carrier:std_logic; signal pat,pat1,pat2:std_logic;beginprocess(clk) begin if(clk'event and clk='1')then if(carrier='1') then sub<=count; else sub<=sub-1; end if; end if; end process;process(sub) begin if(sub=0) then pat<='1' else pat<='0' end if; carrier<=pat; end process; process(clk) begin if(clk'event and clk='1')then pat1<=pat; end if; end process;process(pat1) begin if(pat1'event and pat1='1') then pat2<= not pat2; end if; music_out<=pat2; end process; process(clk_4) begin if(clk_4'event and clk_4='1') then if(music_begin='1') then counter<=counter+1; else counter<=0; end if; end if; end process; process(counter) begin case counter is when 0=>count<=m0; when 1=>count<=m1;when 2=>count<=m1; when 3=>count<=m2;when 4=>count<=m2; when 5=>count<=m3;when 6=>count<=m3; when 7=>count<=m1;when 8=>count<=m1; when 9=>count<=m1;when 10=>count<=m2; when 11=>count<=m2;when 12=>count<=m3; when 13=>count<=m3;when 14=>count<=m1; when 15=>count<=m1;when 16=>count<=m3; when 17=>count<=m3;when 18=>count<=m4; when 19=>count<=m4;when 20=>count<=m5; when 21=>count<=m5;when 22=>count<=m5; when 23=>count<=m5;when 24=>count<=m3; when 25=>count<=m3;when 26=>count<=m4; when 27=>count<=m5;when 28=>count<=m5; when 29=>count<=m5;when 30=>count<=m5; when 31=>count<=m5;when 32=>count<=m5; when 33=>count<=m6;when 34=>count<=m5;when 35=>count<=m4;when 36=>count<=m3;when 37=>count<=m3;when 38=>count<=m1;when 39=>count<=m1;when 40=>count<=m5;when 41=>count<=m6;when 42=>count<=m5;when 43=>count<=m4;when 44=>count<=m3;when 45=>count<=m3;when 46=>count<=m1;when 47=>count<=m1;when 48=>count<=m0; when 49=>count<=m1;when 50=>count<=m1;when 51=>count<=m5;when 52=>count<=m5;when 53=>count<=m1;when 54=>count<=m1;when 55=>count<=m1;when 56=>count<=m1;when 57=>count<=m0;when 58=>count<=m1;when 59=>count<=m1;when 60=>count<=m5;when 61=>count<=m5;when 62=>count<=m1;when 63=>count<=m1;when 64=>count<=m1;when 65=>count<=m5;when 66=>count<=m0;when 67=>count<=m0; end case; end process; end music_body;3.2 系统整体电路图(或RTL级电路图)四、系统仿真(Simulation Waveform)功能仿真波形图时序仿真波形图 五、FPGA实现(FPGA Implementation)将程序下载到EDA2000实验箱然后按照设定的管脚在EDA2000实验箱上连接好实物图输入脉冲,验证其功能六、总结(Closing)经过一学期的学习,在陈强老师的教导下,我对在系统编程技术这门课有了很深刻的理解,并能结合所学的知识设计了这次的乒乓球游戏机。由于实验箱上脉冲端有限,于是我又想到了要设计一个分频器,我开始设计的是16分频和64分频,因为我需要一个4Hz和1Hz的脉冲信号,但是,这样做对整个电路而言没有任何效果,无论怎样都仿真不出波形,但是代码没错,单独仿真分频器也有波形输出。当我准备放弃时,我又抱着侥幸心理只设计一个16分频的分频器,我把分频器接入电路,然后仿真,结果仿真波形出来了。然后下载到实验箱验证时,结果甲乙两位选手的得分不能再同一排数码管上显示,后经过我冷静的分析,我想到了曾经做过的60进制计数器,于是我便加了个数码管选择器,这样甲乙二人的分数可以再同一排数码上显示了。经过这次实训,我收获颇丰,学到了很多知识,特别是提高了综合分析应用的能力。我学会了如何去完成一个任务,懂得了享受过程。当遇到问题,冷静,想办法一点一点的排除障碍,到最后获取成功,一种自信心由然而生。实训是对每个人综合能力的检验。要想做好任何事,除了自己平时要有一定的功底外,我们还需要一定的实践动手能力,操作能力。此次实训,我深深体会到了积累知识的重要性。在短暂的实训过程中,让我深深的感觉到自己在实际运用中的知识的匮乏这时才真正领悟到“学无止境”的含义。