-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdancingThumbs.sv
180 lines (167 loc) · 7.52 KB
/
dancingThumbs.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
module dancingThumbs (CLOCK_50, HEX0, HEX1, HEX8, HEX9, KEY, LEDR, SW);
input CLOCK_50; // 50MHz clock.
output [6:0] HEX0, HEX1, HEX8, HEX9;
output [9:0] LEDR;
input [3:0] KEY;
input [9:0] SW;
reg [4:0] count, count1, count2, count3, count4, count5, count6;
reg tick1, tick2, tick3, tick4;
reg hold1, hold2, hold3, hold4;
reg restart;
// // Generate clk off of CLOCK_50, whichClock picks rate.
// wire [31:0] clk;
// parameter whichClock = 8;
// clock_divider cdiv (CLOCK_50, clk);
//
wire [8:0] random;
//wire [9:0] check;
wire [4:0] column1, column2, column3, column4;
wire spot1, spot2, spot3, spot4;
wire [1:0] play1, play2, play3, play4;
// assign restart = 1'b0;
// assign hold = (column1 == 5'b00000) || (column2 == 5'b00000) ||
// (column3 == 5'b00000) || (column4 == 5'b00000);
assign hold1 = (column1 == 5'b00000);
assign hold2 = (column2 == 5'b00000);
assign hold3 = (column3 == 5'b00000);
assign hold4 = (column4 == 5'b00000);
assign restart = (count >= 5'd9) && (count <= 5'd23);
assign LEDR[4:0] = column1;
assign LEDR[9:5] = column2;
LFSR r (.Clock(CLOCK_50), .Reset(SW[9]), .q(random));
press pp1 (.Clock(CLOCK_50) , .pressed(hold1) , .pull(tick1) , .stop(restart));
press pp2 (.Clock(CLOCK_50) , .pressed(hold2) , .pull(tick2) , .stop(restart));
press pp3 (.Clock(CLOCK_50) , .pressed(hold3) , .pull(tick3) , .stop(restart));
press pp4 (.Clock(CLOCK_50) , .pressed(hold4) , .pull(tick4) , .stop(restart));
press p1 (.Clock(CLOCK_50) , .pressed(~KEY[0]), .pull(spot1), .stop(restart));
press p2 (.Clock(CLOCK_50) , .pressed(~KEY[1]), .pull(spot2), .stop(restart));
press p3 (.Clock(CLOCK_50) , .pressed(~KEY[2]), .pull(spot3), .stop(restart));
press p4 (.Clock(CLOCK_50) , .pressed(~KEY[3]), .pull(spot4), .stop(restart));
oneBank o1 (.Clock(CLOCK_50), .Reset(SW[9]), .speed(SW[1:0]), .start(random[0]), .out(column1), .stop(restart));
oneBank o2 (.Clock(CLOCK_50), .Reset(SW[9]), .speed(SW[1:0]), .start(random[5]), .out(column2), .stop(restart));
oneBank o3 (.Clock(CLOCK_50), .Reset(SW[9]), .speed(SW[1:0]), .start(random[7]), .out(column3), .stop(restart));
oneBank o4 (.Clock(CLOCK_50), .Reset(SW[9]), .speed(SW[1:0]), .start(random[2]), .out(column4), .stop(restart));
checkOnPoint c1 (.Clock(CLOCK_50), .Reset(SW[9] || restart), .in(spot1), .allOff(tick1), .harder(SW[2]), .column(column1), .point(play1), .stop(terminate));
checkOnPoint c2 (.Clock(CLOCK_50), .Reset(SW[9] || restart), .in(spot2), .allOff(tick2), .harder(SW[2]), .column(column2), .point(play2), .stop(terminate));
checkOnPoint c3 (.Clock(CLOCK_50), .Reset(SW[9] || restart), .in(spot3), .allOff(tick3), .harder(SW[2]), .column(column3), .point(play3), .stop(terminate));
checkOnPoint c4 (.Clock(CLOCK_50), .Reset(SW[9] || restart), .in(spot4), .allOff(tick4), .harder(SW[2]), .column(column4), .point(play4), .stop(terminate));
score s1 (.Clock(CLOCK_50), .Reset(SW[9]), .onPoint(play1), .out(count1), .stop(restart));
score s2 (.Clock(CLOCK_50), .Reset(SW[9]), .onPoint(play2), .out(count2), .stop(restart));
score s3 (.Clock(CLOCK_50), .Reset(SW[9]), .onPoint(play3), .out(count3), .stop(restart));
score s4 (.Clock(CLOCK_50), .Reset(SW[9]), .onPoint(play4), .out(count4), .stop(restart));
//score s2 (.Clock(CLOCK_50), .Reset(SW[9]), .out(countR), .stop(max));
add5bits aa1 (.A(count1), .B(count2), .out(count5), .stop(restart), .E(1'b0));
add5bits aa2 (.A(count3), .B(count4), .out(count6), .stop(restart), .E(1'b0));
add5bits aa3 (.A(count5), .B(count6), .out(count), .stop(restart), .E(1'b0));
//add5bits (.A(count3), .B(count4), .out(count), .stop(max || min), .E(1'b0));
seg7 display1 (count, HEX1, HEX0);
//seg7 display1 (count2, HEX9, HEX8);
endmodule
// divided_clocks[0] = 25MHz, [1] = 12.5Mhz, ... [23] = 3Hz, [24] = 1.5Hz,
//[25] = 0.75Hz, ...
//module clock_divider (clock, divided_clocks);
// input clock;
// output [31:0] divided_clocks;
// reg [31:0] divided_clocks;
//
// initial
// divided_clocks = 0;
//
// always @(posedge clock)
// divided_clocks = divided_clocks + 1;
//endmodule
module dancingThumbs_testbench(); //CLOCK_50, KEY, SW, LEDR, HEX0
reg CLOCK_50;
reg [9:0] LEDR;
reg [6:0] HEX0, HEX1;
reg [9:0] SW;
reg [3:0] KEY;
dancingThumbs dut(CLOCK_50, HEX0, HEX1, HEX8, HEX9, KEY, LEDR, SW);
// Set up the clock.
parameter CLOCK_PERIOD=100;
initial CLOCK_50=1;
initial KEY[3:0]=4'b1111;
always begin
#(CLOCK_PERIOD/2);
CLOCK_50 = ~CLOCK_50;
end
// Set up the inputs to the design. Each line is a clock cycle.
initial begin
SW[9] <= 1; @(posedge CLOCK_50);
SW[9] <= 0; KEY[0] <= 0; @(posedge CLOCK_50);
@(posedge CLOCK_50);
SW[1:0] <= 2'b11; @(posedge CLOCK_50);
SW[2] <= 1'B0; @(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
KEY[0] <= 1; @(posedge CLOCK_50);
KEY[0] <= 0; @(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
KEY[0] <= 1; @(posedge CLOCK_50);
KEY[0] <= 0; @(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
KEY[0] <= 1; @(posedge CLOCK_50);
KEY[0] <= 0; @(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
KEY[0] <= 1; @(posedge CLOCK_50);
KEY[0] <= 0; @(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
KEY[0] <= 1; @(posedge CLOCK_50);
KEY[0] <= 0; @(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
KEY[0] <= 1; @(posedge CLOCK_50);
KEY[0] <= 0; @(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
KEY[0] <= 1; @(posedge CLOCK_50);
KEY[0] <= 0; @(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
$stop;
end
endmodule