Monday, 10 March 2014
Tuesday, 4 March 2014
Wednesday, 12 February 2014
Tuesday, 11 February 2014
Friday, 7 February 2014
verilog code for decoder 2x4
BEHAVIORAL:
module dec(a,b,en,c);
input a,b,en;
output[0:3] c;
reg [0:3] c;
reg s0,s1;
always @(a or b or en)
begin
s0 = ~a;
s1 = ~b;
c[0]=(s0&s1&en);
c[1]=(s0&b&en);
c[2]=(a&s1&en);
c[3]=(a&b&en);
end
endmodule
module dec(a,b,en,c);
input a,b,en;
output[0:3] c;
reg [0:3] c;
reg s0,s1;
always @(a or b or en)
begin
s0 = ~a;
s1 = ~b;
c[0]=(s0&s1&en);
c[1]=(s0&b&en);
c[2]=(a&s1&en);
c[3]=(a&b&en);
end
endmodule
TEST BENCH:
initializing is automatically done in xilinx 14th version .
en=1'b0;b=1'b0;a=1'b0;
#10 en=1'b0;b=1'b0;a=1'b1;
#10 en=1'b0;b=1'b1;a=1'b0;
#10 en=1'b0;b=1'b1;a=1'b1;
#10 en=1'b1;b=1'b0;a=1'b0;
#10 en=1'b1;b=1'b0;a=1'b1;
#10 en=1'b1;b=1'b1;a=1'b1;
end
initial begin
$monitor($time,"a=%b,b=%b,En=%b,c=%b",a,b,en,c);
end
endmodule
Wednesday, 5 February 2014
2x1 multiplexer
DATA FLOW
module mux2_1(a,b,s,cout);
input a,b,s;
output cout;
assign cout = ((a&s)||(b&~s));
endmodule
GATE LEVEL:
module mux2_1(a,b,s,cout);
input a,b,s;
output cout;
wire s0,x1,x2;
xor (s0,s);
and a1(x1,a,s);
and a2(x2,b,s0);
or a3(cout,x1,x2);
endmodule
BEHAVIORAL:
module mux2_1(a,b,s,cout);
input a,b,s;
output cout;
wire s0,x1,x2;
reg cout;
always @(a or b or s) begin
s0=~s;
x1=a&s;
x2=b&s0;
cout=x1||x2;
end
endmodule
TEST BENCH:
module mux2_1( );
//inputs
wire a,b,s;
//outputs
reg cout;
//instantiate the unit under test
muxgtlev uut (
.a(a),
.b(b),
.s(s),
.cout(cout)
);
initial begin
#10 a=2'b01;
#20 b=2'b10;
#25 s=2'b11;
end
initial begin
$monitor($time,"a=%b,b=%b,s=%b,cout=%b",a,b,s,cout);
end
endmodule
module mux2_1(a,b,s,cout);
input a,b,s;
output cout;
assign cout = ((a&s)||(b&~s));
endmodule
GATE LEVEL:
module mux2_1(a,b,s,cout);
input a,b,s;
output cout;
wire s0,x1,x2;
xor (s0,s);
and a1(x1,a,s);
and a2(x2,b,s0);
or a3(cout,x1,x2);
endmodule
BEHAVIORAL:
module mux2_1(a,b,s,cout);
input a,b,s;
output cout;
wire s0,x1,x2;
reg cout;
always @(a or b or s) begin
s0=~s;
x1=a&s;
x2=b&s0;
cout=x1||x2;
end
endmodule
TEST BENCH:
module mux2_1( );
//inputs
wire a,b,s;
//outputs
reg cout;
//instantiate the unit under test
muxgtlev uut (
.a(a),
.b(b),
.s(s),
.cout(cout)
);
initial begin
#10 a=2'b01;
#20 b=2'b10;
#25 s=2'b11;
end
initial begin
$monitor($time,"a=%b,b=%b,s=%b,cout=%b",a,b,s,cout);
end
endmodule
Sunday, 2 February 2014
mux 4x1
Gate Level :
module mux4_1(
input a,
input b,
input c,
input d,
input s0,
input s1,
output out
);
wire s2,s3,x,x1,x2,x3;
not (s2,~s0);
not (s3,~s1);
and z1(x,a,s0);
and z2(x1,b,s1);
and z3(x2,c,s2);
and z4(x3,d,s3);
or z5(out,x,x1,x2,x3);
endmodule
Behavioral :
module mux4_1(
input a,
input b,
input c,
input d,
input s0,
input s1,
output out
);
wire s2,s3,x,x1,x2,x3;
not (s2,~s0);
not (s3,~s1);
and z1(x,a,s0);
and z2(x1,b,s1);
and z3(x2,c,s2);
and z4(x3,d,s3);
or z5(out,x,x1,x2,x3);
endmodule
Behavioral :
module mux_4(
input a,b,c,d,s,s0,
output z);
reg s1,s2,x1,x2,x3,x4,z;
always @(a or b or c or d or s or s0)
begin
s1=~s;
s2=~s0;
x1=s&a;
x2=s0&b;
x3=s1&c;
x4=s2&d;
z <= #20 (x1||x2||x3||x4);
end
endmodule
XOR verilog HDL code
dataflow:
module sw(
input a,
input b,
output c
);
assign c= a^b;
endmodule
Behavioral :
module sw(
input a,
input b,
output c
);
reg c;
always @(a or b) begin
c=a^b;
end
endmodule
module sw(
input a,
input b,
output c
);
assign c= a^b;
endmodule
Behavioral :
module sw(
input a,
input b,
output c
);
reg c;
always @(a or b) begin
c=a^b;
end
endmodule
Subscribe to:
Posts (Atom)