-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenericCounter.v
70 lines (60 loc) · 1.34 KB
/
GenericCounter.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 16:29:44 04/11/2014
// Design Name:
// Module Name: GenericCounter
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module GenericCounter( CLK,
RESET,
ENABLE_IN,
TRIGG_OUT,
COUNT
);
parameter COUNTER_WIDTH = 4;
parameter COUNTER_MAX = 9;
input CLK;
input RESET;
input ENABLE_IN;
output reg TRIGG_OUT;
output [COUNTER_WIDTH - 1 : 0] COUNT;
// Declare the registers that hold the state of the
// counter and the trigger signal
reg [COUNTER_WIDTH - 1 : 0] Counter;
always@ (posedge CLK) begin
if (RESET)
Counter <= 0;
else begin
if(ENABLE_IN) begin
if (Counter == COUNTER_MAX)
Counter <= 0;
else
Counter <= Counter +1;
end
end
end
always@ (posedge CLK) begin
if (RESET)
TRIGG_OUT <= 0;
else begin
if (ENABLE_IN && (Counter == COUNTER_MAX))
TRIGG_OUT <= 1;
else
TRIGG_OUT <= 0;
end
end
assign COUNT = Counter;
endmodule