-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathbcd2gray.v
More file actions
44 lines (35 loc) · 784 Bytes
/
bcd2gray.v
File metadata and controls
44 lines (35 loc) · 784 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
35
36
37
38
39
40
41
42
43
44
// BCD to gray conversion
module bcd2gray_gate(a, b);
// gate level
input [3:0]a;
output [3:0]b;
// Assignment statement
xor x0(b[3], 0, a[3]);
xor x1(b[2], a[3], a[2]);
xor x2(b[1], a[2], a[1]);
xor x3(b[0], a[1], a[0]);
endmodule
module bcd2gray_df(a, b);
// dataflow model
input [3:0]a;
output [3:0]b;
assign b[3] = a[3];
assign b[2] = a[3] ^ a[2];
assign b[1] = a[2] ^ a[1];
assign b[0] = a[1] ^ a[0];
endmodule
module testbench;
reg [3:0]a;
wire [3:0]b;
bcd2gray_df bcd2gray(a, b);
initial
begin
$monitor(, $time, " a=%4b, b=%4b", a, b);
#0 a=4'b0000;
// repeat(n): repeats the statement below n times
repeat(16)
// updates 'a' 16 times at an interval of 10 time units
#10 a=a+4'b0001;
#180 $finish;
end
endmodule