VHDL四人抢答器
一 設(shè)計(jì)任務(wù)及要求:
(1)設(shè)計(jì)用于競賽搶答的四人搶答器;
◇有多路搶答,搶答臺數(shù)為4;
◇具有搶答開始后20秒倒計(jì)時(shí),20秒倒計(jì)時(shí)后無人搶答顯示超時(shí),并報(bào)警;
◇能顯示超前搶答臺號并顯示犯規(guī)警報(bào);
(2)系統(tǒng)復(fù)位后進(jìn)入搶答狀態(tài),當(dāng)有一路搶答按鍵按下,該路搶答信號將其余各路搶答信號封鎖,同時(shí)鈴聲想起,直至該路按鍵松開,顯示牌顯示該路搶答臺號;
(3)用VHDL語言設(shè)計(jì)符合上述功能要求的四人搶答器,并用層次化設(shè)計(jì)方法設(shè)計(jì)該電路;
二 采用自頂向下模式,總體布局直至分化模塊,由模塊組成整體。
2 模塊功能分析
2.1編碼器
編碼器的作用是將開關(guān)信息轉(zhuǎn)化為8421BCD碼,以提供數(shù)字顯示電路所需要的編碼輸入。
2.2 鎖存器
當(dāng)只要有一個(gè)且為任意一個(gè)選手搶答輸入信號產(chǎn)生時(shí),鎖存器電路被觸發(fā),在輸出端產(chǎn)生相應(yīng)的開關(guān)電平信息,同時(shí)為避免之后的搶答開關(guān)按鈕也按下產(chǎn)生錯(cuò)亂,最先產(chǎn)生的輸出電平變化又反饋回來將鎖存器器鎖定住,并保持輸出的電平信息。
2.3 譯碼器
譯碼器的作用是將編碼器輸出的8421BCD碼轉(zhuǎn)化為數(shù)碼管需要的邏輯狀態(tài)。
2.4號碼和時(shí)間顯示器
數(shù)碼顯示管有發(fā)光的共陰二極管(LED)數(shù)碼管,喇叭為高電平觸發(fā)。
2.5分頻器
通過脈沖來進(jìn)行計(jì)時(shí),用來搶答倒計(jì)時(shí)。
2.6報(bào)警器
當(dāng)有選手搶答成功時(shí)或倒計(jì)時(shí)到十秒后,喇叭鳴響。
三 總體電路RTL視圖:
?
3,1各種模塊的VHDL文本輸入語言
1編碼器
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ?bm ?IS?
PORT(a,b,c,d,:IN ?STD_LOGIC;
? ? ?RST1 :IN ?STD_LOGIC;
M: OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
END bm;
ARCHITECTURE one OF bm IS
? ?SIGNAL ?M1: STD_LOGIC_VECTOR(1 ?TO ?8);
? BEGIN
? ? ?M1<= a&b&c&d;
? ?PROCESS(M1,RST1)
? ? ? BEGIN
? ? ? ?IF RST1='0' THEN
? ? ? ? ?M<="0000";
? ? ? ?ELSE
? ? ? ?CASE M1 IS
?WHEN "01111111" =>M<="0001";
WHEN "10111111" =>M<="0010";
?WHEN "11011111" =>M<="0011";
WHEN "11101111" =>M<="0100";
WHEN OTHERS =>M<="0000";
? ? ?END CASE;
? ?END IF;
END PROCESS;
END one;
2.鎖存器
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY sc IS
PORT(S:IN STD_LOGIC_VECTOR(3 DOWNTO 0);
RST2,EN2:IN STD_LOGIC;
C:OUT STD_LOGIC_VECTOR(3 DOWNTO 0) );
END sc;
ARCHITECTURE TWO OF sc IS
BEGIN
?PROCESS(S,EN2,RST2)
? ?BEGIN
? ? ? ?IF ?RST2='0' THEN
? ? ? ?C<="0000";
ELSE IF EN2='1' THEN
? ?C<=S;
END IF;
END IF;
? END PROCESS;
END TWO;
3.譯碼器
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY ym IS
PORT(Y:IN STD_LOGIC_VECTOR(3 DOWNTO 0);
? ? ? LED1:OUT STD_LOGIC_VECTOR(7 DOWNTO 1));
END ym ;
ARCHITECTURE THREE OF ym IS
? BEGIN ?
PROCESS(Y)
BEGIN ?
?CASE Y IS
?WHEN "0001"=>LED1<="0000110";
WHEN "0010"=>LED1<="1011011";
WHEN "0011"=>LED1<="1001111";
WHEN "0100"=>LED1<="1100110";
WHEN OTHERS=>LED1<="0111111";
END CASE;
? END PROCESS;
END THREE;
4.報(bào)警器
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY bj IS
? ?PORT(BC,BS:IN STD_LOGIC_VECTOR(3 DOWNTO 0);
LA:OUT STD_LOGIC);
END bj ;
ARCHITECTURE FOUR OF bj IS
? ?BEGIN
PROCESS(BC,BS)
? BEGIN
? ?IF (((BC(0)OR BC(1) OR BC(2) OR BC(3))='1') OR BS="0000") THEN
? ? ? ? ?LA<='1';
? ?ELSE
? ? ? ? ?LA<='0';
? ? END IF;
? END PROCESS;
END FOUR;
5.分頻器
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY fp IS
PORT(CLK1,RST3:IN STD_LOGIC;
? ? ? ? ?S:OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
END fp;
ARCHITECTURE FIVE OF fp IS
? ?BEGIN
?PROCESS(CLK1,RST3)
? ?VARIABLE S1: STD_LOGIC_VECTOR(3 DOWNTO 0);
? ?VARIABLE cnt:INTEGER RANGE 0 TO 29999999;
?? ?BEGIN
IF RST3='0' THEN S1:="1111";?
? ?ELSE IF (CLK1'EVENT AND CLK1='1') ?THEN
? ? ? ?IF cnt<29999999 THEN
?? ??? ? S1:=S1-1;
? ? ?END IF;
END IF;
? ?END IF;
S<=S1;
END PROCESS;
END FIVE;
6.顯示器
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY xs IS
PORT(X:IN STD_LOGIC_VECTOR(3 DOWNTO 0);
? ? ? LED2:OUT STD_LOGIC_VECTOR(7 DOWNTO 1));
END xs;
ARCHITECTURE SIX OF xs IS
? BEGIN ?
PROCESS(X)
BEGIN ?
?CASE X IS
?WHEN "0001"=>LED2<="0000110";
WHEN "0010"=>LED2<="1011011";
WHEN "0011"=>LED2<="1001111";
WHEN "0100"=>LED2<="1100110";
WHEN "0101"=>LED2<="1101101";
WHEN "0110"=>LED2<="1111101";
WHEN "0111"=>LED2<="0000111";
WHEN "1000"=>LED2<="1111111";
WHEN "1001"=>LED2<="1101111";
WHEN OTHERS=>LED2<="0111111";
END CASE;
? END PROCESS;
END SIX;
7.頂層文件
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY qdq IS
PORT(Q1,Q2,Q3,Q4:IN STD_LOGIC;
? ? ?RST,CLK: IN STD_LOGIC;
LED1,LED2:OUT STD_LOGIC_VECTOR(7 DOWNTO 1);
LA:OUT STD_LOGIC);
END qdq;
ARCHITECTURE SEVEN OF qdq IS
COMPONENT ?bm ?
PORT(a,c,c,d:IN ?STD_LOGIC;
? ? ?RST1:IN ?STD_LOGIC;
? ? ?M:OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
END COMPONENT;
COMPONENT sc?
PORT(S:IN STD_LOGIC_VECTOR(3 DOWNTO 0);
RST2,EN2:IN STD_LOGIC;
C:OUT STD_LOGIC_VECTOR(3 DOWNTO 0) );
END COMPONENT;
COMPONENT ym?
PORT(Y:IN STD_LOGIC_VECTOR(3 DOWNTO 0);
? ? ? LED1:OUT STD_LOGIC_VECTOR(7 DOWNTO 1));
END COMPONENT;
COMPONENT bj?
PORT(BC,BS:IN STD_LOGIC_VECTOR(3 DOWNTO 0);
LA:OUT STD_LOGIC);
END COMPONENT;
COMPONENT fp?
PORT(CLK1,RST3:IN STD_LOGIC;
? ? ? ? ? S:OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
END COMPONENT;
COMPONENT xs?
PORT(X:IN STD_LOGIC_VECTOR(3 DOWNTO 0);
? ? ? LED2:OUT STD_LOGIC_VECTOR(7 DOWNTO 1));
END COMPONENT;
SIGNAL A, C: STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL B: STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL D:STD_LOGIC;
SIGNAL E:STD_LOGIC;
SIGNAL F:STD_LOGIC;
BEGIN
D<=NOT(B(0) OR B(1) OR B(2) OR B(3));
E<=C(0) OR C(1) OR C(2) OR C(3);
F<=D AND E;
U1: bm PORT MAP(Q1,Q2,Q3,Q4,RST,A);
U2:sc PORT MAP(A,RST,F,B);
U3:ym PORT MAP(B,LED1);
U4:bj PORT MAP(B,C,LA);
U5:fp PORT MAP(CLK,RST,D, C);
U6:xs PORT MAP(C,LED2);
END SEVEN;
總結(jié)
- 上一篇: conda 环境中 一些包安装问题总结
- 下一篇: GitHub断供危机来了!权威解读程序员