Designing a Two-Bit Adder Using Verilog Primitive Gates

In summary, the conversation discusses the process of designing a two-bit adder using verilog's primitive gates. The individual had previously implemented a two-bit adder using their own gates with nmos and pmos transistors, and now they are attempting to implement it using verilog's primitive gates. They have calculated the worst-case delays for each gate and have written the code for the adder and testbench. However, when simulating the adder, they are getting "z" for the outputs. After some troubleshooting, they realize that the order of the inputs and outputs for the primitive gates in verilog is different from what they had initially thought, and once they correct this, the "z"s disappear from the waveforms.
  • #1
Loulou21
2
0
designing a two-bit adder using verilog's primitive gates_I get "z" for my outputs

Hi,
I am trying to write verilog code for a two bit adder using verilog's primitive gates. I had implemented a two bit adder before...using gates I myself had implemented with nmos and pmos transistors, with delays of 3,4,5 (ns) for the nmos transistors and 5,6,7 (ns) for the pmos transistors. The worstcase delay I had calculated for the final adder was 31 ns.(I think we need to know this to get good results when simulating!) And I had instantiated this adder within a testbench. When I simulated my adder, I didn't have any problems.
Here are the code I used for the adder and the testbench of the adder:
(mxor/mnand2/mnand3/minverter used below, are my own gates that I had implemented and tested each; and they all worked fine!)
************************************************************
module madder(input a1,a0,b1,b0, output s2,s1,s0);

wire nanda0b0,notnanda0b0,xora1b1,nanda0b1b0,nanda1b1,nanda1a0b0;

mxor xorfors0(a0,b0,s0);

mnand2 nand2fors1(a0,b0,nanda0b0);
minverter inverterfors1(nanda0b0,notnanda0b0);
mxor xor1fors1(a1,b1,xora1b1);
mxor xor2fors1(xora1b1,notnanda0b0,s1);

mnand3 nand31fors2(a1,a0,b0,nanda1a0b0);
mnand2 nand2fors2(a1,b1,nanda1b1);
mnand3 nand32fors2(a0,b1,b0,nanda0b1b0);
mnand3 nand33fors2(nanda1a0b0,nanda1b1,nanda0b1b0,s2);

endmodule
*********************************************************
module madderTester();

reg ia1=1;
reg ia0=1;
reg ib1=1;
reg ib0=1;

wire ws2;
wire ws1;
wire ws0;

madder madderInstance(ia1,ia0,ib1,ib0,ws2,ws1,ws0);


initial repeat(50) #72 ia1=~ia1;

initial repeat(45) #61 ia0=~ia0;

initial repeat(40) #79 ib1=~ib1;

initial repeat(50) #67 ib0=~ib0;



endmodule
****************************************************************
Now I'm supposed to implement the same two bit adder using verilog's primitive gates.
I have calculated the worst-case delays of each gate (2-input nand/3-input nand/nor/xor/not), using the same numbers as above (3,4,5) and (5,6,7) for nmos and pmos transistors respectively. Using these time delays and the transistor implementation of each gate, I have calculated 0-to-1 and 1-to-0 delays for each of the above gates that I need in my two bit adder.
These are the delays I found: (the first delay is 0-to-1 delay and the second one is 1-to-0)
*for 2-input nand: 7; 10 (ns)
*for 3-input nand: 7; 15 (ns)
*for xor: 21; 24 (ns)
*for not: 7; 5 (ns)

Here's my code for the two bit adder using verilog's primitive gates (and the gate delays I calculated above):

*******************************************************
module madder(input a1,a0,b1,b0, output s2,s1,s0);

wire nanda0b0,notnanda0b0,xora1b1,nanda0b1b0,nanda1b1,nanda1a0b0;

xor #(21,24) xorfors0(a0,b0,s0);

nand #(7,10) nand2fors1(a0,b0,nanda0b0);
not #(7,5) inverterfors1(nanda0b0,notnanda0b0);
xor #(21,24) xor1fors1(a1,b1,xora1b1);
xor #(21,24) xor2fors1(xora1b1,notnanda0b0,s1);

nand #(7,15) nand31fors2(a1,a0,b0,nanda1a0b0);
nand #(7,10) nand2fors2(a1,b1,nanda1b1);
nand #(7,15) nand32fors2(a0,b1,b0,nanda0b1b0);
nand #(7,15) nand33fors2(nanda1a0b0,nanda1b1,nanda0b1b0,s2);

endmodule
*************************************************************
And the testbench:


module madderTester();

reg ia1=1;
reg ia0=1;
reg ib1=1;
reg ib0=1;

wire ws2;
wire ws1;
wire ws0;

madder madderInstance(ia1,ia0,ib1,ib0,ws2,ws1,ws0);


initial repeat(50) #31 ia1=~ia1;

initial repeat(45) #47 ia0=~ia0;

initial repeat(40) #81 ib1=~ib1;

initial repeat(50) #73 ib0=~ib0;



endmodule
********************************************************
When I simulate this, I get "z" for all three outputs...And I have no idea why!
Can anyone help me, please? How can I get rid of these "z"s? What's wrong?! O.O
I would appreciate your help in advance!
=)
 
Physics news on Phys.org
  • #2


OMG...SORRYYYYYY! I figured the problem myself! For the primitive gates of verilog, I had first entered the inputs and then the ouput...Because I thought it was like the gates I myself had implemented using transistors...But when I first entered the output then the inputs (like: nand myNand #(7,10) (ouput, input1, input2); ), the "z"s I used to get in the waveforms dissappeared! =)))))
 

1. How do I design a two-bit adder using Verilog primitive gates?

The first step in designing a two-bit adder using Verilog primitive gates is to identify the inputs and outputs of the circuit. In this case, the inputs are two 2-bit binary numbers and the output is a 3-bit sum. Then, you can use the primitive gates such as AND, OR, and XOR gates to construct the logic for the adder. Finally, you can test and simulate the circuit to ensure it is functioning correctly.

2. What are Verilog primitive gates?

Verilog primitive gates are the basic building blocks of digital logic circuits. These include AND, OR, NOT, and XOR gates, among others. They are used to construct more complex logic circuits and are the foundation of digital design using Verilog.

3. What are the advantages of using Verilog for designing a two-bit adder?

Verilog is a hardware description language specifically designed for digital circuit and system design. It allows for efficient and accurate description of complex digital circuits, making it a popular choice for designing two-bit adders. Additionally, Verilog has a wide range of simulation and verification tools available, making it easier to test and debug designs.

4. Can Verilog be used to design other types of digital circuits?

Yes, Verilog can be used to design various types of digital circuits, including adders, counters, multiplexers, and more. It is a versatile language that can handle both combinational and sequential logic circuits, making it suitable for a wide range of applications.

5. Are there any resources available for learning how to design a two-bit adder using Verilog?

Yes, there are many online tutorials, guides, and textbooks available for learning how to design a two-bit adder using Verilog. Some popular resources include online courses, YouTube videos, and Verilog reference books. Additionally, many universities offer courses on digital design using Verilog as part of their computer engineering or computer science programs.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
10K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
20K
Back
Top