-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgray.v
53 lines (51 loc) · 1.28 KB
/
gray.v
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
45
46
47
48
49
50
51
52
53
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2020/10/24 19:30:25
// Design Name:
// Module Name: gray
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module gray(
input Clk,
input Reset,
input En,
output [2:0] Output,
output Overflow
);
integer cnt = 0, overflow = 0;
always @(posedge Clk) begin
if (Reset) begin
cnt = 0;
overflow = 0;
end
else if (En) begin
cnt = cnt + 1;
if (cnt > 7) begin
cnt = 0;
overflow = 1;
end
end
end
assign Overflow = overflow;
assign Output = (cnt == 0) ? 3'b000 :
(cnt == 1) ? 3'b001 :
(cnt == 2) ? 3'b011 :
(cnt == 3) ? 3'b010 :
(cnt == 4) ? 3'b110 :
(cnt == 5) ? 3'b111 :
(cnt == 6) ? 3'b101 :
(cnt == 7) ? 3'b100 : 0;
endmodule