四人抢答器
一、设计任务:
l、设计用于竞赛的四人抢答器,功能如下: (1) 有多路抢答器,台数为四;
(2) 具有抢答开始后20秒倒计时,20秒倒计时后无人抢答显示超时,并报警; (3) 能显示超前抢答台号并显示犯规警报; (4) 能显示各路得分,并具有加、减分功能;
2、系统复位后进入抢答状态,当有一路抢答键按下时,该路抢答信号将其余各路抢答封锁,同时铃声响,直至该路按键松开,显示牌显示该路抢答台号。
3、用VHDL语言设计符合上述功能要求的四人抢答器,并用层次设计方法设计该电路
二、设计思路:
将该任务分成三个模块进行设计,分别为:抢答器鉴别模块、抢答器计时模块、抢答器记分模块,最后是撰写顶层文件。
1、抢答器鉴别模块:
在这个模块中主要实现抢答过程中的抢答功能,并能对超前抢答进行警告,还能记录无论是正常抢答还是朝前抢答者的台号,并且能实现当有一路抢答按键按下时,该路抢答信号将其余个绿抢答封锁的功能。其中有四个抢答信号a、b、c、d;抢答使能信号en;抢答状态显示信号states;警报时钟信号clk2;系统复位信号rst;超前警报信号ring。
2、抢答器计时模块:
在这个模块中主要实现抢答过程中的计时功能,在有抢答开始后进行20秒的倒计时,并且在20秒倒计时后无人抢答显示超时并报警。其中有抢答时钟信号clk;系统复位信号rst;抢答使能信号en;抢答状态显示信号states;无人抢答警报信号warn;计时中止信号stop;计时十位个位信号tb,ta。
3、抢答器记分模块:
在这个模块中主要是给四个抢答信号记分,并给每个抢答信号预置5分,当抢答并答对时加1分,答错减1分,没有获得抢答保持不变。其中有抢答时钟信号clk;系统复位信号rst;抢答使能信号en;抢答状态显示信号states;记分加减信号add(add=‘1’时为加,add=‘0’时为减);四个信号的得分显示信号a_out,b_out,c_out,d_out。
4、顶层文件:
在这个模块中是对前三个模块的综合编写的顶层文件。
三、具体实施:
1、本设计的实现电路图:
2、本设计的源程序:
library ieee;--抢答鉴别模块 use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity qdjb is
port(clk2,en,rst:in std_logic;
a,b,c,d:in std_logic;
ring:out std_logic;
states:out downto 0)); end qdjb; architecture one of qdjb is signal sinor,ringf,tmp:std_logic; signal cnt:std_logic_vector(5 downto 0); begin sinor
begin
if rst=\'1\' then
tmp
elsif tmp=\'1\' then
if a=\'1\' then
states
elsif b=\'1\' then
states
elsif c=\'1\' then
states
elsif d=\'1\' then
states
else tmp
end if ;
end if; end proce p1; p2roce(clk2,en,rst,cnt)
begin
if rst=\'1\' then
cnt
elsif clk2\'event and clk2=\'1\' then
if en=\'0\' and sinor=\'1\' then
if cnt
ringf
else ringf
end if;
end if;
end if; end proce p3; ring
library ieee;--抢答器计时模块 use ieee.std_logic_1164.all; std_logic_vector(3 use ieee.std_logic_unsigned.all; entity js is
port(clk,rst,en,stop:in std_logic;
warn:buffer std_logic;
ta,tb:buffer std_logic_vector(3 downto 0)); end js; architecture one of js is signal co:std_logic; begin p1:proce(clk,rst,en,stop,ta)
begin
if rst=\'1\' or stop=\'1\' then
ta
elsif clk\'event and clk=\'1\' then
co
if en=\'1\' then
if ta=\"0000\" then
ta
else ta
end if;
end if;
end if; end proce p1; p2:proce(co,rst,en,stop,tb)
begin
if rst=\'1\' or stop=\'1\' then
tb
elsif co\'event and co=\'1\' then
if en=\'1\' then
if tb=\"0000\" then tb
else tb
end if;
end if;
end if; end proce p2; p3:proce(rst,ta,tb)
begin
if rst=\'1\' then
warn
elsif ta=\"0000\" and tb=\"0000\" then
warn
else warn
end if; end proce p3; end one;
library ieee;--抢答器记分模块 use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity jf is
port(clk,rst,en,add:in std_logic;
states:in std_logic_vector(3 downto 0);
a_out,b_out,c_out,d_out:buffer std_logic_vector(3 downto 0)); end jf;
architecture one of jf is begin
p2:proce(clk,rst,add,states,a_out,b_out,c_out,d_out)
begin
if (rst=\'1\') then
a_out
elsif en=\'1\'then
if clk\'event and clk=\'1\' then
case states is
when \"0001\"=>
if add=\'1\' then
if a_out=\"1111\" then
a_out
else a_out
end if;
elsif add=\'0\' then
if a_out=\"0000\" then
a_out
else a_out
end if;
end if;
when \"0010\"=>
if add=\'1\' then
if b_out=\"1111\" then
b_out
else b_out
end if;
elsif add=\'0\' then
if b_out=\"0000\" then
b_out
else b_out
end if;
end if;
when \"0011\"=>
if add=\'1\' then
if c_out=\"1111\" then
c_out
else c_out
end if;
elsif add=\'0\' then
if c_out=\"0000\" then
c_out
else c_out
end if;
end if;
when \"0100\"=>
if add=\'1\' then
if d_out=\"1111\" then
d_out
else d_out
end if;
elsif add=\'0\' then
if d_out=\"0000\" then
d_out
else d_out
end if;
end if;
when others=>
a_out
end case;
end if;
end if;
end proce p2; end one;
library ieee;--抢答器顶层文件 use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity qiangda is
port(clk,clk2,en,a,b,c,d,add,stop,rst:in std_logic;
ring,alarm:out std_logic;
ta,tb:buffer std_logic_vector(3 downto 0);
states:buffer std_logic_vector(3 downto 0);
a_out,b_out,c_out,d_out:buffer std_logic_vector(3 downto 0)); end qiangda;
architecture bhv of qiangda is component qdjb is
port(clk2,en,rst:in std_logic;
a,b,c,d:in std_logic;
ring:out std_logic;
states:out std_logic_vector(3
downto 0)); end component; component js is
port(clk,rst,en,stop:in std_logic;
warn:buffer std_logic;
ta,tb:buffer std_logic_vector(3 downto 0)); end component;
component jf is
port(clk,rst,en,add:in std_logic;
states:in downto 0);
a_out,b_out,c_out,d_out:buffer std_logic_vector(3 downto 0)); end component; signal cnt:std_logic_vector(3 downto 0); std_logic_vector(3
begin
u1:qdjb port map(clk2,en,rst,a,b,c,d,ring,states); u2:js port map(clk,rst,en,stop,alarm,ta,tb); u3:jf ; end bhv;
port
map(clk,rst,en,add,states,a_out,b_out,c_out,d_out)
四、结果分析:
(一)、软件分析:
1、抢答器鉴别模块:
编译报告:
仿真结果:
2、抢答器计时模块:
编译报告:
仿真结果:
3、抢答器记分模块:
编译报告:
仿真结果:
4、抢答器顶层模块:
编译报告:
仿真结果:
顶层文件的RTL级:
管脚锁定图:
(二)、硬件分析:
五、参考文献: