-
Notifications
You must be signed in to change notification settings - Fork 0
/
shot_timer.v
53 lines (52 loc) · 1.29 KB
/
shot_timer.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: University of Utah
// Engineer: Dave Kloster, Revised by Jacob Sanders
// http://web.mit.edu/6.111/www/s2004/PROJECTS/12/report12.pdf
// Create Date: 18:35:06 11/16/2010
// Design Name:
// Module Name: shot_timer
// Project Name: CS3710
// Description: Sets the time values for the shot/hit cycle
// for the gun interface of the NES Zapper.
//////////////////////////////////////////////////////////////////////////////////
module shot_timer
(
input clk,
input rst,
input start,
input stop,
output reg time_up
);
//SET TO THE AMOUNT OF TIME TO WAIT.
//VALUE DEPENDS ON DESIRED TIME AND
//THE FREQUENCE OF THE CLOCK.
parameter TIMER_COUNT = 24'h186A00;
//USING 50MHz CLOCK, COUNTING TO .32 SECONDs.
reg [21:0] Q;
reg on;
always @ (posedge clk) begin
if (!rst) begin
Q <= 22'b0;
time_up = 0;
on = 0;
end
else if (stop) begin
Q <= 22'b0;
time_up = 0;
on = 0;
end
else if (Q == TIMER_COUNT) begin
time_up = 1;
on = 0;
end
else if (on) begin
Q <= Q + 1;
on = 1;
end
else if (start) begin
Q <= 22'b1;
on = 1;
end
end // always @ (posedge clk or posedge rst)
endmodule // shot_timer