This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setAnswerModule.v
71 lines (65 loc) · 2.16 KB
/
setAnswerModule.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
module setAnswerModule(input wire CLK,
input wire rst_n, // Active low reset
input wire zero,
input wire one,
input wire two,
input wire three,
input wire four,
input wire five,
input wire six,
input wire seven,
input wire eight,
input wire nine,
output reg [15:0] answer, // Change to 16-bit output
output reg legalAnswer); // Add legalAnswer output
wire [3:0] bin_out;
wire [3:0] out_wire1, out_wire2, out_wire3, out_wire4;
wire button_pressed; // Button pressed signal
wire trigger_out; // Output from trigger module
assign button_pressed = zero | one | two | three | four | five | six | seven | eight | nine; // Combine all the digits inputs to generate button_pressed signal
decimal_to_binary u12 (
.CLK(CLK),
.rst_n(rst_n),
.zero(zero),
.one(one),
.two(two),
.three(three),
.four(four),
.five(five),
.six(six),
.seven(seven),
.eight(eight),
.nine(nine),
.binary(bin_out)
);
trigger T12 (
.CLK(CLK),
.Din(button_pressed),
.rst_n(rst_n),
.Dout(trigger_out)
);
FourInputConv u22 (
.in(bin_out),
.clk(CLK),
.rst_n(rst_n),
.ce(trigger_out), // Connect trigger_out signal
.out1(out_wire1),
.out2(out_wire2),
.out3(out_wire3),
.out4(out_wire4)
);
always @(posedge CLK or negedge rst_n) begin
legalAnswer <= 1'b0;
if (~rst_n) begin
answer <= 16'd0;
legalAnswer <= 1'b0;
end else begin
answer <= {out_wire1, out_wire2, out_wire3, out_wire4};
// If any of the out_wire[i] signals is 1111, set legalAnswer to 1.
if (out_wire1 ! = 4'b1111 && out_wire2 ! = 4'b1111 && out_wire3 ! = 4'b1111 && out_wire4 ! = 4'b1111)
legalAnswer <= 1'b1;
else
legalAnswer <= 1'b0;
end
end
endmodule