Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
18 years ago

the clock divider with enable using verilog

i am working with EPM570T100I5,which has no PLL,i want to get a 1MHz clcok,the global clock is 50MHz.i have read the posts about clcok divider,the enable clock is a good way,but i am a newbie,i didnot kown what to do,can anybody give me a hand,thx a lot!!

12 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Hi,

    use a counter running continuously on your 50MHz clk from 0 to 49 and back.

    generate a single enable pulse when count say = 49. Enable should be low otherwise. Then use this enable pulse together with your 50MHz clk to enable your work at 1MHz.

    Additionally, you may add a multicycle of 50 to your logic timing constraints since the required speed is now just 1MHz. Obviously, you don't need to do this if your design doesn't violate the 50MHz.

    Regards

    kaz

    --- Quote End ---

    In accordance with your post, I wrote the following code,could tell me is it right?is it the enable clock divider? THX very much.

    module divider

    (clk,

    rst_n,

    clk_o);

    parameter TIMECONST_49 = 6'b110001;

    input clk;

    input rst_n;

    output reg clk_o;

    reg [5:0] div_50;

    reg en_50;

    always @ (posedge clk or negedge rst_n)

    begin

    if (!rst_n)

    begin

    div_50 <= 6'b000000;

    en_50 <= 1'b0;

    end

    else

    begin

    if (div_50 == TIMECONST_49)

    begin

    div_50 <= 6'b000000;

    en_50 <= 1'b1;

    end

    else

    begin

    div_50 <= div_50 + 6'b1;

    en_50 <= 1'b0;

    end

    end

    end

    always @ (posedge clk or negedge rst_n)

    begin

    if (!rst_n)

    begin

    clk_o <= 1'b0;

    end

    else if (en_50)

    clk_o <= ~clk_o;

    end

    endmodule
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    use a counter running continuously on your 50MHz clk from 0 to 49 and back.

    generate a single enable pulse when count say = 49. Enable should be low otherwise. Then use this enable pulse together with your 50MHz clk to enable your work at 1MHz.

    Additionally, you may add a multicycle of 50 to your logic timing constraints since the required speed is now just 1MHz. Obviously, you don't need to do this if your design doesn't violate the 50MHz.

    Regards

    kaz