实验六计数器与序列检测器的仿真
一、实验目的:
实现计数器与序列检测器的仿真。
二、实验内容
1. 用VHDL语言设计一个按余3码顺序计数的计数器,并进行仿真与分析;
2.用VHDL语言设计一个“1101001”位串的序列检测器,并仿真与分析。
三、实验步骤。
(一)、计数器与序列检测器的逻辑图。
1.计数器:
2.序列检测器:
(二)、计数器与序列检测器的VHDL。
1.计数器:
library ieee;
use ieee.std_logic_11.all; use ieee.std_logic_unsigned.all; entity yusanjishuqi is
port(clk,clr,en:in std_logic;
a:out std_logic_vector(3 downto 0); cout:out std_logic); end yusanjishuqi;
architecture bhv of yusanjishuqi is signal b:std_logic_vector(3 downto 0); begin
process(clk,clr,en,b) begin
if(clr='1') then b<=\"0011\";
elsif(clk'event and clk='1') then if(en='1') then if(b<\"1100\") then b<=b+1; else
b<=\"0011\"; end if;
end if; end if;
if(b=\"1100\") then cout<='1'; else cout<='0'; end if; a<=b;
end process; end bhv;
2.序列检测器: library ieee;
use ieee.std_logic_11.all; entity xuliejianceqi is
port(clk,reset,d:in std_logic; z: out std_logic); end xuliejianceqi;
architecture bhv of xuliejianceqi is type state_type is(s0,s1,s2,s3,s4,s5,s6); signal state: state_type; begin process(clk,reset) begin
if reset= '1' then state<=s0;
elsif (clk'event and clk ='1') then case state is when s0 => if d='1' then state<=s1; else
state<=s0; end if; when s1=>
if d='1' then state<=s2; else
state<=s0; end if; when s2=>
if d='0' then state<=s3; else
state<=s2; end if;
when s3=>
if d='1' then state<=s4; else
state<=s0; end if; when s4=>
if d='0' then state<=s5; else
state<=s2; end if; when s5=>
if d='0' then state<=s6; else
state<=s1; end if; when s6=>
if d='1' then state<=s0; else
state<=s0; end if; end case; end if;
end process; process(state,d) begin
case state is when s6=>
if d='1' then z<='1'; else
z<='0'; end if; when others=> z<='0'; end case; end process; end bhv;
四、实验仿真结果。
1.计数器:
2.序列检测器:
五、总结。
时序电路确实的VHDL确实麻烦很多,虽说只是增加个process,但是如果没有很好的理解状态图状态表,后边儿是很难进行的。还需要能把每一个process准确的分开,也要正确的连接。