Professional Documents
Culture Documents
FALLSEM2022-23 BECE102L TH VL2022230102871 Reference Material I 08-10-2022 15. Verilog 1 (Logic Gates HA FA and D FF)
FALLSEM2022-23 BECE102L TH VL2022230102871 Reference Material I 08-10-2022 15. Verilog 1 (Logic Gates HA FA and D FF)
(Verilog HDL)
Types of Modelling
Gate level Modelling / Structural Modelling (Using Gate primitives)
Data flow Modelling (Using Verilog Operators)
Behavioral Modelling (Using Initial and Always block)
module
1. Verilog HDL
2. VHDL
module logic_gates (A,B,y0,y1,y2,y3,y4,y5,y6,y7);
input A,B;
output y0,y1,y2,y3,y4,y5,y6,y7;
or g1(y0,A,B);
nor g2(y1,A,B);
and g3(y2,A,B);
nand g4(y3,A,B);
xor g5(y4,A,B);
xnor g6(y5,A,B);
The inputs of the gates are A and B. not g7(y6,A);
The output of the gates are y0, endmodule
y1,y2,y3,y4,y5 and y6.
module full_adder(A,B,C,SUM,CARRY);
input A,B,C;
output SUM,CARRY;
c<=a+b \\ 12
d<=a+c \\ 5
module DFF(D,clk,preset,clr,q,qbar);
input D,clk,clr,preset;
output reg q,qbar;
always @(posedge clk)
begin
if(clr==1)
begin
q<=0;
qbar<=1;
end
else if(preset==1)
begin
q<=0;
q<=1;
q<=q
qbar<=0;
end
else
begin
if(d==1)
begin
q<=1;
qbar<=0;
end
else
begin
q<=0;
qbar<=1;
end
end
end
endmodule
module TFF(T,clk,clr,q,qbar);
input T,clk,clr;
output reg q,qbar;
always @(posedge clk)
begin
if(clr==1)
begin
q<=0;
qbar<=1;
end
else
begin
if(T==1)
begin
q<=qbar;
qbar<=q;
end
else
begin
q<=q;
qbar<=qbar;
end
end
end
endmodule
module JKFF(J,K,clk,clr,preset,q,qbar);
input J,K,clk,clr,preset;
output reg q,qbar;
always @(posedge clk)
begin
if(clr==1)
begin
q<=0;
qbar<=1;
end
if(preset==1)
begin
q<=1;
qbar<=0;
end
else
begin
if ((J==0)&&(K==0))
begin
q<=q;
qbar<=qbar;
end
else if ((J==0)&&(K==1))
begin
q<=1’b0;
qbar<=1’b1;
end
else if ((J==1)&&(K==0))
begin
q<=1’b1;
qbar<=1’b0;
end
else
begin
q<=qbar;
qbar<=q;
end
end
end
endmodule
If(a==1)