问题描述
我正在尝试为作业编写有限状态机。但是,我不明白我的模块代码有什么问题。我收到错误:
错误 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 语句的一种情况下分配的内容,您隐含地要求在其他所有情况下都将其锁回,这与您明确将其设置为上面的触发器相冲突.