forked from tgiv014/ECE441-Project-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock_divider.v
More file actions
35 lines (29 loc) · 878 Bytes
/
clock_divider.v
File metadata and controls
35 lines (29 loc) · 878 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
/*================================================
Thomas Gorham
ECE 441 Spring 2017
Project 2 - Clock divider
Description: This module divides the input clk
signal frequency by 50000000.
For example, when inputting 50MHz, the resulting
frequency is 1Hz and period is 1 second.
================================================*/
`timescale 100 ns / 1 ns
module clock_divider(clk, ar, q);
input clk, ar;
output reg q;
reg [25:0] ctr; // Need a 26 bit counter reg
always @ (posedge clk or negedge ar)
if(~ar) // If reset has negedge down to level 0,
begin
ctr = 26'd0; // Put ctr and output in known state
q = 1'd0;
end
else
if(ctr>=26'd25000000) // If the counter hits 25M
begin
q = ~q; // Flip output
ctr = 26'd0; // Reset ctr
end
else
ctr = ctr + 1; // Inc ctr
endmodule