本文為大家帶來三種四人搶答器的VHDL語言設計方案介紹。
VHDL語言設計四人搶答器方案一
設計要求
l、設計用于競賽的四人搶答器,功能如下:
(1)有多路搶答器,臺數為四,能顯示搶答臺號;
(2)具有搶答開始后20秒倒計時,20秒倒計時后無人搶答顯示超時,并報警;
(3)能顯示超前搶答臺號并顯示犯規警報;
2、系統復位后進入搶答狀態,當有一路搶答鍵按下時,該路搶答信號將其余各路搶答封鎖,同時鈴聲響,直至該路按鍵松開,顯示牌顯示該路搶答臺號。
3、用VHDL語言設計符合上述功能要求的四人搶答器,并用層次設計方法設計該電路。
電路工作原理
簡易邏輯數字搶答器由主體電路與擴展電路組成。優先編碼電路、鎖存器、譯碼電路將參賽隊的輸入信號在顯示器上輸出;用控制電路和主持人開關啟動報警電路,以上兩部分組成主體電路。通過定時電路和譯碼電路將秒脈沖產生的信號在顯示器上輸出實現計時功能,構成擴展電路。
電路主要由脈沖產生電路、鎖存電路、編碼及譯碼顯示電路、倒計時電路和音響產生電路組成。當有選手搶答時,首先鎖存,阻止其他選手搶答,然后編碼,再經譯碼器將數字顯示在顯示器上同時產生音響。主持人宣布開始搶答時,倒計時電路啟動由20計到0,如有選手搶答,倒計時停止,如20秒后無人搶答,則會顯示報警。
源程序
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityqdqis
port(clr,clk,clk0,en,a,b,c,d:instd_logic;
dps:outstd_logic_vector(3downto0);
count:outstd_logic_vector(7downto0);
speaker:outstd_logic);
end;
architectureoneofqdqis
signaldps1:std_logic_vector(3downto0);
signalcount1:std_logic_vector(7downto0);
signaltmp1,tmp2,tmp3:std_logic;
begin
p1:process(clr,en,tmp1,tmp2)
begin
ifclr=‘1’then
tmp1<=‘0’;tmp2<=‘0’;
dps1<=“0000”;
elsifen=‘1’then
iftmp1=‘0’then
ifa=‘1’then
tmp1<=‘1’;
dps1<=“0001”;
endif;
ifb=‘1’thentmp1<=‘1’;
dps1<=“0010”;
endif;
ifc=‘1’thentmp1<=‘1’;
dps1<=“0011”;
endif;
ifd=‘1’thentmp1<=‘1’;
dps1<=“0100”;
endif;
endif;
elsifen=‘0’then
iftmp2=‘0’then
ifa=‘1’then
tmp2<=‘1’;
dps1<=“0001”;
endif;
ifb=‘1’then
tmp2<=‘1’;
dps1<=“0010”;
endif;
ifc=‘1’then
tmp2<=‘1’;
dps1<=“0011”;
endif;
ifd=‘1’then
tmp2<=‘1’;
dps1<=“0100”;
endif;
endif;
endif;
endprocess;
p2:process(clr,clk,tmp1,tmp3)
begin
ifclk‘eventandclk=’1‘then
ifclr=’1‘thencount1<=“00100000”;
tmp3<=’0‘;
elsifen=’1‘andtmp1=’0‘andtmp3=’0‘then
ifcount1=“00000000”then
tmp3<=’1‘;
elsifcount1(3downto0)=“0000”then
count1(3downto0)<=“1001”;
count1(7downto4)<=count1(7downto4)-’1‘;
elsecount1(3downto0)<=count1(3downto0)-’1‘;
endif;
endif;
endif;
endprocess;
count<=count1;
dps<=dps1;
speaker<=((tmp3oraorborcord)andclk0);
end;
仿真波形
(一)無人搶答的仿真波形
由上圖可知,當en=0時此時主持人并沒有提出開始搶答的信號.en=1,開始搶答的時候20秒倒計時,時間到而無人搶答。(count=“00000000”),則speaker報警,按下清零開關(clr=1),重新開始20秒倒計時進行下一輪
(二)有人搶答的仿真波形
由上圖可知,clr=1,系統進入初始狀態,即count=“00100000”,dps=“0000”;en=0時,此時主持人并沒有提出開始搶答的信號是不允許搶答的,若有人搶答(b=1),則speaker報警,且數碼管顯示組別(dps=“0010”)顯示出犯規的組別;en=1時,開始正常搶答而且count開始20秒倒計時,在15秒時(count=“00010101”)有人搶答(a=1),倒計時暫停同時鎖存器工作將其他組別的信號鎖存后面的信號將視為無效,數碼管顯示組別(dps=“0001”),且speaker報警。
評論
查看更多