-
Notifications
You must be signed in to change notification settings - Fork 0
/
counter_led_works.v
60 lines (55 loc) · 1.08 KB
/
counter_led_works.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 23.03.2022 00:47:56
// Design Name:
// Module Name: counter
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module counter(clk,reset,count);
input clk,reset;
output reg [3:0] count = 4'b0000;
reg [25:0] count_reg;
reg clk_div = 1'b0;
always @ (posedge clk)
begin
if (reset)
begin
clk_div <= 1'b0;
count_reg <= 26'd0;
end
else
begin
count_reg <= count_reg + 1;
if (count_reg == 26'h322) // for synthesis
// if (count_reg == 26'd12) // for simulation
begin
clk_div <= ~ clk_div;
count_reg <= 26'd0;
end
end
end
always @ (posedge clk_div)
begin
if (reset)
begin
count <= 4'b0000;
end
else
begin
count <= count + 1;
end
end
endmodule