课程EDA技术课程设计题目拔河游戏机专业电子信息工程主要内容、基本要求、主要参考资料等主要内容:电子拔河游戏机是一种能容纳甲乙双方参赛游戏电路。
由一排发光二极管表示拔河的“电子绳”。
由甲乙双方通过按纽开关使发光二极管向一方的终点延伸,当延伸到某方的最后一个发光二极管时,则该方获胜,连续比赛多局以定胜负。
基本要求:1、设计一个能进行拔河游戏的电路。
2、电路使用9个发光二极管,开机后只有中间一个发亮,此即拔河的中心点。
3、游戏双方各持一个按钮,迅速地、不断地按动,产生脉冲,谁按得快,亮点就向谁的方向移动,每按一次,亮点移动一次。
4、亮点移到任一方终端二极管时,这一方就获胜,此时双方按钮均无作用,输出保持,只有复位后才使亮点恢复到中心。
5、用数码管显示获胜者的盘数。
主要参考资料:[1] 潘松著.EDA技术实用教程(第二版). 北京:科学出版社,2005.[2] 康华光主编.电子技术基础模拟部分. 北京:高教出版社,2006.[3] 阎石主编.数字电子技术基础. 北京:高教出版社,2003.完成期限2011.3.11指导教师专业负责人2011年3月7日一、总体设计思想1.基本原理由设计内容可知,需要一个十进制的计数器,用于对双方按钮的次数计数,并通过译码器显示在数码管上。
设计要求用50MHz的频率,而设计用到的是1KHz 的频率,所以要设计一个程序进行分频。
显视控制部分设计要求在发光二极管上显示游戏状态,双方每按十次,亮点向先按十次移动一次,对脉冲进行计数,每十次移一位。
需接入一个清零端,用于复位。
将以上程序组装起来。
2.设计框图图1. 拔河机游戏机框图二、设计步骤和调试过程1、总体设计电路总体电路图和仿真图如图(25)所示,由仿真图可知,此电路设计无误,可以实现按动A、B两个按键时,分别产生两个脉冲信号,经整形后分别加到可逆计数器上,可逆计数器输出的代码经译码器译码后驱动电平指示灯点亮并产生位移,当亮点移到任何一方终端后,由于控制电路的作用,使这一状态被锁定,双方按键产生的输入脉冲不起作用。
如按动复位键C,亮点又回到中点位置,再次按C键则比赛又可重新开始。
图2. 电路图2、模块设计和相应模块程序1.顶层文件library IEEE;use IEEE.std_logic_1164.all;use IEEE.std_logic_unsigned.all;entity bahe isport(player1,player2:in std_logic; --玩家1,2输入clk_in:in std_logic; --clk_in(1MHZ)reset:in std_logic; --重置键row : out std_logic_vector(7 downto 0);col : out std_logic_vector(7 downto 0);led:out std_logic_vector(7 downto 0); --绳子cats:out std_logic_vector(6 downto 0); --比分q:out std_logic_vector(5 downto 0); --数码管控制mus:out std_logic); --蜂鸣输出end bahe;architecture body_bahe of bahe iscomponent divisionport(clk_in:in std_logic; --1MHZ输入clk_100,clk_5,clk_1:out std_logic);--100HZ,5Hz,1HZend component;--计数模块component countport(clk_1:in std_logic; --1HZ输入sw:in std_logic; --状态开关player1,player2:in std_logic; --选手输入sum1,sum2:out std_logic_vector(4 downto 0)); --计数结果输出end component;--比较模块component cmpport(clk_100:in std_logic; --100hzclk_1:in std_logic; --1hzsw:out std_logic; --状态开关输出reset:in std_logic; --重置start:in std_logic; --开始sum1,sum2:in std_logic_vector(4 downto 0);--计数结果输入music_begin:out std_logic; --音乐record1,record2:out std_logic_vector(1 downto 0);--比分输出lights:out std_logic_vector(2 downto 0)); --拔河绳子显示end component;--音乐模块component musicport(reset:in std_logic; --重置clk:in std_logic; --1MHzclk_5:in std_logic; --5hzmusic_begin:in std_logic; --音乐开始mus:out std_logic);end component;--译码模块component decodeport(clk_in:in std_logic; --1mHZrecord1,record2:in std_logic_vector(1 downto 0); --比分输入lights:in std_logic_vector(2 downto 0); --拔河绳子输入q:buffer std_logic_vector(5 downto 0); --数码管控制cats:out std_logic_vector(6 downto 0) --数码管显示比分);end component;--倒计时模块component daojishiport(clk_in,clk_1,reset:in std_logic;row : out std_logic_vector(7 downto 0);col : out std_logic_vector(7 downto 0);start: out std_logic);end component;--分频器输出signal clk_100,clk_5,clk_1:std_logic; --时钟信号--计数器输出signal sum1,sum2:std_logic_vector(4 downto 0); --计数结果--比较器输出signal sw:std_logic; --状态开关signal record1,record2:std_logic_vector(1 downto 0); --比分signal lights:std_logic_vector(2 downto 0); --绳子signal music_begin:std_logic;--解码器输出signal tmp_led:std_logic_vector(7 downto 0); --LED显示signal tmp_q:std_logic_vector(5 downto 0); --数码管控制signal tmp_cat:std_logic_vector(6 downto 0); --数码管显示比分--倒计时器输出signal tmp_start:std_logic;begincats<=tmp_cat;q<=tmp_q;led<=tmp_led;div: division port map(clk_in=>clk_in,clk_100=>clk_100,clk_5=>clk_5,clk_1=>clk_1);cnt: count port map(clk_1=>clk_1,sw=>sw,player1=>player1,player2=>player2,sum1=>sum1,sum2=>sum2);com: cmp port map(clk_100=>clk_100,clk_1=>clk_1,sw=>sw,reset=>reset,record1=>record1,record2=>record2,lights=>lights);dec: decode port map(clk_in=>clk_in,record1=>record1,record2=>record2,lights=>lights,led=>tmp_led,q=>tmp_q,cats=>tmp_cat);mu: music port map(reset=>reset,clk=>clk_in,clk_5=>clk_5,music_begin=>music_begin,mus=>mus);dao: daojishi port map(clk_in=>clk_in,clk_1=>clk_1,reset=>reset,start=>tmp_start,col=>col,row=>row);end body_bahe;2.CMP模块library IEEE;use IEEE.std_logic_1164.all;use IEEE.std_logic_unsigned.all;entity cmp isport(clk_100:in std_logic; --100HZ输入 clk_1:in std_logic; --1HZ输入reset:in std_logic; --重置start:in std_logic; --开始sum1,sum2:in std_logic_vector(4 downto 0); --计数输入record1,record2:out std_logic_vector(1 downto 0); --比分输出music_begin:out std_logic; --音乐开始sw:out std_logic; --状态输出lights:out std_logic_vector(2 downto 0)); --绳子状态end cmp;architecture body_cmp of cmp issignal tmp_record1:std_logic_vector(1 downto 0); --比分signal tmp_record2:std_logic_vector(1 downto 0);signal tmp:std_logic_vector(2 downto 0); --绳子状态signal tmp_sta:std_logic; --状态signal s1,s2:std_logic_vector(4 downto 0); --计数record1<=tmp_record1;record2<=tmp_record2;lights<=tmp;sw<=tmp_sta;process(clk_100) --判断比赛状态beginif(start='1') thenif(clk_100'event and clk_100='1') thentmp_sta<='1';end if;end if;if(clk_100'event and clk_100='1') then --任意比分到3,比赛结束,开始播放音乐if(tmp_record1="11" or tmp_record2="11") thentmp_sta<='0';music_begin<='1';end if;if(tmp="001" or tmp="111") then --绳子到头,进入等待状态tmp_sta<='0';end if;if(reset='1') then --复位,状态归零tmp_sta<='0';music_begin<='0';end if;end if;end process;s1<=sum1;s2<=sum2;process(clk_1,reset) --控制绳子移位beginif(reset='1') thentmp<="100"; --绳子初始状态为100tmp_record1<="00";tmp_record2<="00";elseif(clk_1'event and clk_1='1') thenif(tmp_sta='1') thenif(s1>s2) then tmp<=tmp-'1'; --绳子左移elsif(s1=s2) then tmp<=tmp; --绳子保持原状else tmp<=tmp+'1'; --绳子右移elseif(tmp="001") then --绳子到左尽头,左计分器加1tmp_record1<=tmp_record1+'1';tmp<="100";elsif(tmp="111") then --绳子到右尽头,右记分器加1,tmp_record2<=tmp_record2+'1';tmp<="100";end if;end if;end if;end if;end process;end body_cmp;3.COUT模块use IEEE.std_logic_1164.all;use IEEE.std_logic_unsigned.all;entity count islibrary IEEE;port(clk_1:in std_logic; --1HZ输入sw:in std_logic; --状态判断输入player1,player2:in std_logic; --选手输入sum1,sum2:out std_logic_vector(4 downto 0)); --计数输出end count;architecture body_count of count issignal p1,p2:std_logic_vector(4 downto 0); --计数输出beginsum1<=p1;sum2<=p2;process(player1,player2,sw,clk_1)beginif(sw='1') then --处于比赛状态if(clk_1='0') thenif(player1'event and player1='1') thenp1<=p1+'1';if(player2'event and player2='1') thenp2<=p2+'1';end if;elsep1<="00000";p2<="00000";end if; --比赛状态结束else p1<="00000";p2<="00000";end if;end process;end body_count;4.daojishi模块library IEEE;use IEEE.std_logic_1164.all;use IEEE.std_logic_unsigned.all;entity daojishi isport(clk_1,clk_in,reset: in std_logic;row : out std_logic_vector(7 downto 0);col : out std_logic_vector(7 downto 0);start : out std_logic);end daojishi;architecture body_daojishi of daojishi istype state is (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10);signal present_state:state:=s10;signal num:std_logic_vector(2 downto 0):="000";beginp3:process(clk_in)beginif clk_in'event and clk_in='1' thenif num="101" then num<="000";else num<=num+1;case present_state iscase num iswhen "000"=> col<="11111111"; row<="11111111"; when "001"=> col<="11011111"; row<="01110100"; when "010"=> col<="11101111"; row<="01010100"; when "011"=> col<="11110111"; row<="01010100"; when "100"=> col<="11111011"; row<="01111100"; when others=> col<="00000000"; row<="00000000"; end case;when s8=>case num iswhen "000"=> col<="11111111"; row<="11111111"; when "001"=> col<="11011111"; row<="01111100"; when "010"=> col<="11101111"; row<="01010100"; when "011"=> col<="11110111"; row<="01010100"; when "100"=> col<="11111011"; row<="01111100"; when others=> col<="00000000"; row<="00000000"; end case;when s7=>case num iswhen "000"=> col<="11111111"; row<="11111111"; when "001"=> col<="11011111"; row<="01000000"; when "010"=> col<="11101111"; row<="01000000"; when "011"=> col<="11110111"; row<="01000000"; when "100"=> col<="11111011"; row<="01111100"; when others=> col<="00000000"; row<="00000000"; end case;when s6=>case num iswhen "000"=> col<="11111111"; row<="11111111"; when "001"=> col<="11011111"; row<="01111100"; when "010"=> col<="11101111"; row<="01010100"; when "011"=> col<="11110111"; row<="01010100"; when "100"=> col<="11111011"; row<="01011100"; when others=> col<="00000000"; row<="00000000"; end case;when "001"=> col<="11011111"; row<="01110100"; when "010"=> col<="11101111"; row<="01010100"; when "011"=> col<="11110111"; row<="01010100"; when "100"=> col<="11111011"; row<="01011100"; when others=> col<="00000000"; row<="00000000"; end case;when s4=>case num iswhen "000"=> col<="11111111"; row<="11111111"; when "001"=> col<="11011111"; row<="01110000"; when "010"=> col<="11101111"; row<="00010000"; when "011"=> col<="11110111"; row<="00010000"; when "100"=> col<="11111011"; row<="01111100"; when others=> col<="00000000"; row<="00000000"; end case;when s3=>case num iswhen "000"=> col<="11111111"; row<="11111111"; when "001"=> col<="11011111"; row<="01010100"; when "010"=> col<="11101111"; row<="01010100"; when "011"=> col<="11110111"; row<="01010100"; when "100"=> col<="11111011"; row<="01111100"; when others=> col<="00000000"; row<="00000000"; end case;when s2=>case num iswhen "000"=> col<="11111111"; row<="11111111"; when "001"=> col<="11011111"; row<="01011100"; when "010"=> col<="11101111"; row<="01010100"; when "011"=> col<="11110111"; row<="01010100"; when "100"=> col<="11111011"; row<="01110100"; when others=> col<="00000000"; row<="00000000"; end case;when s1=>when "001"=> col<="11011111"; row<="00000000"; when "010"=> col<="11101111"; row<="00000000"; when "011"=> col<="11110111"; row<="00000000"; when "100"=> col<="11111011"; row<="01111100"; when others=> col<="00000000"; row<="00000000"; end case;when s0=>case num iswhen "000"=> col<="11111111"; row<="11111111"; when "001"=> col<="11011111"; row<="01111100"; when "010"=> col<="11101111"; row<="01000100"; when "011"=> col<="11110111"; row<="01000100"; when "100"=> col<="11111011"; row<="01111100"; when others=> col<="00000000"; row<="00000000"; end case;when others=>case num iswhen "000"=> col<="00000000"; row<="00000000"; when "001"=> col<="00000000"; row<="00000000"; when "010"=> col<="00000000"; row<="00000000"; when "011"=> col<="00000000"; row<="00000000"; when "100"=> col<="00000000"; row<="00000000"; when others=> col<="00000000"; row<="00000000"; end case;end case;end if;end if;end process p3;p4:process(clk_1)beginif reset='1' then present_state<=s10;start<='0';elseif clk_1'event and clk_1='1' thencase present_state iswhen s10=> present_state<=s9;start<='0';when s9=> present_state<=s8;start<='0';when s8=> present_state<=s7;start<='0';when s7=> present_state<=s6;start<='0';when s6=> present_state<=s5;start<='0';when s5=> present_state<=s4;start<='0';when s4=> present_state<=s3;start<='0';when s3=> present_state<=s2;start<='0';when s2=> present_state<=s1;start<='0';when s1=> present_state<=s0;start<='1';when s0=> present_state<=present_state;when others=>null;start<='1';end case;end if;end if;end process p4;end body_daojishi;library IEEE;use IEEE.std_logic_1164.all;use IEEE.std_logic_unsigned.all;entity decode isport(clk_in:in std_logic; --1MHz record1,record2:in std_logic_vector(1 downto 0); --比分状态输入 lights:in std_logic_vector(2 downto 0); --绳子状态输入led:out std_logic_vector(7 downto 0); --绳子解码后输出q:buffer std_logic_vector(5 downto 0); --数码管控制cats:out std_logic_vector(6 downto 0)); --数码管显示end decode;architecture body_decode of decode issignal tmp_led:std_logic_vector(7 downto 0); --绳子输出signal tmp_da1:std_logic_vector(6 downto 0); --比分1signal tmp_da2:std_logic_vector(6 downto 0); --比分2signal tmp:std_logic_vector(6 downto 0); --比分显示beginled<=tmp_led;cats<=tmp;process(clk_in,lights,record1,record2,q,tmp_da2,tmp_da1,tmp)begincase lights is --绳子状态when "100"=> tmp_led<="00010000";when "011"=> tmp_led<="00001000";when "010"=> tmp_led<="00000100";when "001"=> tmp_led<="00000010";when "101"=> tmp_led<="00100000";when "110"=> tmp_led<="01000000";when "111"=> tmp_led<="10000000";when others =>tmp_led<="00010000";end case;case record1 is --比分状态when "00"=> tmp_da1<="1111110";when "01"=> tmp_da1<="0110000";when "10"=> tmp_da1<="1101101";when "11"=> tmp_da1<="1111001";end case;case record2 is --比分状态when "00"=> tmp_da2<="1111110";when "01"=> tmp_da2<="0110000";when "10"=> tmp_da2<="1101101";when "11"=> tmp_da2<="1111001";end case;if(clk_in='1') thenq<="111110";end if;if(clk_in='0') thenq<="011111";end if;case q is --数码管显示控制when "011111"=> tmp<=tmp_da2;when "111110"=> tmp<=tmp_da1;when others=> tmp<="0000000";end case;end process;end body_decode;3、仿真及仿真结果分析创建一个仿真波形文件,输入引脚,并对所有input引脚付出值,保存仿真波形文件。