2

在 VHDL 中,我可以更新使用相同变量的 case 语句中的变量吗?case 语句位于rising_edge(clk) 块内。谢谢你。

                    case State_var is
                    when "00" => 
                        if (Valid= '1') then
                            State_var := "00";
                        else
                            State_var := "01";
                        end if;
                    when "01" => 
                        if (Valid = '1') then
                            State_var := "00";
                        else
                            State_var := "10";
                        end if;
                    when "10" => 
                        if (Valid = '1') then
                            State_var := "11";
                        else
                            State_var := "01";
                        end if;
                    when "11" => 
                        if (Valid = '1') then
                            State_var := "11";
                        else
                            State_var := "10";
                        end if;
                    when others => null;
                end case;
4

3 回答 3

2

这样做没有问题 - 我一直这样做。

选择会根据case您当时的状态变量的值进行一次评估,并且您对状态变量所做的更新不会导致case语句立即转换到新状态。

于 2013-10-15T13:38:40.007 回答
2

是的你可以。你也可以只使用case语句:

process(...)
...
variable state: std_logic_vector(2 downto 0);
...
begin
...
state := Valid & State_var;
...
    case state is
            when "000"  => State_var := "01";
            when "001"  => State_var := "10";
            when "010"  => State_var := "01";
            when "011"  => State_var := "10";
            when "100"  => State_var := "00";
            when "101"  => State_var := "00";
            when others => State_var := "11";
    end case;
...
end process;
于 2013-10-18T22:22:44.013 回答
-2

为什么要为状态机使用变量?状态机应该是一个注册的信号,这就是状态机的意义所在。我不建议在这里使用变量。它会产生很多额外的组合解码逻辑,并且可能有一些竞争条件。

于 2013-10-14T17:20:48.993 回答