switch-statement - Verilog switch 案例中的“非法引用内存”
问题描述
我正在尝试为作业编写有限状态机。但是,我不明白我的模块代码有什么问题。我得到错误:
错误 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 语句的一种情况下分配一些东西,你隐含地要求它在所有其他情况下都被锁定,这与你明确地使它成为上面的失败相冲突。
推荐阅读
- python - 概率贝叶斯神经网络 ValueError:层 model_39 需要 3 个输入,但它接收到 1 个输入张量
- javascript - 如何使用 JavaScript 检测 Chrome 浏览器窗口何时关闭?
- c# - 如何使用依赖注入在启动时启动自定义服务
- laravel-8 - 从 Laravel 8 中的 SQL 查询中查找列名和数据类型
- r - 用于检测的连续变量和用于密度估计的分类变量?
- c# - 无法将 void 转换为 asp.netcore 中的对象
- python - 比较三个tsv文件以检查相似项并更新原始文件中的差异
- c++ - 模板数组产生一个双倍大小的数组
- sql - SQL 连接中的情况不会在第一次成功匹配时停止
- python - 在 pytest 中使用 record_testsuite_property 夹具时如何访问测试套件属性?