我被要求使用 one-hot 编码创建一个有限状态机,它将检测输入 w 上的四个 1 或 0 的序列。我已经使用 case 语句编写了代码,但我还必须通过提供逻辑表达式作为 9 个触发器的输入来完成它。我在 z 上没有得到正确的输出,我也不太明白为什么。
到目前为止,我已经为 D 触发器编写了以下代码
library ieee;
use ieee.std_logic_1164.all;
entity dflipflop is
port (D, clk, reset: in std_logic;
Q: out std_logic);
end dflipflop;
architecture behavior of dflipflop is
begin
process(clk)
begin
if reset <= '0' then
Q <= '0';
elsif rising_edge(clk) then
Q <= D;
end if;
end process;
end behavior;
然后我把它作为我的代码的其余部分,这就是我认为问题所在。
library ieee;
use ieee.std_logic_1164.all;
entity part1 is
port (clk, w, reset : in std_logic;
z: out std_logic);
end part1;
architecture behavior of part1 is
component dflipflop
port (D, clk, reset: in std_logic;
Q: out std_logic);
end component;
signal A, B, C, D, E, F, G, H, I: std_logic;
signal Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9: std_logic;
dff1: dflipflop port map (clk=>clk, reset=>reset, D=>Y1, Q=>A);
dff2: dflipflop port map (clk=>clk, reset=>reset, D=>Y2, Q=>B);
dff3: dflipflop port map (clk=>clk, reset=>reset, D=>Y3, Q=>C);
dff4: dflipflop port map (clk=>clk, reset=>reset, D=>Y4, Q=>D);
dff5: dflipflop port map (clk=>clk, reset=>reset, D=>Y5, Q=>E);
dff6: dflipflop port map (clk=>clk, reset=>reset, D=>Y6, Q=>F);
dff7: dflipflop port map (clk=>clk, reset=>reset, D=>Y7, Q=>G);
dff8: dflipflop port map (clk=>clk, reset=>reset, D=>Y8, Q=>H);
dff9: dflipflop port map (clk=>clk, reset=>reset, D=>Y9, Q=>I);
begin
process(clk);
begin
if rising_edge(clk) then
Y1 <= (((not w) and C) or ((not w) and G) or ((not w) and H) or ((not w) and I) or (w and B) or (w and D) or (w and E) or (w and F));
Y2 <= ((not w) and A);
Y3 <= (w and A);
Y4 <= ((not w) and B);
Y5 <= ((not w) and D);
Y6 <= (((not w) and E) or ((not w) and F));
Y7 <= (w and C);
Y8 <= (w and G);
Y9 <= ((w and H) or (w and I));
end if;
end process;
z <= (Y6 OR Y9);
end behavior;
任何人都可以就我可能做错的事情提供任何提示或见解吗?