-
Notifications
You must be signed in to change notification settings - Fork 0
/
TopModule.v
210 lines (197 loc) · 7.99 KB
/
TopModule.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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//////////////////////////////////////////////////////////////////////////////////
// school: CSUF
// Engineers: Jeremy, Duy, Spencer
//
// Create Date: 11/16/2021 07:26:26 PM
// Design Name: Basket ball score board
// Module Name: timer, scoreboard
// Project Name: 446 final project
// Target Devices: FPGA Nexys A7
//
// Additional Comments: group project
//
//////////////////////////////////////////////////////////////////////////////////
module Seven_segment_LED_Display_Controller(
input clock, // 100 Mhz clock source on Basys 3 FPGA
input reset, // reset
input reset_points, // reset game score
input reset_score, //reset time clock
input team, //input to switch between teams
input one_point, //input to increment 1 point
input two_point, //input to increment 2 points
input three_point,//input to increment 2 points
input pause, //pause timer
output reg [7:0] Anode_Activate, // anode signals of the 7-segment LED display
output reg [6:0] LED_out// cathode patterns of the 7-segment LED display
);
wire slow_clock; //clock divider wire here
reg [26:0] one_second_counter; // counter for generating 1 second clock enable
wire one_second_enable; // one second enable for counting numbers
reg [15:0] displayed_number; // counting number to be displayed
reg [7:0] team_1; //used to store teams score
reg [7:0] team_2; //used to store teams score
reg [7:0] LED_BCD;//used to out put scores and timer
reg [19:0] refresh_counter; // 20-bit for creating 10.5ms refresh period or 380Hz refresh rate
wire [2:0] LED_activating_counter; //3 bits
reg [5:0] seconds; // 00:ss
reg [5:0] minutes; // mm:00
clock_divider DUT (.clk(clock),.reset(reset), .sclk(slow_clock)); // instantiating here
always @(posedge clock or negedge reset)
begin
if(reset==0) // when switch is down
one_second_counter <= 0;
else if (pause)
displayed_number = displayed_number;
else begin
if(one_second_counter>=99999999)
one_second_counter <= 0;
else
one_second_counter <= one_second_counter + 1;
end
end
assign one_second_enable = (one_second_counter==99999999)?1:0;
always @(posedge clock)
begin
if (reset_score) begin //reset score here
minutes <= 12; // mm is set to 12:00
seconds <= 00;//default to 12:00 min once enabled
end
else if (one_second_enable == 1) // starts one second counter for timer
seconds <= seconds - 1;//decrement clock
else if (seconds == 0) begin //when clock == 0
seconds <= 59; //set value to 59
minutes <= minutes - 1;//decrement mm only if sec == 0
end
else if (pause) //pause clock
seconds=seconds; // pause occurs because p = p
else if (minutes ==0) //reset MM:00 to 11 for wrap
minutes <= 11;
end
always @(posedge clock)
begin
if(reset_score) begin //reset score here
minutes <= 12; // mm is set to 12:00
seconds <= 00;//default to 12:00 min once enabled
end
else if (one_second_enable == 1)// starts one second counter for timer
seconds <= seconds - 1;//decrement clock
else if (seconds == 0) begin //when clock == 0
seconds <= 59; //set value to 59
minutes <= minutes - 1;//decrement mm only if sec == 0
end
else if (pause) //pause clock
seconds=seconds; // pause occurs because p = p
else if ( minutes ==0)//reset MM:00 to 11 for wrap
minutes <= 11;
end
always @(posedge clock or negedge reset)// refresh rate for leds
begin
if (reset==0)
refresh_counter <= 0;
else
refresh_counter <= refresh_counter + 1;
end
assign LED_activating_counter = refresh_counter[19:17];//used 3 instead of 19:18
// anode activating signals for 8 LEDs, digit period of 2.6ms
// decoder to generate anode signals
always @(*)
begin
case(LED_activating_counter)
3'b000: begin
Anode_Activate = 8'b11111110;
// activate LED1 and Deactivate LED2, LED3, LED4, LED5, LED6, LED7, LED8
LED_BCD = minutes / 10;//10s place
// the first digit of the 16-bit number
end
3'b001: begin
Anode_Activate = 8'b11111101;
// activate LED2 and Deactivate LED1, LED3, LED4, LED5, LED6, LED7, LED8
LED_BCD = minutes % 10;//1s place
// the second digit of the 16-bit number
end
3'b010: begin
Anode_Activate = 8'b11111011;
// activate LED3 and Deactivate LED2, LED1, LED4, LED5, LED6, LED7, LED8
LED_BCD = seconds / 10;//10s place
// the third digit of the 16-bit number
end
3'b011: begin
Anode_Activate = 8'b11110111;
// activate LED4 and Deactivate LED2, LED3, LED1, LED5, LED6, LED7, LED8
LED_BCD = seconds % 10;//1s place
// the fourth digit of the 16-bit number
end
3'b100: begin
Anode_Activate = 8'b11101111;
// activate LED5 and Deactivate LED2, LED3, LED4, LED5, LED1, LED7, LED8
LED_BCD = (team_2 / 10);//10s place
// the first digit of the 16-bit number
end
3'b101: begin
Anode_Activate = 8'b11011111;
// activate LED6 and Deactivate LED1, LED3, LED4, LED5, LED2, LED7, LED8
LED_BCD = (team_2 % 10);//1s place
// the second digit of the 16-bit number
end
3'b110: begin
Anode_Activate = 8'b10111111;
// activate LED7 and Deactivate LED2, LED1, LED4, LED5, LED6, LED3, LED8
LED_BCD = (team_1 / 10);
// the third digit of the 16-bit number
end
3'b111: begin
Anode_Activate = 8'b01111111; // leading bit is zero. So turn on first led.
// activate LED8 and Deactivate LED2, LED3, LED1, LED5, LED6, LED7, LED4
LED_BCD = (team_1 % 10);
// the fourth digit of the 16-bit number
end
endcase
end
// Cathode patterns of the 7-segment LED display
always @(*)
begin
case(LED_BCD)
0: LED_out = 7'b0000001; // "0"
1: LED_out = 7'b1001111; // "1"
2: LED_out = 7'b0010010; // "2"
3: LED_out = 7'b0000110; // "3"
4: LED_out = 7'b1001100; // "4"
5: LED_out = 7'b0100100; // "5"
6: LED_out = 7'b0100000; // "6"
7: LED_out = 7'b0001111; // "7"
8: LED_out = 7'b0000000; // "8"
9: LED_out = 7'b0000100; // "9"
default: LED_out = 7'b0000001; // "0"
endcase
end
always @(posedge slow_clock)
begin
if(reset_points) begin //reset team scores here
team_1 = 7'b0000000; //set values to zero
team_2 = 7'b0000000; //set values to see here too
end
if (one_point)
begin //if button pressed for one point increment by 1
if(team)
team_1 = team_1 + 2'b01;
else
team_2 = team_2 + 2'b01;
end //if button pressed for two points increment by 2
else if (two_point) begin
if(team)
team_1 = team_1 + 2'b10;
else
team_2 = team_2 + 2'b10;
end //if button pressed for three points increment by 3
else if (three_point) begin
if(team)
team_1 <= team_1 + 2'b11;
else
team_2 <= team_2 + 2'b11;
end
if(team_1 >= 7'b1100100)//reset score board at 100
team_1 = 7'b0000000;//back to zero
if(team_2 >= 7'b1100100)//reset score board at 100
team_2 = 7'b0000000;//back to zero
end
endmodule //end module here