1
\$\begingroup\$
/* 
 * Do not change Module name 
*/
module stimulus;
  reg[4:0] A, B;
  wire [9:0] Product;
  reg clk, start;
  booth_multiplier m1(A, B, Product, clk, start);
  
  initial
    $monitor($time, "A = %b, B = %b, Product = %b", A, B, Product);

  initial 
  begin 
    clk = 1'b0;
     start = 1'b1;
    #1000 $finish;
  end

  always #50 clk = ~clk;

  initial 
  begin 
     A = 9; B = 7;  
  end    
endmodule



module booth_multiplier(A, B, Product, clk, start);
  input signed [4:0] A, B;
  output signed [9:0] Product;
  input clk, start;

  // Initialize internal signals
  wire clr, ld, addsub, rsh, pld, done, incr;
  wire [1:0] temp;
  wire [2:0] count0;

  // Add a $display statement to debug
  initial $display("Booth Multiplier Simulation Start");

  // ...

  // Add more $display statements if needed

  // Instances of submodules
  data_path data1(clk, clr, ld, addsub, rsh, pld, done, count0, A, B, temp, Product, incr);
  controller con1(clr, rsh, addsub, pld, ld, clk, count0, start, temp, done, incr);
  always @(posedge clk)
    $display("Booth Multiplier: A=%b, B=%b, Product=%b, clr=%b, ld=%b, addsub=%b, rsh=%b, pld=%b, done=%b, incr=%b",
              A, B, Product, clr, ld, addsub, rsh, pld, done, incr);
     always @(posedge clk)
    $display("Booth Multiplier: count0=%b, temp=%b", count0, temp);
endmodule


module data_path(clk, clr, ld, addsub, rsh, pld, done, count1, A, B, temp, Product, incr);
  input [4:0] A, B;
  input clk, clr, ld, pld, rsh, done, incr;
  output addsub;
  wire [10:0] Acc, data_out;
  output [1:0] temp;
  output [2:0] count1;
  output [9:0] Product;
  wire [4:0] sum1, M;
  
  PIPO1 p1(M, A, clk, ld, clr); // load multiplicand
  PIPO1 p2(Acc[5:1], B, clk, ld, clr); // load multiplier
  PIPO1 p3(Acc[10:6], sum1, clk, ld, clr); // accumulator
 //d_ff d1(Acc[0], 0, clk, clr); // q0
  counter c2(count1, incr, clr, clk);
  add_sub as1(sum1, M, Acc[10:6], addsub);
  right_shift r1(rsh, clr, clk, data_out, Acc, ld);
  PIPO p4(Product, data_out[10:1], clk, pld, clr);
  comparator c1(Acc[1:0], addsub, clk, clr);
endmodule

module controller(clr, Rsh, As, pld, ld, clk, count2, start, temp, Done, incr);
  input clk, start;
  input [2:0] count2;
  input [1:0] temp;
  output reg clr, Rsh, As, pld, ld, Done, incr;
  reg [2:0] state;
  parameter init = 3'b000, load = 3'b001, idle = 3'b010, Rshift = 3'b011, done = 3'b100;

  always @(posedge clk)
  begin
    case (state)
      init : if (start) state <= load; else state <= init;
      load : state <= idle;
      idle : state <= Rshift;
      Rshift : #5 if (count2 > 5) state <= done;
                  else state <= idle;
      done : state <= done;
    endcase
  end
  
  always @(state)
  begin
    case (state)
      init : begin  clr <= 1; pld <= 0; ld <= 0; As <= 0; Done <= 0; Rsh <= 0; incr <= 0;
      end
      load : begin  clr <= 0; pld <= 0; ld <= 1; As <= 0; Done <= 0; Rsh <= 0; incr <= 0; 
      end
      idle : begin  pld <= 0; clr <= 0; ld <= 0; Done <= 0; Rsh <= 0; incr <= 0;
          if (temp == 2'b01) As <= 0; else if (temp == 2'b10) As <= 1;
          end
      Rshift : begin  clr <= 0; pld <= 0; ld <= 0; As <= 0; Done <= 0; Rsh <= 1; incr <= 1; end
      done : begin  clr <= 0; pld <= 1; ld <= 0; As <= 0; Done <= 1; Rsh <= 0; incr <= 0; end
    endcase
  end
endmodule

//-----------------------------------------------------------------------------

// Blocks in architecture

module counter(count1, incr, clr, clk);
  input incr, clr, clk;
  output reg [2:0] count1;
  
  always @(posedge clk)
    begin
      if (clr) count1 <= 3'b0;
      else if (incr) count1 <= count1 + 3'b1;
    end
endmodule

module add_sub(out, in1, in2, addsub);
  input signed [4:0] in1, in2;
  input addsub;
  output reg signed [4:0] out;
  
  always @(*)
    begin
      if (addsub == 0) 
        out <= in1 + in2;
      else 
        out <= in1 - in2;
    end
endmodule

module d_ff(d, q, clk, clr);
  input d, clk, clr;
  output reg q;
  
  always @(posedge clk)
    if (clr) q <= 0;
    else q <= d;
endmodule

module right_shift(rsh, clr, clk, data_out, data_in,load);
  input clk, clr, rsh, load;
  input [10:0] data_in;
  output reg [10:0] data_out;
  always @(posedge clk)
    begin
      if (clr) data_out <= 0;
      else if(load) data_out <= data_in;
      else if (rsh)
      begin
           data_out <= {data_in[10], data_in[10:1]};
        end
    end
endmodule

module PIPO(data_out, data_in, clk, load, clr);
  input [9:0] data_in;
  input load, clk, clr;
  output reg [9:0] data_out;
  
  always @(posedge clk)
   if(clr) data_out <= 0;
    else if (load) data_out <= data_in[9:0];
endmodule

module PIPO1(data_out, data_in, clk, load, clr);
  input [4:0] data_in;
  input load, clk,clr;
  output reg [4:0] data_out;
  
  always @(posedge clk)
  if(clr) data_out <= 0;
    else if (load) data_out <= data_in;
endmodule

module comparator(in, as, clk, clr);
  input [1:0] in;
  output reg as;
  input clk, clr;
  
  always @(posedge clk or posedge clr)
    if (clr) 
      as <= 0;
    else if (in == 2'b01) 
      as <= 0;
    else if (in == 2'b10) 
      as <= 1; 
endmodule

output - Booth Multiplier: A=01001, B=00111, Product=xxxxxxxxxx, clr=x, ld=x, addsub=x, rsh=x, pld=x, done=x, incr=x

\$\endgroup\$
2
  • \$\begingroup\$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. \$\endgroup\$
    – Community Bot
    Commented Nov 26, 2023 at 17:52
  • \$\begingroup\$ may i know why do we get unknown states in output \$\endgroup\$
    – user356452
    Commented Nov 26, 2023 at 18:21

2 Answers 2

1
\$\begingroup\$

When I run your simulation and trace the unknown outputs back to their sources, I see that the controller module has several signals which are unknown: As, ld, state. One way to initialize them for simulation is as follows:

  output reg clr, Rsh, As=0, pld, ld=0, Done, incr;
  reg [2:0] state=0;

This clears up some of the internal unknown signals.

You should also consider adding a reset signal to the top-level of the design and propagating it throughout the submodules.

Another problem is that the comparator has an undriven input signal in: bit in[0] is undriven because Acc[0] is undriven. You need to decide how to drive that input.

I recommend that you take a different approach to this design. You should prove that each module works as desired on its own before you start connecting them all up together. You can create a small testbench for each module, then start connecting modules together and running simulations to prove they work together.

If you are not already doing so, you should also debug the simulation using a waveform viewer, instead of only relying on $display statements.

\$\endgroup\$
0
\$\begingroup\$

Looking in the controller module I can't see how state is given an initial value. I think that could then cause the unknown values in the other outputs.

Admittedly this based upon only reading the code, rather than attempting to run it in a simulator.

Suggest the value of state is monitored in the simulation for further investigation.

\$\endgroup\$
0

Your Answer

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