为什么在56-61行出现错误?

时间:2019-02-13 05:45:56

标签: vhdl

我正在尝试为实验室中的状态机设置问题,并且尝试在Quartus中进行编译时始终收到错误消息

我尝试使用逗号,其他语句,但似乎没有任何作用

LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.All;

ENTITY SM_VHDL IS  -- Do not modify this entity statement!
  PORT(X       : IN STD_LOGIC_VECTOR(1 DOWNTO 0);
       RESETN,
       CLOCK   : IN  STD_LOGIC;
       Z       : OUT STD_LOGIC;
       Q       : OUT STD_LOGIC_VECTOR(1 DOWNTO 0)  );
END SM_VHDL;       -- Do not modify this entity statement!


ARCHITECTURE behavior of SM_VHDL IS
  TYPE STATE_TYPE IS (A, B, C);
  SIGNAL state : STATE_TYPE;

BEGIN
    PROCESS(CLOCK, RESETN)
      BEGIN
        IF RESETN = '0' THEN
          state <= A;
        ELSIF CLOCK'EVENT AND CLOCK = '1' THEN
          CASE state IS
            WHEN A =>
              CASE X IS
                WHEN "00"   =>
                                        state <= B;
                                WHEN "11"   =>
                                        state <= C;
                                WHEN OTHERS =>
                                        state <= A;
              END CASE;
            WHEN B =>
              CASE X IS
                WHEN "10"   =>
                                        state <= A;
                                WHEN "11"   =>
                                        state <= C;
                                WHEN OTHERS =>
                                        state <= B;
              END CASE;
            WHEN C =>
              CASE X IS
                WHEN "00"   =>
                                        state <= B;
                                WHEN "01"   =>
                                        state <= A;
                                WHEN OTHERS =>
                                        state <= C;
              END CASE;
          END CASE;
        END IF;
      END PROCESS;

    Z  <= '1' WHEN C;
                  '0' WHEN A;
                  '0' WHEN B;

    Q  <= "00" WHEN A;
                  "01" WHEN B;
                  "10" WHEN C;
                  "11" WHEN "-";

END behavior;

我需要它来编译

2 个答案:

答案 0 :(得分:0)

仅在布尔条件下使用。 A / B / C都是STATE_TYPE的文字。您需要通过对状态信号进行比较来创建布尔结果:

Z <=      '1' when STATE = C
     else '0' when STATE = A    -- This state not actually needed as a single ELSE would cover it
     else '0';

让我计算出Q的语句

答案 1 :(得分:-1)

对于多个问题,分配给ZQ的语法是错误的:

  • 分配前缺少WITH state SELECT ...
  • 使用“;”在when个部分之间,请改用,
  • 不能在最后"-"之后使用when(无关紧要),而应使用OTHERS

因此更新了代码:

WITH state SELECT Z <=
      '1' WHEN C,
      '0' WHEN A,
      '0' WHEN B;

WITH state SELECT Q <=
      "00" WHEN A,
      "01" WHEN B,
      "10" WHEN C,
      "11" WHEN OTHERS;

顺便说一句。迁移到Quartus之前,请考虑使用ModelSim Starter Edition作为编译器/仿真器,因为编译时间更快,消息通常更好。