-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgray_to_bin.v
More file actions
34 lines (29 loc) · 772 Bytes
/
Copy pathgray_to_bin.v
File metadata and controls
34 lines (29 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// The design module - Converter(Bin - Gray)
module gray_to_bin (g, b);
parameter N = 4;
input [N-1:0] g;
output reg [N-1:0] b;
integer i;
always @(*) begin
b[N-1] = g[N-1];
for (i = N-2; i >= 0; i = i - 1) begin
b[i] = g[i] ^ b[i+1];
end
end
endmodule
// The Testbench - Converter(Gray to Bin)
module tb;
parameter N = 4;
reg [N-1:0] g;
wire [N-1:0] b;
gray_to_bin #(N) dut (.g(g), .b(b));
initial begin
$display("\n-----: Output :-----\n");
repeat(10) begin
g = $random;
#1;
$display("Input(Gr) = %b, Output(Bi) = %b", g, b);
end
$display("\n-----: The End :-----");
end
endmodule