-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtop.sv
105 lines (81 loc) · 2.63 KB
/
top.sv
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//=======================================================
// This code is generated by Terasic System Builder
//=======================================================
module top (
//////////// CLOCK //////////
input CLOCK_50,
input CLOCK2_50,
input CLOCK3_50,
//////////// LED //////////
output [8:0] LEDG,
output [17:0] LEDR,
//////////// KEY //////////
input [3:0] KEY,
//////////// SW //////////
input [17:0] SW,
//////////// SEG7 //////////
output [6:0] HEX0,
output [6:0] HEX1,
output [6:0] HEX2,
output [6:0] HEX3,
output [6:0] HEX4,
output [6:0] HEX5,
output [6:0] HEX6,
output [6:0] HEX7
);
//=======================================================
// REG/WIRE declarations
//=======================================================
/* 24 bit clock divider, converts 50MHz clock signal to 2.98Hz */
logic [23:0] clkdiv;
logic ledclk;
assign ledclk = clkdiv[23];
/* driver for LEDs */
logic [25:0] leds;
assign LEDR = leds[25:8];
assign LEDG = leds[7:0];
/* LED state register, 0 means going left, 1 means going right */
logic ledstate;
//=======================================================
// Structural coding
//=======================================================
initial begin
clkdiv = 26'h0;
/* start at the far right, LEDG0 */
leds = 26'b1;
/* start out going to the left */
ledstate = 1'b0;
end
always @(posedge CLOCK_50) begin
/* drive the clock divider, every 2^26 cycles of CLOCK_50, the
* top bit will roll over and give us a clock edge for clkdiv
* */
clkdiv <= clkdiv + 1;
end
always @(posedge ledclk) begin
/* going left and we are at the far left, time to turn around */
if ( (ledstate == 0) && (leds == 26'b10000000000000000000000000) ) begin
ledstate <= 1;
leds <= leds >> 1;
/* going left and not at the far left, keep going */
end else if (ledstate == 0) begin
ledstate <= 0;
leds <= leds << 1;
/* going right and we are at the far right, turn around */
end else if ( (ledstate == 1) && (leds == 26'b1) ) begin
ledstate <= 0;
leds <= leds << 1;
/* going right, and we aren't at the far right */
end else begin
leds <= leds >> 1;
end
end
hexdriver d0 (SW[3:0], HEX0);
hexdriver d1 (SW[7:4], HEX1);
hexdriver d2 (SW[11:8], HEX2);
hexdriver d3 (SW[15:12], HEX3);
hexdriver d4 ({2'b00, SW[17:16]}, HEX4);
hexdriver d5 (4'b0000, HEX5);
hexdriver d6 (4'b0000, HEX6);
hexdriver d7 (4'b0000, HEX7);
endmodule