Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] How to make Clock Divider

Status
Not open for further replies.

dadili

Junior Member level 2
Junior Member level 2
Joined
Oct 31, 2011
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,413
I have to make clock divider from 50MHz to 2.5 Hz. I have no idea how to do it. can someone help me, write the code or explain to me.
 

Hi! You can create enable ticks for registers in your design which appear with freq 2.5Hz. You need a counter that counts from 0 to 50M/2.5 = 20000000 - 1 = 19_999_999.
In this example module data is written to reg with freq 2.5Hz:

module mymod(clk, data, out);
input clk; // 50MHz
input data;
output reg out;

reg [24:0] cntr; // conter size = log2(20000000-1)
// free-run counter
always@(posedge clk)
if(cntr=19_999_999)
cntr <= 0;
else cntr <= cntr + 1;

wire enable_tick = (cntr == 19_999_999)? 1:0; // create 1 cycle enable ticks with freq 2.5Hz

always@(posedge clk)
if(enable_tick)
out <= data;

endmodule
 

to be honest, I dont understand that code, how it works to divide clock
 

Try to model it :wink: Do not forget to add a reset input or the following initial block:

initial
begin
cntr=0;
out=0;
end

... otherwise you will get X for cntr and out on waveforms. Take a look at the attached waveform. Enable ticks appear with freq 2.5Hz.

The link you've provided describes not a good way of freq dividing.

Good luck!

 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top