用VHDL语言 设计4位序列检测器,当检测到“0110”时输出1,否则输出0。 哪位大神会啊,求助!
需要设计一个4位的串入并出移位寄存器和一个4位的二进制数值比较器:
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
ENTITY detector IS
GENERIC(m:std_logic_vector(3 downto 0):="0110");
PORT(clk,clr,s_in:IN std_logic; equal:OUT std_logic);
END detector;
ARCHITECTURE behavioral OF detecor IS
SIGNAL p:std_logic_vector(3 DOWNTO 0);
BEGIN
PROCESS(clk,clr)
BEGIN
IF clr='0' THEN
p<=(OTHERS => '0');
ELSIF rising_edge(clk) THEN
p <= s_in&p(3 DOWNTO 1);
END IF;
END PROCESS;
PROCESS(p)
BEGIN
IF p=m THEN
equal <='1';
ELSE
equal <='0';
END IF;
END PROCESS;
END behavioral;
仿真图如下:
这个状态图我不太懂,亲能大概介绍下吗
这是仿真图,不是状态图。
s_in是检测器的串行码输入端,输入的串行码是“010101011001010”,从15ns开始(由于clr信号在前10ns为有效,所以5ns处的clk信号上升沿没有做检测),每隔10ns检测一次,在95ns处检测到刚刚输入进来的4位串行码恰好是“0110”,所以输出信号equal为高电平。而到105ns处,又输入一个‘0’,4位串行码变成“1100”,因而输出信号equal变为低电平。
从仿真图可以看出,当串行码为“0110”时,输出信号equal为高电平,到达设计目标。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity jiance is
port(q:in std_logic_vector(3 downto 0);
s:out std_logic);
end jiance;
architecture behave of jiance is
signal y:std_logic;
begin
process(q,y)
begin
if q="0110" then
y<='1';
else
y<='0';
end if;
end process;
s<=y;
end behave;
编译正确;
仿真图:
就这样,ok了!
2014-01-10
.....
case(xx_state)
....
when s0 =>
if (seq_in = '0') then
xx_state <= s1;
else
xx_state <= s0;
end if;
seq_hit_o <= '0';
when s1 =>
if (seq_in = '1') then
xx_state <= s2;
else
xx_state <= s0;
end if;
seq_hit_o <= '0';
when s2 =>
if (seq_in = '1') then
xx_state <= s3;
else
xx_state <= s0;
end if;
seq_hit_o <= '0';
when s3 =>
if (seq_in = '0') then
seq_hit_o <= '1';
else
seq_hit_o <= '0';
end if;
xx_state <= s0;
end case;
.....