Skip to main content

Half Adder And Full Adder in All Level Of Abstraction Verilog Code

Hello Dear Reader,


Fig.1



Here given Fig.1 is one bit half adder in the lowest level of the abstration diagram is there as similarly we know their are two ways to designed one bit full adder either using two half adder and one or gate or designed using their separate boolean expression As shown in below Fig.2 and Fig.3.

Fig.2

   
Fig.3

Here in below section i have provided verilog code at all the levels of the digital system design such as Behavioural Level, Data or RTL Level, Structural Level.

Half-Adder:

1) Behavioural Level Verilog Code:

module half_adder(a,b,c,s
    );// behavioural model
input a,b;
output reg c,s;
always@(a,b)
begin
if((a&&~b)||(~a&&b))
s=1;
else
s=0;
if(a&&b)
c=1;
else
c=0;
end
endmodule

2) RTL or Data Flow Level Verilog Code:

module half_adder(a,b,c,s
    );// Dataflow level model
input a,b;
output c,s;
assign s=((a&&~b)||(~a&&b));
assign c=(a&&b);
endmodule

3) Structural Level Verilog Code: 

module half_adder(a,b,c,s
    );// Structural level model
input a,b;
output c,s;
wire w1,w2;
and g1(w1,~a,b);
and g2(w2,a,~b);
or g3(s,w1,w2);
and g4(c,a,b);
endmodule

RTL Viewer:

Fig.4

Simulational Result:


Full-Adder:

1) Behavioural Level Verilog Code:

module full_adder(a,b,cin,s,c
    );//behavioural level model
input a,b,cin;
output reg s,c;
always@(a,b,cin)
begin
s=a^b^cin;
c= (a&&b )||((a^b)&&cin);
end
endmodule

2) RTL or Data Flow Level Verilog Code:

module full_adder(a,b,cin,s,c
    );//Dataflow level model
input a,b,cin;
output s,c;
assign s=(a^b^cin);
assign c=((a&&b )||((a^b)&&cin));
endmodule

3) Structural Level Verilog Code: 

module full_adder(a,b,cin,s,c
    );//structural level model
input a,b,cin;
output s,c;
wire w1,w2,w3;
xor g1(w1,a,b);
and g2(w2,a,b);
and g3(w3,cin,w1);
xor g4(s,w1,cin);
or g5(c,w2,w3);
endmodule

4) Full Adder using Half Adder As Instance Model: 

module full_adder(a,b,cin,sum,carry);//structural level model
               input a,b,cin;
               output sum,carry;
               half_adder p1(a,b,c1,s);
               half_adder p2(s,cin,c2,sum);
               or g1(carry,c1,c2);
               endmodule

RTL Viewer:


Simulational Result:


Now Thank the reader for this post and I hope it might be helpful and give your suggestions in the comment box I will try to improve my side.



Comments

  1. I like this sir but please upload some more code by example. I personally like your articles.

    ReplyDelete
  2. Sure I Will do In short time around December end.

    ReplyDelete
  3. Yes Sir I am from Punjab I like your content and most waiting for Verilog more example code.

    ReplyDelete
  4. Good article for all level of code thanks sir🙌🙌🙌🙌

    ReplyDelete
  5. Good write some more complex problems code so it is better.

    ReplyDelete
  6. Good starting brother keep it up 👍👍👍👌👌👌

    ReplyDelete
  7. Are you writing Specifically VLSI Field related then share site. I like your technical articles

    ReplyDelete
  8. I am doing M. Tech In VLSI and yes I have my own site specifically for VLSI field checkout this link https://geniusvlsi.blogspot.com/

    ReplyDelete

Post a Comment

Popular posts from this blog

Application Engineer- Prototyping at Siemens India

  Hello, Dear Readers, Siemens India has a vacancy for the Application Engineer role. Siemens EDA is a global technology leader in Electronic Design Automation software. Our software tools enable companies around the world to develop highly innovative electronic products faster and more cost-effectively. Our customers use our tools to push the boundaries of technology and physics to deliver better products in the increasingly complex world of chip, board, and system design. This role is based in Bengaluru. But you’ll also get to visit other locations in India and globe, so you’ll need to go where this job takes you. In return, you’ll get the chance to work with teams impacting entire cities, countries, and the shape of things to come We make real what matters! This is your role: Deploy Siemens EDA ProFPGA prototyping software and hardware solutions at customers and guide the customers to successful design bring-up Work closely with R&D to solve problems, review product spe...

Tutorial on EasyEDA desktop software for PCB and schematic design

In this article, I am going to write a tutorial on how to use EasyEDA desktop application for creating a schematic and for PCB design. One of best advantage of this software is that you can create design offline and can automatically synchronize your design with your online EasyEDA account.  It can be used for circuits simulation, PCB deign and electronics circuits design. You can download EasyEDA desktop application by clicking on following link and it will work on windows 7 or its greater version. They are also releasing soon offline application OSX and Linux users. So keep visiting their website for more information.                                                    https://easyeda.com/page/download So let’s start and see how to design a schematic and PCB using EasyEDA offline desktop application. So first of all lets see how to create a schema...

CMOS OPAMP Design Using LTspice

  Hello Dear Reader, Here in this post, I will give an idea about how CMOS OPAMP designing using 180nm technology node and using LTspice. from that opamp I have design switched capacitor integrator. Design Specifications: Here Design specification may be changed according to the application here my target is to design an active lowpass filter so I have chosen an opamp integrator so in the below I have explained how to design an opamp as well as an integrator in a 180nm technology node in LTspice. So let's start design First, we need a technology parameter file so that the file we can insert in the LTspice, in my example it is 180nm so mostly it is available from the  http://ptm.asu.edu/latest.html  and you make one text file using notepad or whatever is fit on your own. Then go to the LTspice and new schematic and then you see .op on the right most upper side click on it and give your text file path after .include  as shown in the below images.  Now first of all...