【问题标题】:Error Number 10170 in Verilog using If/Else and Case StatementsVerilog 中使用 If/Else 和 Case 语句的错误号 10170
【发布时间】:2016-04-26 06:27:40
【问题描述】:

我正在尝试编译以下代码,但无论何时我都会收到错误:

'10170 Verilog HDL 语法错误在 FSM.v(9) 靠近文本“case”;期待一个操作数'

'10170 Verilog HDL 语法错误在 FSM.v(9) 靠近文本 ")";选择 "

'10170 Verilog HDL 语法错误在 FSM.v(11) 靠近文本“4”;期待“结束”'

module FSM (in0, in1, in2, in3, S, out0, out1, out2, out3); 
input in0, in1, in2, in3, S;
output out0, out1, out2, out3;
reg out0, out1, out2, out3;
always @(in0 or in1 or in2 or in3 or S)
begin
    if(S == 0) begin
    {
        case({in3, in2, in1, in0})
            4'b0000: {out3, out2, out1, out0} = 4'b0000; //0->0
            4'b0001: {out3, out2, out1, out0} = 4'b0011; //1->3
            4'b0010: {out3, out2, out1, out0} = 4'b0110; //2->6
            4'b0011: {out3, out2, out1, out0} = 4'b1001; //3->9
            4'b0100: {out3, out2, out1, out0} = 4'b0010; //4->2
            4'b0101: {out3, out2, out1, out0} = 4'b0101; //5->5
            4'b0110: {out3, out2, out1, out0} = 4'b1000; //6->8
            4'b0111: {out3, out2, out1, out0} = 4'b0001; //7->1
            4'b1000: {out3, out2, out1, out0} = 4'b0100; //8->4
            4'b1001: {out3, out2, out1, out0} = 4'b0111; //9->7
        endcase
    }
    end
    else begin
    {
        case({in3, in2, in1, in0})
            4'b0000: {out3, out2, out1, out0} = 4'b0111; //0->7
            4'b0001: {out3, out2, out1, out0} = 4'b1000; //1->8
            4'b0010: {out3, out2, out1, out0} = 4'b1001; //2->9
            4'b0011: {out3, out2, out1, out0} = 4'b0000; //3->0
            4'b0100: {out3, out2, out1, out0} = 4'b0001; //4->1
            4'b0101: {out3, out2, out1, out0} = 4'b0010; //5->2
            4'b0110: {out3, out2, out1, out0} = 4'b0011; //6->3
            4'b0111: {out3, out2, out1, out0} = 4'b0100; //7->4
            4'b1000: {out3, out2, out1, out0} = 4'b0101; //8->5
            4'b1001: {out3, out2, out1, out0} = 4'b0110; //9->6
        endcase
    }
    end
end
endmodule

在 case 语句中找到的每一行代码都会重复最后一个错误。如果有人知道我有什么问题以及如何解决这个问题,我将不胜感激!

【问题讨论】:

    标签: verilog


    【解决方案1】:

    删除if 条件后的花括号 ({..})。 Verilog 不是需要花括号的 C,在 Verilog 中,我们使用begin..end 表示多行程序语句。

    此外,对于自动灵敏度,建议使用always @(*)(或SystemVerilog 中的always_comb),而不是always @(in0 or in1 or in2 or in3 or S) 的手动灵敏度。

    您可能必须阅读详细的 Verilog 语法。请参阅Begin..end 链接和always sensitivity question 了解一些信息。请参阅 IEEE 1364-2001 获取 Verilog 和 IEEE 1800-2012 获取 SystemVerilog。

    【讨论】:

      【解决方案2】:

      我相信您不能将连接操作用作 case 语句或赋值左侧的参数。

      所以你需要做这样的事情:

      ....
      reg [3:0] inword, outword;
      begin
         inword = {in3, in2, in1, in0};
         if(S == 0) begin
            case (inword)
               4'b0000: outword = 4'b0000; //0->0
               ...
            endcase
         ...
         end
         out3 = outword[3];
         out2 = outword[2];
         out1 = outword[1];
         out0 = outword[0];      
      end;
      

      【讨论】:

      • case({in3, in2, in1, in0}){out3, out2, out1, out0} = ... 最好是合法的语法。使用中间变量来处理频繁连接的信号是减少打字的好主意。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-11
      • 2016-07-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多