EDA课程设计乒乓球游戏机vhd语言l - 图文
更新时间:2024-07-08 10:54:01 阅读量: 综合文库 文档下载
《基于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 系统整体架构(Architecture Description) ?????04页 2.1 设计思路???????????????????04页 2.2 系统原理(包含:框图等阐述与设计说明等内容)?04页
3 系统设计 (含HDL或原理图输入设计)?????????05页 3.1 HDL 代码???????????????????05页 3.2 系统整体电路图(或RTL级电路图)???????12页
4 系统仿真(Simulation Waveform)??????????13页
5 FPGA实现(FPGA Implementation) ?????????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)比赛结束后音乐自动响起。
二、系统整体架构(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 is
type 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):=\ ---内部计数器,是4位二进制变量 begin
process(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 then count1<=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 then i<=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' then i<=0;count1<=0;count2<=0;count3<=0;count4<=0;count5<=0;count6<=0; else --以下case语句是程序中最关键的状态机部分 case state is when waitserve=>
--进程处于等待发球状态
case serve is when \ when \ when \ when “00”=> i<=0;sound<=”0”; end case; when light1on=> --进程处于第一盏灯亮状态 i<=2; if hit2='1' or hit22=’1’ then i<=0; count1<=count1+1;sound<=”1”state<=waitserve; else state<=ballmoveto2; end if; when light8on=> --进程处于第八盏灯亮状态 i<=7; if hit1='1' or hit11=”1” then i<=0; count2<=count2+1;sound<=”1”;state<=waitserve; else state<=ballmoveto1; end if; when ballmoveto1=> --进程处于球向甲移动状态 if hit1='1' then i<=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'then i<=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<=\
\\\\\\\\
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 is port( cp:in std_logic; clk_4:out std_logic ); end division16;
architecture division_body of division16 is signal count:std_logic_vector(3 downto 0); begin
process(cp) begin
if(cp'event and cp='1')then if(count=\count<=(others=>'0'); else
count<=count+1; end if; end if;
end process; process(cp) begin
if(cp'event and cp='1')then if(count=\clk_4<='1'; else
clk_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 \ when \ when \ when \ when \ when \ when \ when \ when \ when \ when others=>q<=\ 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) BEGIN IF(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; begin
process(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;
六、总结(Closing)
经过一学期的学习,在陈强老师的教导下,我对在系统编程技术这门课有了很深刻的理解,并能结合所学的知识设计了这次的乒乓球游戏机。由于实验箱上脉冲端有限,于是我又想到了要设计一个分频器,我开始设计的是16分频和64分频,因为我需要一个4Hz和1Hz的脉冲信号,但是,这样做对整个电路而言没有任何效果,无论怎样都仿真不出波形,但是代码没错,单独仿真分频器也有波形输出。当我准备放弃时,我又抱着侥幸心理只设计一个16分频的分频器,我把分频器接入电路,然后仿真,结果仿真波形出来了。然后下载到实验箱验证时,结果甲乙两位选手的得分不能再同一排数码管上显示,后经过我冷静的分析,我想到了曾经做过的60进制计数器,于是我便加了个数码管选择器,这样甲乙二人的分数可以再同一排数码上显示了。
经过这次实训,我收获颇丰,学到了很多知识,特别是提高了综合分析应用的能力。我学会了如何去完成一个任务,懂得了享受过程。当遇到问题,冷静,想办法一点一点的排除障碍,到最后获取成功,一种自信心由然而生。实训是对每个人综合能力的检验。要想做好任何事,除了自己平时要有一定的功底外,我们还需要一定的实践动手能力,操作能力。此次实训,我深深体会到了积累知识
的重要性。在短暂的实训过程中,让我深深的感觉到自己在实际运用中的知识的匮乏这时才真正领悟到“学无止境”的含义。
参考书目(Reference):
李国丽 朱维勇 《电子技术实验指导书》 中国科技大学出版社 潘松 黄继 《EDA技术实用教程》 科学出版社 王金明 《Verilog HDL程序设计教程》
宋万杰 罗丰 吴顺君 《CPLD技术及其应用》 西安电子科技大学出版社
张昌凡 龙永红 彭涛 《可编程逻辑器件及VHDL设计技术》 华南工学院出版社 陈强 《EDA技术与实验》 三峡学院内部试用 LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL; ENTITY mux2 IS
PORT(a,b: IN STD_LOGIC; sel: IN STD_LOGIC; c:out std_logic); END mux2;
ARCHITECTURE example OF mux2 IS BEGIN
PROCESS(sel) BEGIN IF(SEL='1')THEN c<=a; ELSE c<=b; END IF;
END PROCESS; END example;
正在阅读:
某工程施工组织设计04-28
2010-2018年会计师事务所行政处罚原因汇总分析11-13
青岛版三年级上册数学期末测试题105-16
难忘的拓展训练生活作文06-21
发电厂电气部分复习资料10-25
海南旅游发展04-21
中国教育寓言故事03-17
实验室安全考试10-19
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 游戏机
- 乒乓球
- 语言
- 课程
- 图文
- 设计
- EDA
- vhd
- 2006年1月-200710
- 大工《电工学》课程考试模拟试卷A
- 单片机学习习题答案
- 山西省忻州市2012-2013学年高二物理上学期期末联考试题 文 新人
- 新版人教版三年级语文下册第五单元试卷3套(2019最新编辑)
- 坐禅实务 导师 净元禅师
- 保险公司经营业绩工作总结-word范文模板(6页)
- 人教课标版小学数学三年级下册全册导学案41 - 图文
- 员工行为规范及奖惩条例
- 《国王的演讲》观后感
- 2015年高考历史真题汇编 古代希腊罗马的政治制度 第6课 罗马法的
- 2013-2014学年机械13-08班评优材料 - 图文
- “十三五”重点项目-铁矿石开挖项目申请报告
- 适用于液晶1602 - 图文
- 统计学实验报告
- 有机化学的发展前沿和研究热点
- 葡萄胎1
- 江苏省淮安市八年级生物上学期第一次月考试题新人教版
- 网络安全考试2014.4
- 2011年最新中考数学模拟试卷(80)