+ Post New Thread
Results 1 to 3 of 3
  1. #1
    Newbie level 2
    Points: 1,231, Level: 7

    Join Date
    Jan 2013
    Posts
    3
    Helped
    0 / 0
    Points
    1,231
    Level
    7

    Need of a Verilog code to generate clock signal for 10Mhz with system clock 50Mhz.

    VERILOG CODE to generate clock signal for 10Mhz with system clock 50Mhz
    Need Verilog code for generating two signals
    1.clock signal to generate 10Mhz
    2. at the same time the second signal has to toggle its sate on specific count on "negative" edge period
    3. How to call a function after a specific clock period?

    here i'm sharing a clock signal generation verilog code of 10Mhz from system clock 50Mhz

    Code Verilog - [expand]
    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
    
    module clk_div(clk,reset, clk_out );
    parameter N=5;
    parameter R=3;// Detramains number of binary bits to present the value of "N" 
    input clk;
    input reset;
    output clk_out;
     
    reg [R-1:0] pos_count, neg_count;
    wire [R-1:0] r_nxt;
     
    always @(posedge clk)
    if (reset)
    pos_count <=0;
    else if (pos_count ==(N-1))
    pos_count <=0;
    else 
    pos_count<= pos_count +1;
     
    always @(negedge clk)
    if (reset)
    neg_count <=0;
    else  if (neg_count ==(N-1)) 
    neg_count <=0;
      
    else 
    neg_count<= neg_count +1;
    assign clk_out = ((pos_count == (N-1)) | (neg_count == (N-1)));
    endmodule
    Last edited by ads-ee; 6th September 2019 at 15:45. Reason: fixed incorrectly used tags

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 77,731, Level: 67
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,756
    Helped
    3590 / 3590
    Points
    77,731
    Level
    67

    Re: Need of a Verilog code to generate clock signal for 10Mhz with system clock 50Mhz

    Hi,

    Take a piece of paper and draw the timing diagram for 50MHz and 10MHz.

    Then with 50% duty cycle you will see that the edges of the 10MHz will fall on rising as well as falling edge of the 50MHz.
    But usually only the rising edge of the system clock will be used.

    Either generate 2:5 duty cycle or use a PLL.

    Klaus
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



    •   AltAdvertisement

        
       

  3. #3
    Super Moderator
    Points: 260,203, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,441
    Helped
    13826 / 13826
    Points
    260,203
    Level
    100

    Re: Need of a Verilog code to generate clock signal for 10Mhz with system clock 50Mhz

    The logic in post #1 has some issues.
    The phase between pos_count and neg_count is undetermined. Depending on the reset timing either pos_count or neg_count will increment first, giving different clk_out waveforms. It's even possible that reset release is coinciding with a clock edge, resulting in unexpected counter values.

    You may do this:
    1. Use a reset synchronizer (if not already present)
    2. Use only one counter, derive the neg_edge action from pos_edge controlled signals.

    Be aware that generated clocks are likely to cause timing issues if they are combined with the original clock in downstream logic.



--[[ ]]--