-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounterBasic.sv
More file actions
45 lines (35 loc) · 816 Bytes
/
CounterBasic.sv
File metadata and controls
45 lines (35 loc) · 816 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
39
40
41
42
43
44
45
module CounterBasic #(width = 4,compare = 10)(
input logic clk,
input logic rst,
output logic over_value
);
enum int unsigned { reset_state=0, inc_state=1} state, next_state;
reg [width-1:0]count_value;
integer i;
always_ff @(posedge clk)
begin
if (clk) begin
state <= next_state;
case(state)
reset_state:
count_value<='b0;
inc_state:
if(count_value == compare-1)
count_value<='b0;
else
count_value <= count_value + 'b1;
endcase;
end
end
always_ff @ (negedge clk)
over_value <= (count_value == compare-1) ? 1'b1 : 1'b0;
always_comb
if (rst)
next_state <= reset_state;
else begin
case(state)
reset_state: next_state <= inc_state;
inc_state: next_state <= inc_state;
endcase;
end
endmodule