Code Convertor & parity generators using
reduction operators in Verilog
BINARY TO GRAY
CONVERTER
module bin2gray(b,g);
input [3:0] b;
output [3:0] g;
assign g[3]=b[3];
assign g[2]=^b[3:2];
assign g[1]=^b[2:1];
assign g[0]=^b[1:0];
endmodule
TESTBENCH:
module bin2gray_tb();
wire [3:0] G;
reg [3:0] B;
bin2gray BG1(B,G);
initial
begin
B=4'b0000;
#50; B=4'b0001;
#50; B=4'b0010;
#50; B=4'b0011;
#50; B=4'b0100;
#50; B=4'b0101;
#50; B=4'b0110;
#50; B=4'b0111;
#50; B=4'b1000;
#50; B=4'b1001;
#50; B=4'b1010;
#50; B=4'b1011;
#50; B=4'b1100;
#50; B=4'b1101;
#50; B=4'b1110;
#50; B=4'b1111;
#250 $finish;
end
endmodule
PARITY GENERATOR
module parity(a,p);
input [3:0]a;
output p;
assign p=^a;
endmodule
TESTBENCH:
module parity_tb();
reg [3:0] A;
wire P;
parity P1(A,P);
initial
begin
A=4'b0000;
#50; A=4'b0001;
#50; A=4'b0010;
#50; A=4'b0011;
#50; A=4'b0100;
#50; A=4'b0101;
#50; A=4'b0110;
#50; A=4'b0111;
#50; A=4'b1000;
#50; A=4'b1001;
#50; A=4'b1010;
#50; A=4'b1011;
#50; A=4'b1100;
#50; A=4'b1101;
#50; A=4'b1110;
#50; A=4'b1111;
#250 $finish;
end
endmodule
No comments:
Post a Comment