-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcounter.v
More file actions
38 lines (32 loc) · 747 Bytes
/
counter.v
File metadata and controls
38 lines (32 loc) · 747 Bytes
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
/*
Counter Module
Counts Up when inc is 1
Used in:
1. ORA #3
Parameters:
1. BITS : Number of Bits in the Counter
Inputs:
1. clk
2. rst : Asynch Reset
2. inc : Increment when 1
Outputs:
1. count : Current State of Counter
*/
`timescale 1ns/1ns
module counter
#(parameter BITS = 32)
(
input clk,
input rst,
input inc,
output reg [BITS-1:0] counter
);
initial begin
counter = {BITS{1'b0}};
end
always @(posedge(clk) or posedge(rst)) begin
if(inc == 1 && rst == 0) counter <= counter + 1;
if(rst == 1) counter <= {BITS{1'b0}};
end
assign count = counter;
endmodule