1
\$\begingroup\$

I've been trying to implement a 32-bit adder by instantiating two 16-bit adders. The code is compiling but failing some test cases. I don't know what is going wrong in this.

verilog code

module top_module(
 input [0:31] a,
 input [0:31] b,
 output [0:31] sum);
 add16 adder2 (.sum(sum[16:31]), .a(a[16:31]), .b(b[16:31]));
 add16 adder1 (.sum(sum[0:15]), .a(a[0:15]), .b(b[0:15]));
endmodule

This is the top level figure of the circuit:

block diagram

This is the output waveform:

timing diagram

asked Nov 20, 2019 at 21:26
\$\endgroup\$
5
  • 5
    \$\begingroup\$ Hint: your adder block should have a carry_out output and a carry_in input. \$\endgroup\$ Commented Nov 20, 2019 at 21:43
  • \$\begingroup\$ @ThePhoton can you please tell me how I can instantiate the cin and cout by looking at the above figure. \$\endgroup\$ Commented Nov 20, 2019 at 22:19
  • 1
    \$\begingroup\$ @animad93 no, that'd really rob you of any chance to learn. \$\endgroup\$ Commented Nov 20, 2019 at 22:40
  • \$\begingroup\$ @MarcusMüller. Okay \$\endgroup\$ Commented Nov 20, 2019 at 22:41
  • \$\begingroup\$ @animad93, you'd need to change the definition of the add16 module. \$\endgroup\$ Commented Nov 21, 2019 at 0:18

2 Answers 2

4
\$\begingroup\$

To chain smaller adders to make larger ones, you need the building-block adders to have carry in and carry out connections and you need to link those connections from one ader to the next.

Your diagram does not match your code, your diagram shows a carry connection, but your code does not.

You need to expand your add16 module to support carry in and out connections if it does not already do so, then connect them up as in the diagram you have drawn.

P.S. This is the sort of thing you would normally only do as an excercise, normally you just use the + operator to add things and let the synthesis tool sort it out.

answered Nov 20, 2019 at 22:53
\$\endgroup\$
0
\$\begingroup\$
module top_module(
 input [31:0] a,
 input [31:0] b,
 output [31:0] sum
);
 wire w1,cout;
 add16 a1(a[15:0],b[15:0],1'b0,sum[15:0],w1);
 add16 a2(a[31:16],b[31:16],w1,sum[31:16],cout);
endmodule
answered Aug 31, 2023 at 17:45
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.