【发布时间】:2022-01-26 23:03:59
【问题描述】:
当没有变化时,进程 2 会继续激活。我有一块板来测试我的代码,当我翻转时钟时状态会改变(我将时钟设置为按钮)。在我的代码中,只有当我翻转 Qin 时,状态才会改变。所以它没有做我希望它做的事情,我花了很多时间试图找出导致它的原因,但我做不到。请帮忙。
这是测试台图TESTBENCH GRAPH 如您所见,在图中,PS(present_state) 的输出是正确的,但在板中,它的输出不正确。我发现有一个东西很重要,我尝试在board上输出next_state,当我把Qin翻转到'1'时,状态显示为“001”,然后我将clk翻转到'1',状态变成了“010” ",这不应该发生。我希望这是一个重要的信息。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity VendingMechine is
Port ( Clk : in STD_LOGIC;
Reset : in STD_LOGIC;
Cr : in STD_LOGIC;
Qin : in STD_LOGIC;
S : in STD_LOGIC;
CB : in STD_LOGIC;
W : in STD_LOGIC;
CRo : out STD_LOGIC_VECTOR(1 DOWNTO 0);
Qo : out STD_LOGIC;
PS : out STD_LOGIC_VECTOR(2 DOWNTO 0);
Wo : out STD_LOGIC;
CBo : out STD_LOGIC;
So : out STD_LOGIC);
end VendingMechine;
architecture Behavioral of VendingMechine is
TYPE state IS(Idle, S1, S2, S3, Soda, Candy, Water);
Signal Next_State : state;
Signal Present_State : state := Idle;
begin
Process1:Process(clk, reset)
begin
if(reset = '1') THEN
Present_State <= Idle;
elsif rising_edge(clk) THEN Present_State <= Next_State;
end if;
end process;
Process2:Process(Qin, Present_State, Cr, S, w)
begin
Next_State <= Present_State;
CRo <= "00"; Qo <= '0'; PS <= "000"; Wo <= '0'; CBo <= '0'; So <= '0';
CASE Present_State IS
When Idle =>
PS <= "000";
if Qin='1' Then Next_State <= S1;
else Next_State <= Idle;
end if;
When S1 =>
PS <= "001";
if Qin='1' Then Next_State <= S2;
elsif Cr = '1' Then Cro <= "01"; Next_State <= Idle;
else Next_State <= S1;
end if;
When S2 =>
PS <= "010";
if Qin='1' Then Next_State <= S3;
elsif Cr = '1' Then CRo <="10"; Next_State <= Idle;
elsif S = '1' Then Next_State <= Soda;
elsif CB = '1' Then Next_State <= Candy;
else Next_State <= S2;
end if;
When S3 =>
PS <= "011";
if Cr = '1' Then CRo <= "11"; Next_State <= Idle;
elsif S = '1' Then Qo <= '1'; Next_State <= Soda;
elsif CB = '1' Then Qo <= '1'; Next_State <= Candy;
elsif W = '1' Then Next_State <= Water;
elsif Qin = '1' Then Qo <= '1';
else Next_State <= S3;
end if;
When Soda =>
PS <= "100";
So <= '1';
Next_State <= Idle;
When Candy =>
PS <= "101";
CBo <= '1';
Next_State <= Idle;
When Water =>
PS <= "110";
Wo <= '1';
Next_State <= Idle;
END CASE;
end process;
end Behavioral;
【问题讨论】:
-
我说错了,当我翻转 Qin, Cr, S, W 时它们的状态会改变
-
您能否提供一个测试平台来模拟您的代码并查看其行为?
-
我在我的线程中添加了测试台图,如果你愿意的话可以看看
-
我的意思是测试台的代码。您的波形仅显示顶层,但我认为要找到问题的原因需要更深入地了解 FSM。
-
对于未来,尽量使用描述性的信号名称。对我来说,它是不可读的。我想没有多少人会读到这样的代码。
标签: vhdl