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.

Clock Divider from 921600Hz to 115200Hz

Status
Not open for further replies.

fatimamaz

Newbie level 5
Joined
Jan 29, 2018
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
68
Hello,
I wrote this code for clock division from 921600Hz to 115200Hz, but something is going wrong. Can anyone help me?


Code:
module step1_divider (
input clki,
input reset,
output reg clkf
);

localparam constantNumber = 4'b1000;
reg [3:0] count;
 

always @ (posedge(clki) or posedge(reset))
begin
    if (reset == 1'b1)
		  begin
		  count <=4'b0;
        clkf <= 1'b0;
		  end
    else
	 begin 
	 if(count == 4'b0)
	 clkf <= 1'b1;
	 if (count == 4'b0100)
	 clkf <= 1'b0;
	 if (count == constantNumber)
	 count <= 4'b0;
	 count <= count +1;
	end	
end
endmodule
 
Last edited by a moderator:

Hi,

I´m not familiar with writing HDL code.
it seems overcomplicated to me.

Just use a 3 bit counter and output (copy, registered) the third bit (bit 2) as your output_clock.

Klaus
 

It's because you don't know how to count....

0 1 2 3 4 0 1 2 3 4 0

That is a divide by 5.
 
Hello,
I wrote this code for clock division from 921600Hz to 115200Hz, but something is going wrong. Can anyone help me?


Code:
module step1_divider (
input clki,
input reset,
output reg clkf
);

localparam constantNumber = 4'b1000;
reg [3:0] count;
 

always @ (posedge(clki) or posedge(reset))
begin
    if (reset == 1'b1)
		  begin
		  count <=4'b0;
        clkf <= 1'b0;
		  end
    else
	 begin 
	 if(count == 4'b0)
	 clkf <= 1'b1;
	 if (count == 4'b0100)
	 clkf <= 1'b0;
	 if (count == constantNumber)
	 count <= 4'b0;
	 count <= count +1;
	end	
end
endmodule

Did you try to simulate this code? It has a rather trivial mistake that you should be able to find on your own.
 
Code:
always @ (posedge(clki) or posedge(reset))
begin
    if (reset == 1'b1) begin
        count <=4'b0;
        clkf <= 1'b0;
    end else begin 
        if(count == 4'b0) begin
            clkf <= 1'b1;
        end
        // missing "else", but the condition won't be reached when count == 0
        if (count == 4'b0100) begin
            clkf <= 1'b0;
        end

        if (count == constantNumber) begin
            count <= 4'b0;
        end
        // missing else, this statement is always reached and thus the only one that matters.
        count <= count +1;
    end	
end
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top