Verilog switch case 中的“非法引用内存”

问题描述

我正在尝试为作业编写有限状态机。但是,我不明白我的模块代码有什么问题。我收到错误:

错误 VCP5221“非法引用内存:st。” “设计.sv”77 5

当我尝试合成时。我想我要么误解了 Verilog 中如何使用 switch-case,要么我试图在 switch-case 中进行非法赋值,但我不知道如何找到它。

//Code here

module MooreFSM(
  input clk,input in,output out
);
  
  reg state[2:0];
  reg sel[2:0];
  reg o;
  assign out = o;
  
  initial begin
    state <= 3'b000;
    o <= 1'b0;
  end
  
  always@(negedge clk) begin
    state <= sel;
  end
  
  always@(posedge clk) begin
    case(state)
      3'b000: begin
        if(in == 1'b0) begin
          sel <= 3'b010;
          o <= 1'b0;
        end
        else if(in == 1'b1) begin
          sel <= 3'b001;
          o <= 1'b0;
        end
      end
      3'b001: begin
        if(in == 1'b0) begin
          sel <= 3'b000;
          o <= 1'b0;
        end
        else if(in == 1'b1) begin
          state <= 3'b011;
          o <= 1'b0;
        end
      end
      3'b010: begin
        if(in == 1'b0) begin
          sel <= 3'b100;
          o <= 1'b0;
        end
        else if(in == 1'b1) begin
          sel <= 3'b000;
          o <= 1'b0;
        end
      end
      3'b011: begin
        if(in == 1'b0) begin
          sel <= 3'b000;
          o <= 1'b1;
        end
        else if(in == 1'b1) begin
          sel <= 3'b011;
          o <= 1'b1;
        end
      end
      3'b100: begin
        if(in == 1'b0) begin
          sel <= 3'b100;
          o <= 1'b1;
        end
        else if(in == 1'b1) begin
          sel <= 3'b000;
          o <= 1'b1;
        end
      end
      default: begin
        sel <= 3'b000;
        o <= 1'b0;
      end
    endcase
  end
endmodule

请帮我找出问题所在,或者我是否需要使用不同的方法来合成多路复用器。

解决方法

我想当你把

else if(in == 1'b1) begin
  state <= 3'b011;
  o <= 1'b0;
end

你可能想写

else if(in == 1'b1) begin
  sel <= 3'b011;
  o <= 1'b0;
end

通过将 state 作为仅在此 switch 语句的一种情况下分配的内容,您隐含地要求在其他所有情况下都将其锁回,这与您明确将其设置为上面的触发器相冲突.

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...