【问题标题】:VHDL fsm error - near "when": (vcom-1576) expecting ENDVHDL fsm 错误 - 在“何时”附近:(vcom-1576) 期待 END
【发布时间】:2017-06-10 00:01:58
【问题描述】:

我正在尝试使用 modelsim 在 vhdl 中创建 fsm,但是当我尝试编译我的代码时出现此错误

** 错误:C:/Users/manor/Desktop/ldh/mult_fsm.vhd(34): near "when": (vcom-1576) 期待 END。

** 错误:C:/Users/manor/Desktop/ldh/mult_fsm.vhd(60): near "when": (vcom-1576) 期待 END。

** 错误:C:/Users/manor/Desktop/ldh/mult_fsm.vhd(72): near "else": (vcom-1576) 期待 END。

这是我的代码

library ieee;
use ieee.std_logic_1164.all;

entity mult_fsm is
    port(ck,adx,m: in std_logic;
        adsh,sh,cm,mdone: out std_logic);
end entity mult_fsm;

architecture ideal of mult_fsm is
    type StateType is (S0, S1, S2, S3, S4);
    signal CurrentState, NextState: StateType;
begin
    NS_CS: process( ck)
    begin
    if ck'event and ck='1' then
        case CurrentState is
            when S0=>
            if (adx='0') then
                NextState <= S0;
            else
                NextState <= S1;
            end if;

            when S1=>
                NextState <= S2;

            when S2=>
            if (m='1') then
                NextState<=S3;
            else if (m='0') then
                NextState<=S2;
            end if;
            
            when S3=>
                NextState <= S4;

            when S4=>
                NextState <= S0;

        end case;
    end if;
    end process NS_CS;

    OL: process (CurrentState)
    begin
        case CurrentState is
            when S0=>
            if (adx = '0') then
                adsh<='0';
                sh<='0';
                cm<='0';
                mdone<='0';
            else if (adx = '1') then
                if (m='1') then
                    adsh<='1';
                else if (m='0') then
                    sh<='1';
                end if;
            end if;
            when S1=>
            if (m='1') then
                adsh<='1';
            else if (m='0') then
                sh<='1';
            end if;
            when S2=>
            if (m='0') then
                adsh<='0';
                sh<='0';
                cm<='0';
                mdone<='0';
            else if (m='1') then
                adsh<='1';
            end if;
            when S3=>
            if (m='0') then
                sh='1';
            else if (m='1') then
                cm<='1';
                adsh<='1';
            end if;
            when S4=>
                mdone<='1';
        end case;

    end process OL;

end architecture ideal;

我尝试自己修复代码,但我无法弄清楚它有什么问题。

【问题讨论】:

    标签: vhdl modelsim


    【解决方案1】:

    将您的else ifs 替换为elsifs。

    在 VHDL 中,每个if 都需要一个end if。如果你写

    if ... then 
      ...
    else if ... then
    

    您需要两个 end ifs - 每个 if 一个:

    if ... then
      ...
    else IF ... THEN
           ...
         END IF;
    end if;
    

    VHDL 有一个elsif 语句。这不会启动一个新的if 语句,而是它遵循的if 语句的一部分。如果你替换上例中的else IF,你只需要一个end if

    if ... then
      ...
    elsif ... then
      ...
    end if;
    

    【讨论】:

      【解决方案2】:

      看下面的代码:

          if (m='1') then
            NextState<=S3;
          else if (m='0') then
            NextState<=S2;
          end if;
      

      我认为您的意思是 elsif 而不是 else if。或者,由于mstd_logic,您可以将此块简化为:

          if (m='1') then
            NextState<=S3;
          else
            NextState<=S2;
          end if;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多