Verilog FSM和模块实例化

时间:2015-02-18 00:37:39

标签: verilog hdl state-machine

这个有限状态机用作数据路径的控制器,该数据路径包含计算两个4位数字的GCD所需的运算符。我对这种语言比较陌生,我知道这个问题可能是一个缺少的半冒号,也可能是我的声明,但我无法弄清楚问题是什么。我一直在收到错误:

错误:HDLC编译器:806 - “D:/ Xilinx Stuff / GCD / GCD FSM.v”第44行:“if”附近的语法错误。 错误:HDLC编译器:806 - “D:/ Xilinx Stuff / GCD / GCD FSM.v”第60行:“=”附近的语法错误。 错误:HDLCompiler:806 - “D:/ Xilinx Stuff / GCD / GCD FSM.v”第64行:“=”附近的语法错误。 错误:HDLCompiler:806 - “D:/ Xilinx Stuff / GCD / GCD FSM.v”第68行:“;”附近的语法错误。

我也对所有关于逻辑的提示持开放态度,FSM的代码如下所示:

module GCD_FSM(clk,data_in,reset,data_out,x_in,y_in,gcd_out,xgty,xlty,xequaly,go_in,xnew,ynew);

    input   clk, data_in, reset,go_in;
    input reg[3:0] x_in,y_in,gcd_out;
    output reg [1:0] data_out;
    reg [3:0] x,y;
    output reg[3:0] xnew,ynew;
    output reg xgty,xlty,xequaly,cleango;

    // Declare state register
    reg [1:0]state;

    // Declare states
    parameter S0 = 0, S1 = 1, S2 = 2, S3 = 3, S4 =4;

    /* Output depends only on the state
    always @ (state) begin
        case (state)
            S0:
                data_out = 2'b01;
            S1:
                data_out = 2'b10;
            S2:
                data_out = 2'b11;
            S3:
                data_out = 2'b00;
            default:
                data_out = 2'b00;
        endcase
    end
    */


    // Determine the next state
    always @ (posedge clk or posedge reset) begin
        if (reset)
            state <= S0;
        else
            case (state)
                S0:
                    debounce start(.clock(clk),.noisy(go_in),.clean(cleango));
                    if (cleango)
                        state <= S1;
                    else
                        state <= S0;
                S1:
                    state <= S2;
                S2:

                    if (xlty)
                        state <= S3;
                    else if(xgty)
                        state <= S4;
                    else if(xequaly)
                        state <= S5;
                S3:
                    ripple_carry_adder_subtractor ysubx(.S(ynew),.C(carry),.V(overflow),.A(y),.B(x),.Op(1));
                    y = ynew;
                    state <= S2;
                S4:
                    ripple_carry_adder_subtractor xsuby(.S(xnew),.C(carry),.V(overflow),.A(x),.B(y),.Op(1));
                    x = xnew;
                    state <= S2;
                S5:
                    gcd_out = x;
                    state <= S0;

            endcase
    end

endmodule

1 个答案:

答案 0 :(得分:1)

我发现了一些错误:

  • 第3行,您最后错过了;output reg[3:0] gcd_out
  • 未定义变量go_incleango
  • 未定义模块去抖动