-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVendingMachine.v.bak
More file actions
63 lines (55 loc) · 1.84 KB
/
VendingMachine.v.bak
File metadata and controls
63 lines (55 loc) · 1.84 KB
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
module lighting_system (
input clk, // Input clock signal (e.g., 50 MHz)
input rst, // Reset signal
input button1, // Button 1
input button2, // Button 2
input switch, // Switch for credit increment
output reg led1, // LED 1 output
output reg led2, // LED 2 output
output [6:0] seg1, // 7-segment display 1
output [6:0] seg2, // 7-segment display 2
output [6:0] seg3, // 7-segment display 3
output [6:0] seg4 // 7-segment display 4
);
// Internal Signals
wire clk_1hz; // 1 Hz clock signal from clock divider
// Instantiate the clock divider
clock_divider #(
.CLK_FREQ(50_000_000), // Input clock frequency
.TARGET_FREQ(1) // Target frequency
) clk_div_inst (
.clk_in(clk),
.rst(rst),
.clk_out(clk_1hz)
);
// The rest of the logic remains the same, but use `clk_1hz` for timing
// instead of the main `clk`.
// Example: Replace the timer and credit logic to use clk_1hz.
reg [15:0] credits;
reg [31:0] credit_timer;
always @(posedge clk_1hz or posedge rst) begin
if (rst) begin
credits <= 0;
led1 <= 0;
led2 <= 0;
end else begin
// Credit Increment
if (switch) begin
credits <= credits + 5;
end
// Button and LED Logic
if (button1 && credits >= 100) begin
led1 <= 1;
credits <= credits - 100;
end else begin
led1 <= 0;
end
if (button2 && credits >= 100) begin
led2 <= 1;
credits <= credits - 100;
end else begin
led2 <= 0;
end
end
end
endmodule