【问题标题】:synchronous state machine VHDL同步状态机 VHDL
【发布时间】:2023-03-10 22:10:02
【问题描述】:

我正在尝试设计一个具有一个输入 X 和一个输出 Z 的同步状态机 仅当 x 没有时 z 才为 1。 1 的 mod 3=0 甚至没有。 0的 反正我准备好了状态图

我尝试在 xilinix 上测试代码并打印信号以跟踪它 但它没有像代码中所写的那样正确地从一个状态跳到另一个状态 任何帮助表示赞赏 这是链接中的输出谢谢

http://pastebin.com/14e5ZkX4

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity machine is
    Port ( X : in  STD_LOGIC;
            clk : in  STD_LOGIC;
           Z : out  STD_LOGIC);
end machine;

architecture Behavioral of machine is
signal state,nextstate  : integer range 0 to 5 := 0;
signal flag : integer range 0 to 5 := 0;

begin
--state 0 (even and mod3=0)
--state 1 (odd  and mod3=0)
--state 2 (even and mod3=1)
--state 3 (odd  and mod3=1)
--state 4 (even and mod3=2)
--state 5 (odd  and mod3=2)
sequence:process(CLK)
 begin

 if rising_edge(CLK) then

 report "prevstate"& integer'image(state);
 report "x" & STD_LOGIC'image(X);

 if X='0' then
 case state is
   when 0=>
     nextstate<= 1;

   when 1=>
      nextstate<= 0;

  when 2=>
     nextstate<= 3;

 when 3=>
  nextstate<= 2;

 when 4=>
  nextstate<= 5;

 when 5=>
  nextstate<= 4;

 end case;

 --if x=1
 else

 case state is
when 0=>
      flag<= 1;
  nextstate<= 2;

 when 1=>
  nextstate<= 3;

 when 2=>
  nextstate<= 4;

 when 3=>
  nextstate<= 5;

 when 4=>
  nextstate<= 0;

 when 5=>
  nextstate<= 1;

 end case;
 end if;
-- report "flag"&  integer'image(flag);

 report "next state"&  integer'image(nextstate);
 state<=nextstate;


if state=1 then
z<='1';
else
z<='0';
end if;
end if;
end process;

end Behavioral;

【问题讨论】:

    标签: vhdl synchronous xilinx


    【解决方案1】:

    似乎是一种奇怪的方式来实现你想要的......非常复杂,并且将两个独立的任务合并为一个,因此很难(通过肉眼)检查一切是否符合预期。我赞成按照您描述的问题来描述解决方案。

    分别跟踪这两个信息。下面的一些示例代码不完整,您必须将其组合成一个时钟进程并确保完成重置。

    有一个“偶数”标志,每次 X 为“0”时,切换它。确保将其重置为零。

    if x = '1' then 
       even := not even;
    end if;
    

    还有一个计数器,每次 X 为“1”时,将其递增。如果达到 3,则将其重置为零。并确保重置后从零开始!

    if x = '1' then
        counter := counter + 1;
        if counter = 3 then
           counter := 0;
        end if;
    end if;
    

    然后将两者结合起来产生输出:

    z <= '0';
    if counter = 0 and even = '1' then
      z <= '1';
    end if;
    

    【讨论】:

    • 感谢您的帮助我试试看
    【解决方案2】:

    嗯,我是 VHDL 新手,但我认为有一个大问题。 您尝试使用标准的顺序“编程”模式来描述硬件! 在描述硬件时,您必须记住,硬件是并发的。

    您的 FSM 不会有预期的行为,因为您没有记住这一点。 例如 nextstate 计算是在时钟进程中完成的,这没关系, 但是对于状态信号应该有一个并发的信号分配(在进程之外)。 nextstate-signals 的新值在同一进程周期中将不可用。 他们将在该过程完成后被分配。 (警告:仅适用于信号, 变量有一些不同的行为!)

    我认为一本好的 VHDL 书会教你基础知识...

    【讨论】:

      猜你喜欢
      • 2013-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-16
      • 1970-01-01
      • 1970-01-01
      • 2015-08-10
      • 1970-01-01
      相关资源
      最近更新 更多