4

I am trying to implement Booth's algorithm (a finite state machine implementation) for a Xilinx FPGA. Basically, at the start signal I will initialize my auxiliary regs, then I will go in state 0, where I will start to compare the 2 bits and do the shifting. I will repeat this until state 4 is reached.

assign Result = P[8:1];

always@(posedge clk or negedge start)
    if(start == 1)
    begin
            // initialize with start values
        state <= 3'd0;
    end

    else
    if(state == 3'd0 || state == 3'd1 || state == 3'd2 || state == 3'd3)
    begin
       // compare bits and shift data
    end
endmodule

Test module

clk = 0;
a = 4'b0011;
b = 4'b0011;
b = ~b+1;
start = 1;
#10;
start = 0;

clk becomes ~clk after #5 time units.

I do not own an FPGA, so I cannot test the program (I'll have to test it later at class).

I am testing it with Icarus. The problem is that the auxiliary regs are not initialized before the first posedge of the clock.

What can I do in order to properly initialize my auxiliary variables and to maintain the code to be synthesizable? I've tried using a for loop and an initial begin, and the simulation works fine, but it will not work on the FPGA (because I have to use #delays).

3
  • 1
    The easiest way would be to add reset signal and initialize regs when reset == 1 (or 0 for rst_n). Commented May 17, 2014 at 15:39
  • What are the "auxiliary regs" which are not initialized? state? Commented May 17, 2014 at 19:33
  • Solved it! The "auxiliary regs" that were not initialized were the ones were I hold the intermediate results, (the ones were I concat 0000 with 'a' for example) or 2's complement for number a. Commented May 17, 2014 at 19:35

1 Answer 1

3

For ASIC it is best to use active low resets to set initial values however for FPGAs it is common just to set initial values in an initial blocks.

initial begin
  state = 'd0 ;
end

always@(posedge clk) begin
  if(state == 3'd0 || state == 3'd1 || state == 3'd2 || state == 3'd3)begin
    // compare bits and shift data
    state <= 3'd4 ;
  end
endmodule

Using active low resets.

always@(posedge clk or negedge rst_n) begin
  if (~rst_n) begin
    state <= 'd0 ;
  end 
  else begin
    if(state == 3'd0 || state == 3'd1 || state == 3'd2 || state == 3'd3)begin
      // compare bits and shift data
      state <= 3'd4 ;
    end
  end
endmodule
Sign up to request clarification or add additional context in comments.

1 Comment

Here is the reason why active resets are used in ASIC groups.google.com/forum/#!topic/comp.lang.verilog/WI1Ob8C0dzg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.