当前位置:文档之家› 乒乓球游戏机--EDA课程设计--完整版本

乒乓球游戏机--EDA课程设计--完整版本

目录1 设计目的 (1)2 设计要求和任务 (1)2.1设计任务 (1)2.2设计要求 (1)3 总体设计思路及原理描述 (1)4 分层次方案设计及代码描述 (2)4.1控制模块的设计 (2)4.1.1 cornal模块分析 (2)4.1.2 cornal模块VHDL程序描述 (3)4.2送数据模块的设计 (7)4.2.1 ch41a模块分析 (7)4.2.2 ch41a模块VHDL程序描述 (7)4.3产生数码管片选信号模块的设计 (8)4.3.1 sel模块分析 (8)4.3.2 sel模块VHDL程序描述 (9)4.4 七段译码器模块的设计 (10)4.4.1 disp模块分析 (10)4.4.2 disp模块VHDL程序描述 (10)4.5 顶层原理图设计 (11)5 各模块的时序仿真图 (12)6 总结 (14)7 参考文献 (14)乒乓游戏机1 设计目的掌握熟悉的使用Quartus II 9.1软件的原理图绘制,程序的编写,编译以及仿真。

体会使用EDA综合过程中电路设计方法和设计思路的不同。

掌握使用EDA工具设计乒乓游戏机的的设计思路和设计方法。

2 设计要求和任务2.1设计任务设计一个乒乓球游戏机,该机模拟乒乓球比赛的基本过程和规则,并能自动裁判和几分。

2.2设计要求(1)甲乙双方各在不同的位置发球或击球。

(2)乒乓球的位置和移动方向由灯亮及依次点亮的方向决定,球移动的速度为0.1-0.5秒移动一位。

(3)11分为一局,甲乙双方都应设置各自的几分牌,任何一方先记满11分,该方胜出。

当记分牌清零后,重新开始。

3 总体设计思路及原理描述由乒乓游戏机功能,用原理图作为顶层模块,再将底层划分成四个小模块来实现:(1)cornal模块:整个程序的核心,它实现了整个系统的全部逻辑功能;(2)ch41a模块:在数码的片选信号时,送出相应的数据;(3)sel模块:产生数码管的片选信号;(4)disp模块:7段译码器。

图3.1 结构层次图4 分层次方案设计及代码描述4.1控制模块的设计4.1.1 cornal模块分析a发球一、在范围内1、b没有接到球,a加1分,将灯光清零000 00 0002、b接到了球,则灯光为0 &【7位】二、在b方出界了1、如果b没有接到球,则a加分2、如果b接到了球,则灯光为0 &【7位】b发球一、在范围内1、a没有接到球,b加1分,并将灯光清零000 00 0002、a接到了球,则灯光计分为【7位】& 0二、在a方出界了1、a没有接到球,则b加分2、a接到了球,则灯光计分为【7位】& 0af,aj,bf,bj分别为a方发球键和接球键,b方发球键和接球键,shift表示球所在的位置。

图4.1 conal模块原理图4.1.2 cornal模块VHDL程序描述Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity cornal isPort(clr,af,aj,bf,bj,clk:in std_logic;Shift:out std_logic_vector(7 downto 0);Ah,al,bh,bl:out std_logic_vector(3 downto 0);Awin,bwin:out std_logic);End cornal;Architecture bahave of cornal isSignal amark,bmark:integer;BeginProcess(clr,clk)Variable a,b:std_logic;Variable she:std_logic_vector(7 downto 0);BeginIf clr=’0’ t hena:=’0’;b:=’0’;she:=”00000000”amark<=0;bmark<=0;elsif clk’event and clk=’1’ thenif a=’0’ and b=’0’ and af=’0’ then --a方发球 a:=’1’;she;=”10000000”;elsif a=’0’ and b=’0’ then bf=’0’ then --b方发球 b:=’1’;she:=”00000001”;elsif a=’1’ and b=’0’ then --a方发球后if she>8 thenif bj=’0’ then --b方过网击球amark<=amark+1; --a方加一分a:=’0’;b:=’0’;she:=”00000000”;elseshe:=’0’&she(7 downto 1); --b方没有击球end if;elsif she=0 then --球从b方出界amark<=amark+1; --a方加一分a:=’0’;b:=’0’;elseif bj=’0’ then --b方正常击球a:=’0’;b:=’1’;elseshe:=’0’&she(7 downto 1); --b方没有击球end if;end if;elsif a=’0’ and b=’1’then --b方发球if she<16 and she/=0 thenif aj=’0’ thenbmark<=bmark+1;a:=’0’;b:=’0’;she:=”00000000”;elseshe:=she(6 downto 0)&’0’;end if;elsif she=0 thenbmark<=bmark+1;a:=’0’;b:=’0’;elseif aj=’0’thena:=’1’;b:=’0’;elseshe:=she(6 downto 0)&’0’;end if;end if;end if;end if;shift<=she;end process;process(clk,clr,amark,bmark)variable aha,ala,bha,bla:std_logic_vector(3 downto 0); variable tmp1,tmp2:integer;variable t1,t2:std_logic;beginif clr=’0’then --清零aha:=”0000”;ala:=”0000”;bha:=”0000”;bla:=”0000”;tmp1:=0;tmp2:=0;t1:=’0’;t2:=’0’;elsif clk’event and clk=’1’ thenif aha=”0001” and ala=”0001” then --a方得分达到11分,则保持 aha:=”0001”;ala:=”0001”;t1:=’1’;elsif bha=”0001”and bla=”0001” then --b方得分达到11分,则保持 bha:=”0001”;bla:=”0001”;t2:=’1’;elsif amark>tmp1 thenif ala=”1001” thenala:=”0000”;aha:=aha+1;tmp1:=tmp1+1;elseala:=ala+1;tmp1:=tmp1+1;end if;elsif bmark>tmp2 thenif bla=”1001” thenbla:=”0000”;bha:=bha+1;tmp2:=tmp2+1;elsebla:=bla+1;tmp2:=tmp2+1;end if;end if;end if;al<=ala;bl<=bla;ah<=aha;bh<=bha;awin<=t1;bwin<=t2;end process;end behave;4.2送数据模块的设计4.2.1 ch41a模块分析图4.2 ch41a模块分析及原理图4.2.2 ch41a模块VHDL程序描述Library IEEE;Use IEEE.std_logic_1164.all;Entity ch41a isPort(sel:in std_logic_vector(2 downto 0);D0,d1,d2,d3:in std_logic_vector(3 downto 0);Q:out std_logic_vector(3 downto 0));End ch41a;Architecture behave of ch41a isBeginProcess(sel)BeginCase sel isWhen”100”=>q<=d0;When”101”=>q<=d1;When”000”=>q<=d2;When others=>q<=d3;End case;End process;End behave;4.3产生数码管片选信号模块的设计4.3.1 sel模块分析图4.3 sel模块分析及原理图4.3.2 sel模块VHDL程序描述Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity sel isPort(clk:in std_logic;Sell:out std_logic_vector(2 downto 0)); End sel;Architecture behave of sel isBeginProcess(clk)Variable tmp:std_logic_vector(2 downto 0); BeginIf clk’event and clk=’1’ thenIf tmp=”000” thenTmp:=”001”;Elsif tmp=”001” thenTmp:=”100”;Elsif Tmp=”100” thenTmp:=”101”;Elsif tmp=”101” thenTmp:=”000”;End if;End if;Sell<=tmp;End process;End behave;4.4 七段译码器模块的设计4.4.1 disp模块分析图4.4 disp模块分析及原理4.4.2 disp模块VHDL程序描述Library ieee;Use ieee.std_logic_1164.all;Entity disp isPort(d:in std_logic_vector(3 downto 0);Q:out std_logic_vector(6 downto 0));End disp;Architecture behave of disp isBeginProcess(d)BeginCase d isWhen”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 others=>q<=”1101111”;End case;End process;End behave;4.5顶层原理图设计图4.5 顶层模块原理图5 各模块的时序仿真图图5.1为A方两次发球,B方没有接到球,A方得到2分的仿真波形图图5.1 仿真波形图图5.2所示为A方发球,B方提前击球的情况,此时,A方得一分。

相关主题