-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwinner.sv
55 lines (47 loc) · 1.34 KB
/
winner.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
module winner (Clock, Reset, lastLED, defeat, out);
input Clock, Reset, lastLED, defeat;
output reg[6:0] out;
reg [2:0] ps, ns;
//parameter[6:0] leftWin = 7'b0100100, rightWin = 7'b1111001, none = 7'b1111111;
always @(*)
if(lastLED && defeat) ns = ns + 1;
seg7 display (ps, out);
always @(posedge Clock)
if(Reset && (ps == 3'b111))
begin
ps <= 3'b0;
end
else
ps <= ns;
endmodule
module winner_testbench();
reg CLOCK_50, lastLED, defeat, Reset;
reg [6:0] win;
wire out;
// Set up the clock.
winner dut (CLOCK_50, lastLED, defeat, out);
parameter CLOCK_PERIOD=100;
initial CLOCK_50=1;
always begin
#(CLOCK_PERIOD/2);
CLOCK_50 = ~CLOCK_50;
end
initial begin
Reset <= 1; @(posedge CLOCK_50);
Reset <= 0; defeat <= 0; @(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
defeat <= 1; @(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
lastLED <= 0; @(posedge CLOCK_50);
@(posedge CLOCK_50);
lastLED <= 1; @(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
@(posedge CLOCK_50);
$stop;
end
endmodule